Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigQuery schema changes: fix added float column #1495

Merged
merged 7 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flow/connectors/bigquery/bigquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ func (c *BigQueryConnector) ReplayTableSchemaDeltas(

for _, addedColumn := range schemaDelta.AddedColumns {
dstDatasetTable, _ := c.convertToDatasetTable(schemaDelta.DstTableName)
addedColumnBigQueryType := qValueKindToBigQueryTypeString(addedColumn.ColumnType)
query := c.client.Query(fmt.Sprintf(
"ALTER TABLE %s ADD COLUMN IF NOT EXISTS `%s` %s",
dstDatasetTable.table, addedColumn.ColumnName,
qValueKindToBigQueryType(addedColumn.ColumnType)))
dstDatasetTable.table, addedColumn.ColumnName, addedColumnBigQueryType))
query.DefaultProjectID = c.projectID
query.DefaultDatasetID = dstDatasetTable.dataset
_, err := query.Read(ctx)
Expand Down
10 changes: 10 additions & 0 deletions flow/connectors/bigquery/qvalue_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,13 @@ func BigQueryTypeToQValueKind(fieldType bigquery.FieldType) (qvalue.QValueKind,
return "", fmt.Errorf("unsupported bigquery field type: %v", fieldType)
}
}

func qValueKindToBigQueryTypeString(colType string) string {
bqType := qValueKindToBigQueryType(colType)
bqTypeAsString := string(bqType)
// string(bigquery.FloatFieldType) is "FLOAT" which is not a BigQuery type.
if bqType == bigquery.FloatFieldType {
bqTypeAsString = "FLOAT64"
}
return bqTypeAsString
Amogh-Bharadwaj marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 2 additions & 2 deletions flow/e2e/bigquery/peer_flow_bq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,11 @@ func (s PeerFlowE2ETestSuiteBQ) Test_Simple_Schema_Changes_BQ() {

// alter source table, add column c3, drop column c2 and insert another row.
_, err = s.Conn().Exec(context.Background(), fmt.Sprintf(`
ALTER TABLE %s DROP COLUMN c2, ADD COLUMN c3 BIGINT`, srcTableName))
ALTER TABLE %s DROP COLUMN c2, ADD COLUMN c3 FLOAT`, srcTableName))
e2e.EnvNoError(s.t, env, err)
s.t.Log("Altered source table, dropped column c2 and added column c3")
_, err = s.Conn().Exec(context.Background(), fmt.Sprintf(`
INSERT INTO %s(c1,c3) VALUES (3,3)`, srcTableName))
INSERT INTO %s(c1,c3) VALUES (3,3.5)`, srcTableName))
e2e.EnvNoError(s.t, env, err)
s.t.Log("Inserted row with added c3 in the source table")

Expand Down
Loading