-
Notifications
You must be signed in to change notification settings - Fork 30
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
delete with multi columns IN Predicate #1001
base: main
Are you sure you want to change the base?
Conversation
cc8fe09
to
057e3f9
Compare
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.
It is on the right track, assuming we wish to change ir.IN() like this. If we are chaing that, then make sure that TSQL changes if it needs to.
@@ -3557,7 +3557,7 @@ predicate | |||
| expression comparisonOperator expression # predBinop | |||
| expression comparisonOperator (ALL | SOME | ANY) L_PAREN subquery R_PAREN # predASA | |||
| expression IS NOT? NULL # predIsNull | |||
| expression NOT? IN L_PAREN (subquery | exprList) R_PAREN # predIn | |||
| (L_PAREN exprList R_PAREN | expression) NOT? IN L_PAREN (subquery | exprList) R_PAREN # predIn |
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.
| expression NOT? IN L_PAREN (subquery | exprList) R_PAREN # predIn
| L_PAREN exprList R_PAREN NOT? IN L_PAREN (subquery | exprList) R_PAREN # predExprListIn
keep these separate with a separate visitor then there is no need to do complex logic to see whether there is an exprList or an expression. visitpredExprListIn
will autmatically know that it is two expression lists.
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.
done
} | ||
left.size match { | ||
case 1 => | ||
val in = ir.In(left.head, right) // If there's only one expression on the left side |
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.
Revert to the existing code for visitPredIn
and implement visitPredExprListIn
if there is overlap then share the overlap with a buildXXX def to handle the common features so that the visitors are actually quite simple
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.
done
print(s"subquery: $subquery") | ||
val newSubquery = transformSubquery(target, subquery) | ||
delete.copy(where = Some(Exists(newSubquery))) | ||
// delete.copy(where = newSubquery) |
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.
Remove commented out code.
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.
This commented out code is still there.
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.
done
override def visitPredExprListIn(ctx: PredExprListInContext): ir.Expression = { | ||
// left side of In can be a list of expressions | ||
val leftExprList = ctx.exprList(0).expr().asScala.map(_.accept(this)) |
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.
// LHS is a list of expressions
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.
done
c94d95c
to
c518114
Compare
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.
We need to reinstate the errorCheck(ctx) match {
staements
@@ -3558,6 +3558,7 @@ predicate | |||
| expression comparisonOperator (ALL | SOME | ANY) L_PAREN subquery R_PAREN # predASA | |||
| expression IS NOT? NULL # predIsNull | |||
| expression NOT? IN L_PAREN (subquery | exprList) R_PAREN # predIn | |||
| L_PAREN exprList R_PAREN NOT? IN L_PAREN (subquery | exprList) R_PAREN # predExprListIn |
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.
Looks like the ANTLR formatter has been disabled. Extra space crept in there.
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.
done
override def visitPredIn(ctx: PredInContext): ir.Expression = errorCheck(ctx) match { | ||
case Some(errorResult) => errorResult | ||
case None => | ||
val in = if (ctx.subquery() != null) { | ||
// In the result of a sub query | ||
ir.In(ctx.expression().accept(this), Seq(ir.ScalarSubquery(ctx.subquery().accept(vc.relationBuilder)))) | ||
} else { | ||
// In a list of expressions | ||
ir.In(ctx.expression().accept(this), ctx.exprList().expr().asScala.map(_.accept(this))) |
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.
You have deleted the error checking match. That needs to go back in so that errorNodes are generated
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.
done
override def visitPredExprListIn(ctx: PredExprListInContext): ir.Expression = { | ||
// left side of In is a list of expressions | ||
val leftExprList = ctx.exprList(0).expr().asScala.map(_.accept(this)) | ||
|
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.
Error handling needs to go back in
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.
done
...main/scala/com/databricks/labs/remorph/parsers/snowflake/rules/DeleteOnMultipleColumns.scala
Show resolved
Hide resolved
-- snowflake sql: | ||
DELETE FROM test_tbl | ||
WHERE (version, type) NOT IN ( | ||
SELECT version1 , type2 |
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 more test case to check the behaviour., when select column names are expressions.
@@ -34,7 +34,9 @@ class SnowflakeAcceptanceSuite | |||
"test_command/test_command_3.sql", | |||
"test_skip_unsupported_operations/test_skip_unsupported_operations_7.sql", | |||
"test_skip_unsupported_operations/test_skip_unsupported_operations_9.sql", | |||
"test_skip_unsupported_operations/test_skip_unsupported_operations_10.sql"), | |||
"test_skip_unsupported_operations/test_skip_unsupported_operations_10.sql", | |||
"core_engine/delete/test_delete_with_not_in.sql", |
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 these added in ignored test?
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.
done
closes #953
Grammar changes required to handle queries like
Implemented a new visitor method -
visitPredExprListIn
Added code to change the Optimized Plan for Delete with Exists