Skip to content

Commit

Permalink
fix(mc2mc): remove comment before execution (#70)
Browse files Browse the repository at this point in the history
fix: remove comment before execution
  • Loading branch information
deryrahman authored Feb 6, 2025
1 parent 84fc701 commit ccc113b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mc2mc/internal/query/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func (b *Builder) Build() (string, error) {
}

var err error
hr, query := SeparateHeadersAndQuery(b.query)
query := RemoveComments(b.query)
hr, query := SeparateHeadersAndQuery(query)

// construct overrided values if enabled
if b.overridedValues != nil {
Expand Down
36 changes: 35 additions & 1 deletion mc2mc/internal/query/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,41 @@ select * from project.playground.table
SELECT col1, col2, _partitiontime FROM (
SELECT col1, col2, TIMESTAMP('2021-01-01') as _partitiontime FROM (
select * from project.playground.table
-- this is comment
)
)
;`, queryToExecute)
})
t.Run("returns query for replace load method with comment in the end with semicolon", func(t *testing.T) {
queryToExecute := `select * from project.playground.table;
-- this is comment;`
odspClient := &mockOdpsClient{
orderedColumns: func() ([]string, error) {
return []string{"col1", "col2", "_partitiontime"}, nil
},
partitionResult: func() ([]string, error) {
return []string{"col3"}, nil
},
}
destinationTableID := "project.playground.table_destination"

queryToExecute, err := query.NewBuilder(
logger.NewDefaultLogger(),
odspClient,
query.WithQuery(queryToExecute),
query.WithMethod(query.REPLACE),
query.WithDestination(destinationTableID),
query.WithOverridedValue("_partitiontime", "TIMESTAMP('2021-01-01')"),
query.WithOverridedValue("_partitiondate", "DATE(TIMESTAMP('2021-01-01'))"),
query.WithAutoPartition(true),
query.WithPartitionValue(true),
query.WithColumnOrder(),
).Build()

assert.NoError(t, err)
assert.Equal(t, `INSERT OVERWRITE TABLE project.playground.table_destination
SELECT col1, col2, _partitiontime FROM (
SELECT col1, col2, TIMESTAMP('2021-01-01') as _partitiontime FROM (
select * from project.playground.table
)
)
;`, queryToExecute)
Expand Down

0 comments on commit ccc113b

Please sign in to comment.