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

fix(mc2mc): omit last comment in execution #75

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 0 additions & 3 deletions mc2mc/internal/query/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ 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)
Expand Down Expand Up @@ -657,7 +656,6 @@ END
function my_add(@a BIGINT) as @a + 1
;
@src := SELECT my_add(1) id
-- this is comment
;
INSERT OVERWRITE TABLE append_test VALUES(0),(1)
;
Expand All @@ -676,7 +674,6 @@ END
function my_add(@a BIGINT) as @a + 1
;
@src := SELECT my_add(1) id
-- this is comment
;
MERGE INTO append_test
USING (SELECT castStringToBoolean(id) FROM @src) source
Expand Down
17 changes: 7 additions & 10 deletions mc2mc/internal/query/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ func SeparateHeadersAndQuery(query string) (string, string) {
stmtWithoutComment := RemoveComments(stmt)
if headerPattern.MatchString(strings.TrimSpace(stmtWithoutComment)) {
headers = append(headers, stmt)
} else if strings.TrimSpace(stmtWithoutComment) == "" {
// if the statement is empty, it's a comment, then omit it
// since it doesn't make sense to execute this statement
continue
} else {
// if the statement is empty, it's a comment, then add it to the previous query
if strings.TrimSpace(stmtWithoutComment) == "" {
remainingQueries[len(remainingQueries)-1] += fmt.Sprintf("\n%s\n", stmt)
continue
}
remainingQueries = append(remainingQueries, stmt)
}
}
Expand Down Expand Up @@ -77,12 +76,10 @@ func SeparateVariablesUDFsAndQuery(query string) (string, string) {
if variablePattern.MatchString(strings.TrimSpace(stmtWithoutComment)) ||
udfPattern.MatchString(strings.TrimSpace(stmtWithoutComment)) {
variablesAndUDFs = append(variablesAndUDFs, stmt)
} else if strings.TrimSpace(stmtWithoutComment) == "" {
// if the statement is empty, it's a comment, then omit it
// since it doesn't make sense to execute this statement
} else {
// if the statement is empty, it's a comment, then add it to the previous query
if strings.TrimSpace(stmtWithoutComment) == "" {
remainingQueries[len(remainingQueries)-1] += fmt.Sprintf("\n%s\n", stmt)
continue
}
remainingQueries = append(remainingQueries, stmt)
}
}
Expand Down
Loading