Skip to content

Commit 30836d9

Browse files
committed
Fix IN expression with mixed primitive literals and tuples
When the RHS of IN contains a mix of primitive literals (integers, strings, etc.) and tuple literals that only contain primitives, output as a single Literal Tuple_ instead of Function tuple. Example: (number, tuple) IN (3, (2, 3)) now correctly outputs: Literal Tuple_(UInt64_3, Tuple_(UInt64_2, UInt64_3)) Fixed test: 00132_sets/stmt12
1 parent 7fc424e commit 30836d9

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

internal/explain/functions.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,10 +1026,11 @@ func explainInExpr(sb *strings.Builder, n *ast.InExpr, indent string, depth int)
10261026
// Check if this tuple contains only primitive literals (including unary negation)
10271027
if !containsOnlyPrimitiveLiteralsWithUnary(lit) {
10281028
allTuplesArePrimitive = false
1029+
allPrimitiveLiterals = false // Non-primitive tuple breaks the mixed literal check too
10291030
}
10301031
}
1031-
// Check if it's a primitive literal type (not a tuple or complex type)
1032-
if lit.Type == ast.LiteralTuple || lit.Type == ast.LiteralArray {
1032+
// Arrays break the primitive literals check
1033+
if lit.Type == ast.LiteralArray {
10331034
allPrimitiveLiterals = false
10341035
}
10351036
} else if isNumericExpr(item) {
@@ -1173,7 +1174,8 @@ func explainInExprWithAlias(sb *strings.Builder, n *ast.InExpr, alias string, in
11731174
allBooleansOrNull := true
11741175
allTuples := true
11751176
allTuplesArePrimitive := true
1176-
hasNonNull := false // Need at least one non-null value
1177+
allPrimitiveLiterals := true // Any mix of primitive literals (numbers, strings, booleans, null, primitive tuples)
1178+
hasNonNull := false // Need at least one non-null value
11771179
for _, item := range n.List {
11781180
if lit, ok := item.(*ast.Literal); ok {
11791181
if lit.Type == ast.LiteralNull {
@@ -1195,6 +1197,7 @@ func explainInExprWithAlias(sb *strings.Builder, n *ast.InExpr, alias string, in
11951197
} else {
11961198
if !containsOnlyPrimitiveLiterals(lit) {
11971199
allTuplesArePrimitive = false
1200+
allPrimitiveLiterals = false
11981201
}
11991202
}
12001203
} else if isNumericExpr(item) {
@@ -1207,10 +1210,11 @@ func explainInExprWithAlias(sb *strings.Builder, n *ast.InExpr, alias string, in
12071210
allStringsOrNull = false
12081211
allBooleansOrNull = false
12091212
allTuples = false
1213+
allPrimitiveLiterals = false
12101214
break
12111215
}
12121216
}
1213-
canBeTupleLiteral = hasNonNull && (allNumericOrNull || (allStringsOrNull && len(n.List) <= maxStringTupleSizeWithAlias) || allBooleansOrNull || (allTuples && allTuplesArePrimitive))
1217+
canBeTupleLiteral = hasNonNull && (allNumericOrNull || (allStringsOrNull && len(n.List) <= maxStringTupleSizeWithAlias) || allBooleansOrNull || (allTuples && allTuplesArePrimitive) || allPrimitiveLiterals)
12141218
}
12151219

12161220
// Count arguments
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt12": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)