Fix precendence bug in S3Select SQL IN clauses (#18708)

Fixes a precendence issue in SQL Select where `a in b and c = 3` was parsed as `a
in (b and c = 3)`.

Fixes #18682
This commit is contained in:
Aditya Manthramurthy
2023-12-22 23:19:11 -08:00
committed by GitHub
parent 8bd4f6568b
commit 496027b589
5 changed files with 57 additions and 12 deletions

View File

@@ -134,7 +134,7 @@ func (e *ConditionRHS) analyze(s *Select) (result qProp) {
result.combine(e.Between.Start.analyze(s))
result.combine(e.Between.End.analyze(s))
case e.In != nil:
result.combine(e.In.ListExpression.analyze(s))
result.combine(e.In.analyze(s))
case e.Like != nil:
result.combine(e.Like.Pattern.analyze(s))
if e.Like.EscapeChar != nil {
@@ -146,6 +146,25 @@ func (e *ConditionRHS) analyze(s *Select) (result qProp) {
return
}
func (e *In) analyze(s *Select) (result qProp) {
switch {
case e.JPathExpr != nil:
// Check if the path expression is valid
if len(e.JPathExpr.PathExpr) > 0 {
if e.JPathExpr.BaseKey.String() != s.From.As && !strings.EqualFold(e.JPathExpr.BaseKey.String(), baseTableName) {
result = qProp{err: errInvalidKeypath}
return
}
}
result = qProp{isRowFunc: true}
case e.ListExpr != nil:
result = e.ListExpr.analyze(s)
default:
result = qProp{err: errUnexpectedInvalidNode}
}
return
}
func (e *Operand) analyze(s *Select) (result qProp) {
result.combine(e.Left.analyze(s))
for _, r := range e.Right {