I’m trying to basically merge lists in nested maps. There may be a field of type RECORD
, for those I need to look at the fields
and merge them with the corresponding fields
from both schemas and there may be more fields
of type RECORD
in those which also need to be merged. Everything in the new schema needs to be added to the old schema, as you cannot remove columns in Big Query.
Not really sure where to start, so any bit of direction would be great! Thanks!
Old schema:
%GoogleApi.BigQuery.V2.Model.TableSchema{
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "REQUIRED",
name: "timestamp",
type: "TIMESTAMP"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "event_message",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "ip_address",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "request_method",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "server",
type: "STRING"
}
],
mode: "NULLABLE",
name: "request_headers",
type: "RECORD"
}
],
mode: "REPEATED",
name: "metadata",
type: "RECORD"
}
]
}
New schema:
%GoogleApi.BigQuery.V2.Model.TableSchema{
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "REQUIRED",
name: "timestamp",
type: "TIMESTAMP"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "event_message",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "ip_address",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "server",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "user_agent",
type: "STRING"
}
],
mode: "NULLABLE",
name: "request_headers",
type: "RECORD"
}
],
mode: "REPEATED",
name: "metadata",
type: "RECORD"
}
]
}
Merged schemas:
%GoogleApi.BigQuery.V2.Model.TableSchema{
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "REQUIRED",
name: "timestamp",
type: "TIMESTAMP"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "event_message",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "ip_address",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "request_method",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: [
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "server",
type: "STRING"
},
%GoogleApi.BigQuery.V2.Model.TableFieldSchema{
description: nil,
fields: nil,
mode: "NULLABLE",
name: "user_agent",
type: "STRING"
}
],
mode: "NULLABLE",
name: "request_headers",
type: "RECORD"
}
],
mode: "REPEATED",
name: "metadata",
type: "RECORD"
}
]
}