Skip to content

Commit

Permalink
Adds the correct parsing for table value constructors
Browse files Browse the repository at this point in the history
Adds the conversion for ExprValues to a plan node
  • Loading branch information
johnedquinn committed Dec 7, 2024
1 parent 801dd2e commit 5b594e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ import org.partiql.ast.expr.ExprCall
import org.partiql.ast.expr.ExprLit
import org.partiql.ast.expr.ExprPath
import org.partiql.ast.expr.ExprQuerySet
import org.partiql.ast.expr.ExprRowValue
import org.partiql.ast.expr.PathStep
import org.partiql.ast.expr.Scope
import org.partiql.ast.expr.SessionAttribute
Expand Down Expand Up @@ -1616,7 +1617,12 @@ internal class PartiQLParserDefault : PartiQLParser {
}

override fun visitTableValueConstructor(ctx: GeneratedParser.TableValueConstructorContext) = translate(ctx) {
val rows = visitOrEmpty<Expr>(ctx.rowValueExpressionList().expr())
val rows = ctx.rowValueExpressionList().expr().map {
when (val row = visitAs<Expr>(it)) {
is ExprRowValue -> row
else -> exprRowValue(listOf(row), false)
}
}
exprValues(rows)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.partiql.ast.expr.ExprSessionAttribute
import org.partiql.ast.expr.ExprStruct
import org.partiql.ast.expr.ExprSubstring
import org.partiql.ast.expr.ExprTrim
import org.partiql.ast.expr.ExprValues
import org.partiql.ast.expr.ExprVarRef
import org.partiql.ast.expr.ExprVariant
import org.partiql.ast.expr.PathStep
Expand Down Expand Up @@ -494,6 +495,11 @@ internal object RexConverter {
return rex(ANY, op)
}

override fun visitExprValues(node: ExprValues, ctx: Env): Rex {
val rows = node.rows.map { visitExprCoerce(it, ctx) }
return rex(BAG, rexOpCollection(rows))
}

/**
* Construct Rel(Scan([path])).
*
Expand Down

0 comments on commit 5b594e7

Please sign in to comment.