Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds session binders #1252

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading