-
Notifications
You must be signed in to change notification settings - Fork 97
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 a corner case '=' not properly rewritten to AS #3405
Fix a corner case '=' not properly rewritten to AS #3405
Conversation
Previously we rewrite "SELECT COL=expr" to "SELECT expr as "COL"", but there's a corner case that for if condition, it didn't do the rewrite, because different parser path from if condition to dml statement. This commit fix this issue by adding the mutator logic to if statement rewrite. Task: BABEL-5320 Signed-off-by: Zhibai Song <[email protected]>
Pull Request Test Coverage Report for Build 12796200197Details
💛 - Coveralls |
2634a7f
into
babelfish-for-postgresql:BABEL_5_X_DEV
…tgresql#3405) Previously we rewrite "SELECT COL=expr" to "SELECT expr as "COL"", but there's a corner case that for if condition, it didn't do the rewrite, because different parser path from if condition to dml statement. This commit fix this issue by adding the mutator logic to if statement rewrite. Task: BABEL-5320 Signed-off-by: Zhibai Song <[email protected]>
test/JDBC/expected/BABEL-2514.out
Outdated
IF EXISTS | ||
( | ||
SELECT tblnam = a.name FROM sysobjects a where a.name = 'tablename' | ||
) PRINT 'Exists'; ELSE PRINT 'Not Exists'; | ||
GO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add test cases where we have similar statement inside procedure?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, can you add tests where if condition itself gets re-written? For example,
IF EXISTS(
select trim(col) = '' from tab1 where ...
) PRINT 'Exists'; ELSE PRINT 'Not Exists';
{ | ||
PLtsql_stmt_if *fragment = (PLtsql_stmt_if *) getPLtsql_fragment(ctx->parent->parent); | ||
fragment->cond = makeTsqlExpr(ctx, false); | ||
clear_rewritten_query_fragment(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we calling clear_rewritten_query_fragment without calling add_rewritten_query_fragment_to_mutator?
clear_rewritten_query_fragment(); | ||
|
||
/* Now we can prepend SELECT to rewritten search_condition */ | ||
expr->query = strdup((std::string("SELECT ") + std::string(expr->query)).c_str()); | ||
return expr; | ||
} | ||
|
||
void enterSearch_condition(TSqlParser::Search_conditionContext *ctx) override | ||
{ | ||
if (((TSqlParser::Cfl_statementContext *) ctx->parent->parent)->if_statement()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need Sanity check?
if (!ctx->parent || !ctx->parent->parent)
return;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use dynamic_cast function instead of directly casting it
clear_rewritten_query_fragment(); | ||
|
||
/* Now we can prepend SELECT to rewritten search_condition */ | ||
expr->query = strdup((std::string("SELECT ") + std::string(expr->query)).c_str()); | ||
return expr; | ||
} | ||
|
||
void enterSearch_condition(TSqlParser::Search_conditionContext *ctx) override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didnt get why we need this change?
{ | ||
if (((TSqlParser::Cfl_statementContext *) ctx->parent->parent)->if_statement()) | ||
{ | ||
PLtsql_stmt_if *fragment = (PLtsql_stmt_if *) getPLtsql_fragment(ctx->parent->parent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a naive question, I see there are multiple possible parent->parent of search_condition like
table_sources->table_source_item->search_condition
So are we saying that only in few conditions there will be parse tree path to if_condition which will always be parent->parent?
Previously we rewrite "SELECT COL=expr" to "SELECT expr as "COL"", but there's a corner case that for if condition, it didn't do the rewrite, because different parser path from if condition to dml statement.
This commit fix this issue by adding the mutator logic to if statement rewrite.
Task: BABEL-5320
Signed-off-by: Zhibai Song [email protected]
Check List
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.