Skip to content

Commit c6aea9d

Browse files
committed
Pass sproc name metas, modify top-level token checks
1 parent d218a50 commit c6aea9d

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

lang/src/org/partiql/lang/ast/ExprNodeToStatement.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.partiql.lang.ast
22

33
import com.amazon.ionelement.api.toIonElement
44
import org.partiql.lang.domains.PartiqlAst
5+
import org.partiql.pig.runtime.SymbolPrimitive
56
import org.partiql.pig.runtime.asPrimitive
67

78
/** Converts an [ExprNode] to a [PartiqlAst.statement]. */
@@ -23,6 +24,9 @@ fun ExprNode.toAstStatement(): PartiqlAst.Statement {
2324
private fun PartiQlMetaContainer.toElectrolyteMetaContainer(): ElectrolyteMetaContainer =
2425
com.amazon.ionelement.api.metaContainerOf(map { it.tag to it })
2526

27+
private fun SymbolicName.toSymbolPrimitive() : SymbolPrimitive =
28+
SymbolPrimitive(this.name, this.metas.toElectrolyteMetaContainer())
29+
2630
private fun ExprNode.toAstDdl(): PartiqlAst.Statement {
2731
val thiz = this
2832
val metas = metas.toElectrolyteMetaContainer()
@@ -55,7 +59,7 @@ private fun ExprNode.toAstExec() : PartiqlAst.Statement {
5559

5660
return PartiqlAst.build {
5761
when (node) {
58-
is Exec -> exec(node.procedureName.name, node.args.map { it.toAstExpr() }, metas)
62+
is Exec -> exec_(node.procedureName.toSymbolPrimitive(), node.args.map { it.toAstExpr() }, metas)
5963
else -> error("Can't convert ${node.javaClass} to PartiqlAst.Statement.Exec")
6064
}
6165
}

lang/src/org/partiql/lang/syntax/SqlParser.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,10 +2243,13 @@ class SqlParser(private val ion: IonSystem) : Parser {
22432243
}
22442244

22452245
/**
2246-
* Checks that the given [Token] list does not have `EXEC` calls outside of the top level query. Throws
2246+
* Checks that the given [Token] list does not have any top-level tokens outside of the top level query. Throws
22472247
* an error if so.
2248+
*
2249+
* Currently only checks for `EXEC`. DDL and DML along with corresponding error codes to be added in the future
2250+
* (https://github.com/partiql/partiql-lang-kotlin/issues/354).
22482251
*/
2249-
private fun List<Token>.checkForUnexpectedExec() {
2252+
private fun List<Token>.checkUnexpectedTopLevelToken() {
22502253
for ((index, token) in this.withIndex()) {
22512254
if (token.keywordText == "exec" && index != 0) {
22522255
token.err("EXEC call found at unexpected location", PARSE_EXEC_AT_UNEXPECTED_LOCATION)
@@ -2257,7 +2260,7 @@ class SqlParser(private val ion: IonSystem) : Parser {
22572260
/** Entry point into the parser. */
22582261
override fun parseExprNode(source: String): ExprNode {
22592262
val tokens = SqlLexer(ion).tokenize(source)
2260-
tokens.checkForUnexpectedExec()
2263+
tokens.checkUnexpectedTopLevelToken()
22612264
val node = tokens.parseExpression()
22622265
val rem = node.remaining
22632266
if (!rem.onlyEndOfStatement()) {

0 commit comments

Comments
 (0)