Skip to content

Commit

Permalink
Adds session binders
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Oct 25, 2023
1 parent 9e151c2 commit b789b8a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'",
Expand Down

0 comments on commit b789b8a

Please sign in to comment.