Skip to content

Commit 000e37b

Browse files
authored
Merge 108e3f9 into ebfc93f
2 parents ebfc93f + 108e3f9 commit 000e37b

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Thank you to all who have contributed!
5353
### Fixed
5454
- Fixes the CLI hanging on invalid queries. See issue #1230.
5555
- Fixes Timestamp Type parsing issue. Previously Timestamp Type would get parsed to a Time type.
56+
- Fixes PIVOT parsing to assign the key and value as defined by spec section 14.
5657
- Fixes the physical plan compiler to return list when `DISTINCT` used with `ORDER BY`
5758

5859
### Removed

partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToLegacyAst.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,12 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
708708
projectExpr(expr, alias, metas)
709709
}
710710

711+
// !!
712+
// Legacy AST mislabels key and value in PIVOT, swapping the order here to recreate bug for compatibility.
713+
// !!
711714
override fun visitSelectPivot(node: Select.Pivot, ctx: Ctx) = translate(node) { metas ->
712-
val value = visitExpr(node.value, ctx)
713-
val key = visitExpr(node.key, ctx)
715+
val key = visitExpr(node.value, ctx) // SWAP val -> key
716+
val value = visitExpr(node.key, ctx) // SWAP key -> val
714717
projectPivot(value, key, metas)
715718
}
716719

partiql-ast/src/test/kotlin/org/partiql/ast/helpers/ToLegacyAstTest.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,10 +536,14 @@ class ToLegacyAstTest {
536536
}
537537
}
538538
},
539-
expect("(project_pivot (lit 1) (lit 2))") {
539+
expect("(project_pivot (lit 2) (lit 1))") {
540540
selectPivot {
541-
value = exprLit(int32Value(1))
541+
// PIVOT 1 AT 2
542+
// - 1 is the VALUE
543+
// - 2 is the KEY
544+
// In the legacy implementation these were accidentally flipped
542545
key = exprLit(int32Value(2))
546+
value = exprLit(int32Value(1))
543547
}
544548
},
545549
expect("(project_value (lit null))") {

partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,8 +939,8 @@ internal class PartiQLParserDefault : PartiQLParser {
939939
}
940940

941941
override fun visitSelectPivot(ctx: GeneratedParser.SelectPivotContext) = translate(ctx) {
942-
val key = visitExpr(ctx.pivot)
943-
val value = visitExpr(ctx.at)
942+
val key = visitExpr(ctx.at)
943+
val value = visitExpr(ctx.pivot)
944944
selectPivot(key, value)
945945
}
946946

0 commit comments

Comments
 (0)