diff --git a/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToBinder.kt b/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToBinder.kt index 4cfe7ca48c..e155afe8dc 100644 --- a/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToBinder.kt +++ b/partiql-ast/src/main/kotlin/org/partiql/ast/helpers/ToBinder.kt @@ -22,6 +22,7 @@ public fun Expr.toBinder(index: Int): Identifier.Symbol = when (this) { is Expr.Var -> this.identifier.toBinder() is Expr.Path -> this.toBinder(index) is Expr.Cast -> this.value.toBinder(index) + is Expr.SessionAttribute -> this.attribute.name.uppercase().toBinder() else -> col(index).toBinder() } diff --git a/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt b/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt index 9078480a91..59aed25d0f 100644 --- a/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt +++ b/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt @@ -33,6 +33,7 @@ import org.partiql.types.IntType import org.partiql.types.ListType import org.partiql.types.SexpType import org.partiql.types.StaticType +import org.partiql.types.StaticType.Companion.DATE import org.partiql.types.StaticType.Companion.DECIMAL import org.partiql.types.StaticType.Companion.INT import org.partiql.types.StaticType.Companion.INT4 @@ -385,6 +386,35 @@ class PartiQLSchemaInferencerTests { query = "SELECT VALUE a FROM [ 0 ] AS a WHERE CURRENT_USER = 5", expected = BagType(INT), ), + SuccessTestCase( + name = "Testing CURRENT_USER and CURRENT_DATE Binders", + query = """ + SELECT + CURRENT_USER, + CURRENT_DATE, + CURRENT_USER AS "curr_user", + CURRENT_DATE AS "curr_date", + CURRENT_USER || ' is my name.' AS name_desc + FROM << 0, 1 >>; + """.trimIndent(), + expected = BagType( + StructType( + fields = listOf( + StructType.Field("CURRENT_USER", STRING.asNullable()), + StructType.Field("CURRENT_DATE", DATE), + StructType.Field("curr_user", STRING.asNullable()), + StructType.Field("curr_date", DATE), + StructType.Field("name_desc", STRING.asNullable()), + ), + contentClosed = true, + constraints = setOf( + TupleConstraint.Open(false), + TupleConstraint.UniqueAttrs(true), + TupleConstraint.Ordered + ) + ) + ) + ), ErrorTestCase( name = "Current User (String) PLUS String", query = "CURRENT_USER + 'hello'",