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

Fixes pathing of expressions #1255

Merged
merged 1 commit into from
Nov 1, 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 @@ -115,6 +115,16 @@ class PartiQLSchemaInferencerTests {
@Execution(ExecutionMode.CONCURRENT)
fun testAggregations(tc: TestCase) = runTest(tc)

@ParameterizedTest
@MethodSource("scalarFunctions")
@Execution(ExecutionMode.CONCURRENT)
fun testScalarFunctions(tc: TestCase) = runTest(tc)

@ParameterizedTest
@MethodSource("pathExpressions")
@Execution(ExecutionMode.CONCURRENT)
fun testPathExpressions(tc: TestCase) = runTest(tc)

companion object {

private val root = this::class.java.getResource("/catalogs/default")!!.toURI().toPath().pathString
Expand Down Expand Up @@ -2127,6 +2137,139 @@ class PartiQLSchemaInferencerTests {
),
)

@JvmStatic
fun pathExpressions() = listOf(
SuccessTestCase(
name = "Index on literal list",
query = """
[0, 1, 2, 3][0]
""",
expected = INT4
),
SuccessTestCase(
name = "Index on global list",
query = """
dogs[0].breed
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = STRING
),
SuccessTestCase(
name = "Index on list attribute of global table",
query = """
SELECT typical_allergies[0] AS main_allergy FROM dogs
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = BagType(
StructType(
fields = mapOf(
"main_allergy" to STRING,
),
contentClosed = true,
constraints = setOf(
TupleConstraint.Open(false),
TupleConstraint.UniqueAttrs(true),
TupleConstraint.Ordered
)
)
)
),
)

@JvmStatic
fun scalarFunctions() = listOf(
SuccessTestCase(
name = "UPPER on binding tuple of literal string",
query = """
SELECT
UPPER(some_str) AS upper_str
FROM
<< { 'some_str': 'hello world!' } >>
AS t
""",
expected = BagType(
StructType(
fields = mapOf(
"upper_str" to STRING,
),
contentClosed = true,
constraints = setOf(
TupleConstraint.Open(false),
TupleConstraint.UniqueAttrs(true),
TupleConstraint.Ordered
)
)
)
),
SuccessTestCase(
name = "UPPER on literal string",
query = """
UPPER('hello world')
""",
expected = STRING
),
SuccessTestCase(
name = "UPPER on global string",
query = """
UPPER(os)
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = STRING
),
SuccessTestCase(
name = "UPPER on global string",
query = """
UPPER(os)
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = STRING
),
SuccessTestCase(
name = "UPPER on global struct",
query = """
UPPER(person.ssn)
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = STRING
),
SuccessTestCase(
name = "UPPER on global nested struct",
query = """
UPPER(person.name."first")
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = STRING
),
SuccessTestCase(
name = "UPPER on global table",
query = """
SELECT UPPER(breed) AS upper_breed
FROM dogs
""",
catalog = "pql",
catalogPath = listOf("main"),
expected = BagType(
StructType(
fields = mapOf(
"upper_breed" to STRING,
),
contentClosed = true,
constraints = setOf(
TupleConstraint.Open(false),
TupleConstraint.UniqueAttrs(true),
TupleConstraint.Ordered
)
)
)
),
)

@JvmStatic
fun aggregationCases() = listOf(
SuccessTestCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,9 @@ internal class PlanTyper(
// rewrite root
rex(type, op) to steps
}
else -> node.root to node.steps
else -> visitRex(node.root, node.root.type) to node.steps
}

// short-circuit if whole path was matched
if (steps.isEmpty()) {
return root
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
type: "list",
items: {
type: "struct",
constraints: [closed],
fields: [
{
name: "breed",
type: "string",
},
{
name: "avg_height",
type: "float32",
},
{
name: "typical_allergies",
type: {
type: "list",
items: "string"
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// String representing the current operating system
"string"
Loading