Skip to content

Commit

Permalink
Updates all aliases to identifier.symbol to match SQL grammar (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
RCHowell authored Jul 13, 2023
1 parent b1d67b2 commit f7bff3d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 65 deletions.
28 changes: 14 additions & 14 deletions partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToLegacyAst.kt
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
override fun visitSelectProjectItemExpression(node: Select.Project.Item.Expression, ctx: Ctx) =
translate(node) { metas ->
val expr = visitExpr(node.expr, ctx)
val alias = node.asAlias
val alias = node.asAlias?.symbol
projectExpr(expr, alias, metas)
}

Expand All @@ -718,9 +718,9 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
override fun visitFrom(node: From, ctx: Ctx) = super.visitFrom(node, ctx) as PartiqlAst.FromSource
override fun visitFromValue(node: From.Value, ctx: Ctx) = translate(node) { metas ->
val expr = visitExpr(node.expr, ctx)
val asAlias = node.asAlias
val atAlias = node.atAlias
val byAlias = node.byAlias
val asAlias = node.asAlias?.symbol
val atAlias = node.atAlias?.symbol
val byAlias = node.byAlias?.symbol
when (node.type) {
From.Value.Type.SCAN -> scan(expr, asAlias, atAlias, byAlias, metas)
From.Value.Type.UNPIVOT -> unpivot(expr, asAlias, atAlias, byAlias, metas)
Expand Down Expand Up @@ -755,7 +755,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi

override fun visitLetBinding(node: Let.Binding, ctx: Ctx) = translate(node) { metas ->
val expr = visitExpr(node.expr, ctx)
val name = node.asAlias
val name = node.asAlias?.symbol
letBinding(expr, name, metas)
}

Expand All @@ -765,13 +765,13 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
GroupBy.Strategy.PARTIAL -> groupPartial()
}
val keyList = groupKeyList(node.keys.translate<PartiqlAst.GroupKey>(ctx))
val groupAsAlias = node.asAlias
val groupAsAlias = node.asAlias?.symbol
groupBy(strategy, keyList, groupAsAlias, metas)
}

override fun visitGroupByKey(node: GroupBy.Key, ctx: Ctx) = translate(node) { metas ->
val expr = visitExpr(node.expr, ctx)
val asAlias = node.asAlias
val asAlias = node.asAlias?.symbol
groupKey(expr, asAlias, metas)
}

Expand Down Expand Up @@ -911,7 +911,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi

override fun visitStatementDMLInsert(node: Statement.DML.Insert, ctx: Ctx) = translate(node) { metas ->
val target = visitIdentifier(node.target, ctx)
val asAlias = node.asAlias
val asAlias = node.asAlias?.symbol
val values = visitExpr(node.values, ctx)
val conflictAction = node.onConflict?.let { visitOnConflictAction(it.action, ctx) }
val op = insert(target, asAlias, values, conflictAction)
Expand All @@ -935,7 +935,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi

override fun visitStatementDMLUpsert(node: Statement.DML.Upsert, ctx: Ctx) = translate(node) { metas ->
val target = visitIdentifier(node.target, ctx)
val asAlias = node.asAlias
val asAlias = node.asAlias?.symbol
val values = visitExpr(node.values, ctx)
val conflictAction = doUpdate(excluded())
// UPSERT overloads legacy INSERT
Expand All @@ -945,7 +945,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi

override fun visitStatementDMLReplace(node: Statement.DML.Replace, ctx: Ctx) = translate(node) { metas ->
val target = visitIdentifier(node.target, ctx)
val asAlias = node.asAlias
val asAlias = node.asAlias?.symbol
val values = visitExpr(node.values, ctx)
val conflictAction = doReplace(excluded())
// REPLACE overloads legacy INSERT
Expand Down Expand Up @@ -991,9 +991,9 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi

override fun visitStatementDMLDeleteTarget(node: Statement.DML.Delete.Target, ctx: Ctx) = translate(node) { metas ->
val path = visitPathUnpack(node.path, ctx)
val asAlias = node.asAlias
val atAlias = node.atAlias
val byAlias = node.byAlias
val asAlias = node.asAlias?.symbol
val atAlias = node.atAlias?.symbol
val byAlias = node.byAlias?.symbol
scan(path, asAlias, atAlias, byAlias, metas)
}

Expand Down Expand Up @@ -1041,7 +1041,7 @@ private class AstTranslator(val metas: Map<String, MetaContainer>) : AstBaseVisi
ctx: Ctx,
) = translate(node) { metas ->
val target = visitIdentifier(node.target, ctx)
val asAlias = node.asAlias
val asAlias = node.asAlias?.symbol
val values = visitExpr(node.values, ctx)
val conflictAction = node.onConflict?.let { visitOnConflictAction(it.action, ctx) }
dmlOpList(insert(target, asAlias, values, conflictAction, metas))
Expand Down
30 changes: 15 additions & 15 deletions partiql-ast/src/main/resources/partiql_ast.ion
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ statement::[
insert::{
target: identifier,
values: expr,
as_alias: optional::string,
as_alias: optional::'.identifier.symbol',
on_conflict: optional::on_conflict,
},

Expand All @@ -34,14 +34,14 @@ statement::[
upsert::{
target: identifier,
values: expr,
as_alias: optional::string,
as_alias: optional::'.identifier.symbol',
},

// REPLACE INTO <target> [AS <alias>] <values>
replace::{
target: identifier,
values: expr,
as_alias: optional::string,
as_alias: optional::'.identifier.symbol',
},

// UPDATE <target> SET <set clause list> WHERE <expr>
Expand All @@ -65,9 +65,9 @@ statement::[
delete::{
target: {
path: path,
as_alias: optional::string,
at_alias: optional::string,
by_alias: optional::string,
as_alias: optional::'.identifier.symbol',
at_alias: optional::'.identifier.symbol',
by_alias: optional::'.identifier.symbol',
},
where: optional::expr,
returning: optional::returning,
Expand All @@ -84,7 +84,7 @@ statement::[
insert::{
target: identifier,
values: expr,
as_alias: optional::string,
as_alias: optional::'.identifier.symbol',
on_conflict: optional::on_conflict,
},
insert_legacy::{
Expand Down Expand Up @@ -541,8 +541,8 @@ select::[
setq: optional::set_quantifier,
_: [
item::[
all::{ expr: expr }, // <expr>.*
expression::{ expr: expr, as_alias: optional::string } // <expr> [as <identifier>]
all::{ expr: expr }, // <expr>.*
expression::{ expr: expr, as_alias: optional::'.identifier.symbol' } // <expr> [as <identifier>]
],
],
},
Expand All @@ -567,9 +567,9 @@ from::[
value::{
expr: expr,
type: [ SCAN, UNPIVOT ],
as_alias: optional::string,
at_alias: optional::string,
by_alias: optional::string,
as_alias: optional::'.identifier.symbol',
at_alias: optional::'.identifier.symbol',
by_alias: optional::'.identifier.symbol',
},

// TODO https://github.com/partiql/partiql-spec/issues/41
Expand Down Expand Up @@ -597,7 +597,7 @@ let::{
_: [
binding::{
expr: expr,
as_alias: string,
as_alias: '.identifier.symbol',
},
],
}
Expand All @@ -606,11 +606,11 @@ let::{
group_by::{
strategy: [ FULL, PARTIAL ],
keys: list::[key],
as_alias: optional::string,
as_alias: optional::'.identifier.symbol',
_: [
key::{
expr: expr,
as_alias: optional::string,
as_alias: optional::'.identifier.symbol',
},
],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ class ToLegacyAstTest {
}
items += selectProjectItemExpression {
expr = exprLit(int32Value(1))
asAlias = "x"
asAlias = id("x")
}
}
},
Expand All @@ -558,9 +558,9 @@ class ToLegacyAstTest {
fromValue {
expr = NULL
type = From.Value.Type.SCAN
asAlias = "a"
atAlias = "b"
byAlias = "c"
asAlias = id("a")
atAlias = id("b")
byAlias = id("c")
}
},
expect("(unpivot (lit null) null null null)") {
Expand All @@ -573,9 +573,9 @@ class ToLegacyAstTest {
fromValue {
expr = NULL
type = From.Value.Type.UNPIVOT
asAlias = "a"
atAlias = "b"
byAlias = "c"
asAlias = id("a")
atAlias = id("b")
byAlias = id("c")
}
},
expect(
Expand Down Expand Up @@ -626,7 +626,7 @@ class ToLegacyAstTest {
let {
bindings += letBinding {
expr = NULL
asAlias = "x"
asAlias = id("x")
}
}
},
Expand All @@ -644,7 +644,7 @@ class ToLegacyAstTest {
groupBy {
strategy = GroupBy.Strategy.FULL
keys += groupByKey(exprLit(stringValue("a")), null)
keys += groupByKey(exprLit(stringValue("b")), "x")
keys += groupByKey(exprLit(stringValue("b")), id("x"))
}
},
expect(
Expand All @@ -661,8 +661,8 @@ class ToLegacyAstTest {
groupBy {
strategy = GroupBy.Strategy.PARTIAL
keys += groupByKey(exprLit(stringValue("a")), null)
keys += groupByKey(exprLit(stringValue("b")), "x")
asAlias = "as"
keys += groupByKey(exprLit(stringValue("b")), id("x"))
asAlias = id("as")
}
},
expect(
Expand Down
Loading

1 comment on commit f7bff3d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JMH Benchmark

Benchmark suite Current: f7bff3d Previous: b1d67b2 Ratio
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLCompiler15 123.70995887814281 us/op 124.40889551027503 us/op 0.99
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLCompiler30 237.43117745754813 us/op 238.14559472455124 us/op 1.00
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator15 529607.63185 us/op 531956.6932999999 us/op 1.00
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator30 1026046.32915 us/op 1039047.5218499998 us/op 0.99
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLEvaluator30WithData10 10517123.33265 us/op 10311482.59525 us/op 1.02
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLParser15 211.29098112337851 us/op 206.9495664186471 us/op 1.02
org.partiql.jmh.benchmarks.MultipleLikeBenchmark.testPartiQLParser30 405.5901383412893 us/op 390.83435024847296 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameCaseWhenThen 47.17053526432666 us/op 46.28398808279274 us/op 1.02
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery 63.93788873460844 us/op 63.40448695333758 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery01 334.07049297590686 us/op 324.6897554433036 us/op 1.03
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameComplexQuery02 568.6569058444906 us/op 572.4114052600651 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameExceptUnionIntersectSixty 215.148565704273 us/op 216.60542519979157 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameExec20Expressions 68.4652913472532 us/op 76.65637152354086 us/op 0.89
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameFromLet 48.82184023653325 us/op 48.56285803874688 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGraphPattern 47.65981962149432 us/op 44.739022095711654 us/op 1.07
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGraphPreFilters 73.44574232973505 us/op 66.82881338263432 us/op 1.10
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameGroupLimit 57.64799702745169 us/op 58.62933123551206 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameLongFromSourceOrderBy 72.72917348739033 us/op 71.81734058399446 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameManyJoins 69.26178546877402 us/op 66.48879777247556 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameNestedAggregates 118.37898531474089 us/op 116.86286924491132 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameNestedParen 22.656903243490046 us/op 22.220482839843548 us/op 1.02
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNamePivot 74.09433109676368 us/op 73.95456509033345 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuery15OrsAndLikes 222.92773974576116 us/op 221.5325423894655 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuery30Plus 122.53802535024037 us/op 125.37576785954916 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryFunc 57.87976734443056 us/op 58.62020514942532 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryFuncInProjection 127.9855119793356 us/op 133.19782324857465 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryList 86.64720080630613 us/op 85.95172316195557 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQueryNestedSelect 815.9457965691123 us/op 846.2961700777614 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameQuerySimple 20.162062149660304 us/op 20.08306372435477 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralJoins 26.938290944395753 us/op 26.744902085344386 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralProjections 84.11836836287941 us/op 82.9314348874017 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSeveralSelect 220.34386564761522 us/op 213.3048418824539 us/op 1.03
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSimpleInsert 35.28979956761712 us/op 33.35431827657312 us/op 1.06
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeJoins 26.32094422943316 us/op 26.644440324276253 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeProjections 36.19430658396169 us/op 35.07159318426362 us/op 1.03
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameSomeSelect 57.764358463266674 us/op 58.6175916920872 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameTimeZone 29.70691732116281 us/op 30.206455656276102 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameVeryLongQuery 367.53405055595067 us/op 362.6526201276632 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseFailNameVeryLongQuery01 1095.9593607519278 us/op 1093.6627913419306 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameCaseWhenThen 30.77203212532954 us/op 30.383732006487087 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameComplexQuery 271.0961472395501 us/op 276.4703610124461 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameComplexQuery01 124.37055774563832 us/op 122.62440805015399 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameExceptUnionIntersectSixty 248.5123312303157 us/op 248.73982958800934 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameExec20Expressions 74.03485019157408 us/op 74.07470771144244 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameFromLet 42.914947037366744 us/op 42.18286529634639 us/op 1.02
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGraphPattern 47.18372647733386 us/op 44.879603787521376 us/op 1.05
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGraphPreFilters 78.23830942303663 us/op 78.28968401623418 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameGroupLimit 38.48755421852702 us/op 38.818743554969274 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameLongFromSourceOrderBy 155.0589000351572 us/op 149.1465889236926 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameManyJoins 50.545973260606374 us/op 51.29588314786812 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameNestedAggregates 105.4149551784747 us/op 107.53343933111219 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameNestedParen 94.14243675744946 us/op 90.74818128235873 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseNamePivot 75.5168336074288 us/op 75.72304779993637 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuery15OrsAndLikes 201.56039156698176 us/op 199.7375297511003 us/op 1.01
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuery30Plus 69.94831534891456 us/op 70.63364800768144 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryFunc 147.0657515839902 us/op 143.35668339811636 us/op 1.03
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryFuncInProjection 106.10149883095127 us/op 107.02589128087295 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryList 90.85043229288013 us/op 92.53744530694787 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQueryNestedSelect 149.88976069156794 us/op 149.9405861470423 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameQuerySimple 15.734556037396368 us/op 15.136949228778187 us/op 1.04
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralJoins 85.7466281274066 us/op 84.35006170392934 us/op 1.02
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralProjections 63.78456555646238 us/op 64.01442191337533 us/op 1.00
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSeveralSelect 129.35180006119802 us/op 132.49281721790777 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSimpleInsert 25.57194662702777 us/op 25.74997880344386 us/op 0.99
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeJoins 25.595640702026742 us/op 24.73179221553043 us/op 1.03
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeProjections 21.454929394642893 us/op 23.438636349094637 us/op 0.92
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameSomeSelect 40.86117152488956 us/op 41.69627245781816 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameTimeZone 10.70986507800516 us/op 10.965839888101808 us/op 0.98
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameVeryLongQuery 481.0118417067741 us/op 499.0581438913092 us/op 0.96
org.partiql.jmh.benchmarks.ParserBenchmark.parseNameVeryLongQuery01 1373.0031639925896 us/op 1390.9681305640354 us/op 0.99
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLCompiler 9.643845511132582 us/op 10.01399116814483 us/op 0.96
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLEvaluator 2.5912574435044045 us/op 2.59067292457159 us/op 1.00
org.partiql.jmh.benchmarks.PartiQLBenchmark.testPartiQLParser 13.921229356421076 us/op 14.353662754826525 us/op 0.97

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.