Skip to content

Commit ce8d9be

Browse files
authored
Merge pull request #1314 from partiql/partiql-eval-merge
Merges 0.14 main into partiql-eval
2 parents 9b73804 + 6e1d7fe commit ce8d9be

File tree

70 files changed

+2170
-2507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2170
-2507
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ Thank you to all who have contributed!
2727

2828
## [Unreleased]
2929

30+
### Added
31+
32+
### Changed
33+
34+
### Deprecated
35+
36+
### Fixed
37+
38+
### Removed
39+
40+
### Security
41+
42+
### Contributors
43+
Thank you to all who have contributed!
44+
- @<your-username>
45+
46+
## [0.14.0-alpha] - 2023-12-15
47+
3048
### Added
3149
- Adds top-level IR node creation functions.
3250
- Adds `componentN` functions (destructuring) to IR nodes via Kotlin data classes
@@ -43,29 +61,38 @@ Thank you to all who have contributed!
4361
- **Breaking** The default integer literal type is now 32-bit; if the literal can not fit in a 32-bit integer, it overflows to 64-bit.
4462
- **BREAKING** `PartiQLValueType` now distinguishes between Arbitrary Precision Decimal and Fixed Precision Decimal.
4563
- **BREAKING** Function Signature Changes. Now Function signature has two subclasses, `Scalar` and `Aggregation`.
64+
- **BREAKING** Plugin Changes. Only return one Connector.Factory, use Kotlin fields. JVM signature remains the same.
4665
- **BREAKING** In the produced plan:
4766
- The new plan is fully resolved and typed.
4867
- Operators will be converted to function call.
4968
- Changes the return type of `filter_distinct` to a list if input collection is list
69+
- Changes the `PartiQLValue` collections to implement Iterable rather than Sequence, allowing for multiple consumption.
70+
- **BREAKING** Moves PartiQLParserBuilder.standard().build() to be PartiQLParser.default().
71+
- **BREAKING** Changed modeling of `EXCLUDE` in `partiql-ast`
5072

5173
### Deprecated
5274

5375
### Fixed
5476
- Fixes the CLI hanging on invalid queries. See issue #1230.
5577
- Fixes Timestamp Type parsing issue. Previously Timestamp Type would get parsed to a Time type.
78+
- Fixes PIVOT parsing to assign the key and value as defined by spec section 14.
5679
- Fixes the physical plan compiler to return list when `DISTINCT` used with `ORDER BY`
5780

5881
### Removed
5982
- **Breaking** Removed IR factory in favor of static top-level functions. Change `Ast.foo()`
6083
to `foo()`
6184
- **Breaking** Removed `org.partiql.lang.planner.transforms.AstToPlan`. Use `org.partiql.planner.PartiQLPlanner`.
85+
- **Breaking** Removed `org.partiql.lang.planner.transforms.PartiQLSchemaInferencer`. In order to achieve the same functionality, one would need to use the `org.partiql.planner.PartiQLPlanner`.
86+
- To get the inferred type of the query result, one can do: `(plan.statement as Statement.Query).root.type`
6287

6388
### Security
6489

6590
### Contributors
6691
Thank you to all who have contributed!
6792
- @rchowell
6893
- @johnedquinn
94+
- @yliuuuu
95+
- @alancai98
6996

7097
## [0.13.2-alpha] - 2023-09-29
7198

@@ -920,6 +947,7 @@ breaking changes if migrating from v0.9.2. The breaking changes accidentally int
920947
Initial alpha release of PartiQL.
921948

922949
[Unreleased]: https://github.com/partiql/partiql-lang-kotlin/compare/v0.13.2-alpha...HEAD
950+
[0.14.0-alpha]: https://github.com/partiql/partiql-lang-kotlin/compare/v0.13.2-alpha...v0.14.0-alpha
923951
[0.13.2-alpha]: https://github.com/partiql/partiql-lang-kotlin/compare/v0.13.1-alpha...v0.13.2-alpha
924952
[0.13.1-alpha]: https://github.com/partiql/partiql-lang-kotlin/compare/v0.13.0-alpha...v0.13.1-alpha
925953
[0.13.0-alpha]: https://github.com/partiql/partiql-lang-kotlin/compare/v0.12.0-alpha...v0.13.0-alpha

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This project is published to [Maven Central](https://search.maven.org/artifact/o
3131

3232
| Group ID | Artifact ID | Recommended Version |
3333
|---------------|-----------------------|---------------------|
34-
| `org.partiql` | `partiql-lang-kotlin` | `0.13.2` |
34+
| `org.partiql` | `partiql-lang-kotlin` | `0.14.0` |
3535

3636

3737
For Maven builds, add the following to your `pom.xml`:

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=org.partiql
2-
version=0.14.0-SNAPSHOT
2+
version=0.14.1-SNAPSHOT
33

44
ossrhUsername=EMPTY
55
ossrhPassword=EMPTY

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

Lines changed: 16 additions & 13 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

@@ -753,42 +756,42 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
753756
}
754757

755758
override fun visitExclude(node: Exclude, ctx: Ctx): PartiqlAst.ExcludeOp = translate(node) { metas ->
756-
val excludeExprs = node.exprs.translate<PartiqlAst.ExcludeExpr>(ctx)
759+
val excludeExprs = node.items.translate<PartiqlAst.ExcludeExpr>(ctx)
757760
excludeOp(excludeExprs, metas)
758761
}
759762

760-
override fun visitExcludeExcludeExpr(node: Exclude.ExcludeExpr, ctx: Ctx) = translate(node) { metas ->
761-
val root = visitIdentifierSymbol(node.root, ctx)
763+
override fun visitExcludeItem(node: Exclude.Item, ctx: Ctx) = translate(node) { metas ->
764+
val root = visitExprVar(node.root, ctx)
762765
val steps = node.steps.translate<PartiqlAst.ExcludeStep>(ctx)
763-
excludeExpr(root = root, steps = steps, metas)
766+
excludeExpr(root = identifier_(root.name, root.case), steps = steps, metas)
764767
}
765768

766769
override fun visitExcludeStep(node: Exclude.Step, ctx: Ctx) =
767770
super.visitExcludeStep(node, ctx) as PartiqlAst.ExcludeStep
768771

769-
override fun visitExcludeStepExcludeTupleAttr(node: Exclude.Step.ExcludeTupleAttr, ctx: Ctx) = translate(node) { metas ->
772+
override fun visitExcludeStepStructField(node: Exclude.Step.StructField, ctx: Ctx) = translate(node) { metas ->
770773
val attr = node.symbol.symbol
771774
val case = node.symbol.caseSensitivity.toLegacyCaseSensitivity()
772775
excludeTupleAttr(identifier(attr, case), metas)
773776
}
774777

775-
override fun visitExcludeStepExcludeCollectionIndex(
776-
node: Exclude.Step.ExcludeCollectionIndex,
778+
override fun visitExcludeStepCollIndex(
779+
node: Exclude.Step.CollIndex,
777780
ctx: Ctx
778781
) = translate(node) { metas ->
779782
val index = node.index.toLong()
780783
excludeCollectionIndex(index, metas)
781784
}
782785

783-
override fun visitExcludeStepExcludeTupleWildcard(
784-
node: Exclude.Step.ExcludeTupleWildcard,
786+
override fun visitExcludeStepStructWildcard(
787+
node: Exclude.Step.StructWildcard,
785788
ctx: Ctx
786789
) = translate(node) { metas ->
787790
excludeTupleWildcard(metas)
788791
}
789792

790-
override fun visitExcludeStepExcludeCollectionWildcard(
791-
node: Exclude.Step.ExcludeCollectionWildcard,
793+
override fun visitExcludeStepCollWildcard(
794+
node: Exclude.Step.CollWildcard,
792795
ctx: Ctx
793796
) = translate(node) { metas ->
794797
excludeCollectionWildcard(metas)

partiql-ast/src/main/kotlin/org/partiql/ast/sql/SqlDialect.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,32 +86,32 @@ public abstract class SqlDialect : AstBaseVisitor<SqlBlock, SqlBlock>() {
8686
override fun visitExclude(node: Exclude, head: SqlBlock): SqlBlock {
8787
var h = head
8888
h = h concat " EXCLUDE "
89-
h = h concat list(start = null, end = null) { node.exprs }
89+
h = h concat list(start = null, end = null) { node.items }
9090
return h
9191
}
9292

93-
override fun visitExcludeExcludeExpr(node: Exclude.ExcludeExpr, head: SqlBlock): SqlBlock {
93+
override fun visitExcludeItem(node: Exclude.Item, head: SqlBlock): SqlBlock {
9494
var h = head
95-
h = h concat visitIdentifierSymbol(node.root, SqlBlock.Nil)
95+
h = h concat visitExprVar(node.root, SqlBlock.Nil)
9696
h = h concat list(delimiter = null, start = null, end = null) { node.steps }
9797
return h
9898
}
9999

100-
override fun visitExcludeStepExcludeCollectionIndex(node: Exclude.Step.ExcludeCollectionIndex, head: SqlBlock): SqlBlock {
100+
override fun visitExcludeStepCollIndex(node: Exclude.Step.CollIndex, head: SqlBlock): SqlBlock {
101101
return head concat r("[${node.index}]")
102102
}
103103

104-
override fun visitExcludeStepExcludeTupleWildcard(node: Exclude.Step.ExcludeTupleWildcard, head: SqlBlock): SqlBlock {
104+
override fun visitExcludeStepStructWildcard(node: Exclude.Step.StructWildcard, head: SqlBlock): SqlBlock {
105105
return head concat r(".*")
106106
}
107107

108-
override fun visitExcludeStepExcludeTupleAttr(node: Exclude.Step.ExcludeTupleAttr, head: SqlBlock): SqlBlock {
108+
override fun visitExcludeStepStructField(node: Exclude.Step.StructField, head: SqlBlock): SqlBlock {
109109
var h = head concat r(".")
110110
h = h concat visitIdentifierSymbol(node.symbol, SqlBlock.Nil)
111111
return h
112112
}
113113

114-
override fun visitExcludeStepExcludeCollectionWildcard(node: Exclude.Step.ExcludeCollectionWildcard, head: SqlBlock): SqlBlock {
114+
override fun visitExcludeStepCollWildcard(node: Exclude.Step.CollWildcard, head: SqlBlock): SqlBlock {
115115
return head concat r("[*]")
116116
}
117117

partiql-ast/src/main/resources/partiql_ast.ion

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -563,17 +563,17 @@ select::[
563563
]
564564

565565
exclude::{
566-
exprs: list::[exclude_expr],
566+
items: list::[item],
567567
_: [
568-
exclude_expr::{
569-
root: '.identifier.symbol',
568+
item::{
569+
root: '.expr.var',
570570
steps: list::[step],
571571
},
572572
step::[
573-
exclude_tuple_attr::{ symbol: '.identifier.symbol' },
574-
exclude_collection_index::{ index: int },
575-
exclude_tuple_wildcard::{},
576-
exclude_collection_wildcard::{},
573+
struct_field::{ symbol: '.identifier.symbol' },
574+
coll_index::{ index: int },
575+
struct_wildcard::{},
576+
coll_wildcard::{},
577577
]
578578
]
579579
}

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-ast/src/test/kotlin/org/partiql/ast/sql/SqlDialectTest.kt

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,11 +1073,9 @@ class SqlDialectTest {
10731073
type = From.Value.Type.SCAN
10741074
}
10751075
exclude = exclude {
1076-
exprs += excludeExcludeExpr {
1077-
root = id("t", Identifier.CaseSensitivity.INSENSITIVE)
1078-
steps += excludeStepExcludeTupleAttr {
1079-
symbol = id("a", Identifier.CaseSensitivity.INSENSITIVE)
1080-
}
1076+
items += excludeItem {
1077+
root = v("t")
1078+
steps += insensitiveExcludeStructField("a")
10811079
}
10821080
}
10831081
}
@@ -1090,21 +1088,21 @@ class SqlDialectTest {
10901088
type = From.Value.Type.SCAN
10911089
}
10921090
exclude = exclude {
1093-
exprs += excludeExcludeExpr {
1094-
root = id("a", Identifier.CaseSensitivity.INSENSITIVE)
1095-
steps += insensitiveExcludeTupleAttr("b")
1091+
items += excludeItem {
1092+
root = v("a")
1093+
steps += insensitiveExcludeStructField("b")
10961094
}
1097-
exprs += excludeExcludeExpr {
1098-
root = id("c", Identifier.CaseSensitivity.INSENSITIVE)
1099-
steps += insensitiveExcludeTupleAttr("d")
1095+
items += excludeItem {
1096+
root = v("c")
1097+
steps += insensitiveExcludeStructField("d")
11001098
}
1101-
exprs += excludeExcludeExpr {
1102-
root = id("e", Identifier.CaseSensitivity.INSENSITIVE)
1103-
steps += insensitiveExcludeTupleAttr("f")
1099+
items += excludeItem {
1100+
root = v("e")
1101+
steps += insensitiveExcludeStructField("f")
11041102
}
1105-
exprs += excludeExcludeExpr {
1106-
root = id("g", Identifier.CaseSensitivity.INSENSITIVE)
1107-
steps += insensitiveExcludeTupleAttr("h")
1103+
items += excludeItem {
1104+
root = v("g")
1105+
steps += insensitiveExcludeStructField("h")
11081106
}
11091107
}
11101108
}
@@ -1117,37 +1115,37 @@ class SqlDialectTest {
11171115
type = From.Value.Type.SCAN
11181116
}
11191117
exclude = exclude {
1120-
exprs += excludeExcludeExpr {
1121-
root = id("t", Identifier.CaseSensitivity.INSENSITIVE)
1118+
items += excludeItem {
1119+
root = v("t")
11221120
steps += mutableListOf(
1123-
insensitiveExcludeTupleAttr("a"),
1124-
sensitiveExcludeTupleAttr("b"),
1125-
excludeStepExcludeTupleWildcard(),
1126-
excludeStepExcludeCollectionWildcard(),
1127-
insensitiveExcludeTupleAttr("c"),
1121+
insensitiveExcludeStructField("a"),
1122+
sensitiveExcludeStructField("b"),
1123+
excludeStepStructWildcard(),
1124+
excludeStepCollWildcard(),
1125+
insensitiveExcludeStructField("c"),
11281126
)
11291127
}
1130-
exprs += excludeExcludeExpr {
1131-
root = id("s", Identifier.CaseSensitivity.SENSITIVE)
1128+
items += excludeItem {
1129+
root = exprVar(id("s", Identifier.CaseSensitivity.SENSITIVE), Expr.Var.Scope.DEFAULT)
11321130
steps += mutableListOf(
1133-
excludeStepExcludeCollectionIndex(0),
1134-
insensitiveExcludeTupleAttr("d"),
1135-
sensitiveExcludeTupleAttr("e"),
1136-
excludeStepExcludeCollectionWildcard(),
1137-
insensitiveExcludeTupleAttr("f"),
1138-
excludeStepExcludeTupleWildcard(),
1131+
excludeStepCollIndex(0),
1132+
insensitiveExcludeStructField("d"),
1133+
sensitiveExcludeStructField("e"),
1134+
excludeStepCollWildcard(),
1135+
insensitiveExcludeStructField("f"),
1136+
excludeStepStructWildcard(),
11391137
)
11401138
}
11411139
}
11421140
}
11431141
},
11441142
)
11451143

1146-
private fun AstBuilder.insensitiveExcludeTupleAttr(str: String) = excludeStepExcludeTupleAttr {
1144+
private fun AstBuilder.insensitiveExcludeStructField(str: String) = excludeStepStructField {
11471145
symbol = id(str, Identifier.CaseSensitivity.INSENSITIVE)
11481146
}
11491147

1150-
private fun AstBuilder.sensitiveExcludeTupleAttr(str: String) = excludeStepExcludeTupleAttr {
1148+
private fun AstBuilder.sensitiveExcludeStructField(str: String) = excludeStepStructField {
11511149
symbol = id(str, Identifier.CaseSensitivity.SENSITIVE)
11521150
}
11531151

partiql-cli/src/main/kotlin/org/partiql/cli/Main.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,16 @@ package org.partiql.cli
1717

1818
import AstPrinter
1919
import com.amazon.ion.system.IonSystemBuilder
20-
import com.amazon.ionelement.api.field
21-
import com.amazon.ionelement.api.ionString
22-
import com.amazon.ionelement.api.ionStructOf
2320
import org.partiql.cli.pico.PartiQLCommand
2421
import org.partiql.cli.shell.info
2522
import org.partiql.lang.eval.EvaluationSession
26-
import org.partiql.parser.PartiQLParserBuilder
23+
import org.partiql.parser.PartiQLParser
2724
import org.partiql.plan.debug.PlanPrinter
2825
import org.partiql.planner.PartiQLPlanner
29-
import org.partiql.planner.PartiQLPlannerBuilder
30-
import org.partiql.plugins.local.LocalPlugin
26+
import org.partiql.plugins.local.LocalConnector
3127
import picocli.CommandLine
3228
import java.io.PrintStream
29+
import java.nio.file.Paths
3330
import java.util.UUID
3431
import kotlin.system.exitProcess
3532

@@ -53,15 +50,14 @@ object Debug {
5350

5451
private const val USER_ID = "DEBUG_USER_ID"
5552

56-
private val plugins = listOf(LocalPlugin())
57-
private val catalogs = mapOf(
58-
"local" to ionStructOf(
59-
field("connector_name", ionString("local")),
60-
)
61-
)
53+
private val root = Paths.get(System.getProperty("user.home")).resolve(".partiql/local")
6254

63-
private val planner = PartiQLPlannerBuilder().plugins(plugins).build()
64-
private val parser = PartiQLParserBuilder.standard().build()
55+
private val planner = PartiQLPlanner.builder()
56+
.catalogs(
57+
"local" to LocalConnector.Metadata(root)
58+
)
59+
.build()
60+
private val parser = PartiQLParser.default()
6561

6662
// !!
6763
// IMPLEMENT DEBUG BEHAVIOR HERE
@@ -80,7 +76,6 @@ object Debug {
8076
val sess = PartiQLPlanner.Session(
8177
queryId = UUID.randomUUID().toString(),
8278
userId = "debug",
83-
catalogConfig = catalogs,
8479
)
8580
val result = planner.plan(statement, sess).plan
8681
out.info("-- Plan ----------")

0 commit comments

Comments
 (0)