Skip to content

Commit

Permalink
Adds literal STRUCT test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedquinn committed Dec 12, 2023
1 parent dccab37 commit a87e4e3
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import org.partiql.parser.PartiQLParserBuilder
import org.partiql.planner.PartiQLPlanner
import org.partiql.planner.PartiQLPlannerBuilder
import org.partiql.value.BagValue
import org.partiql.value.PartiQLValue
import org.partiql.value.PartiQLValueExperimental
import org.partiql.value.bagValue
import org.partiql.value.boolValue
import org.partiql.value.int32Value
import org.partiql.value.nullValue
import org.partiql.value.stringValue
import org.partiql.value.structValue
import kotlin.test.assertEquals

Expand Down Expand Up @@ -98,4 +100,39 @@ class PartiQLEngineDefaultTest {
val expected = bagValue(sequenceOf(structValue(sequenceOf("a" to int32Value(1), "b" to nullValue()))))
assertEquals(expected, output)
}

@OptIn(PartiQLValueExperimental::class)
@Test
fun testStruct() {
val source = """
SELECT VALUE {
'a': 1,
'b': NULL,
c : d
}
FROM <<
{ 'c': 'hello', 'd': 'world' }
>>
""".trimIndent()
val statement = parser.parse(source).root
val session = PartiQLPlanner.Session("q", "u")
val plan = planner.plan(statement, session)

val prepared = engine.prepare(plan.plan)
val result = engine.execute(prepared) as PartiQLResult.Value
val output = result.value

val expected: PartiQLValue = bagValue(
sequenceOf(
structValue(
sequenceOf(
"a" to int32Value(1),
"b" to nullValue(),
"hello" to stringValue("world")
)
)
)
)
assertEquals(expected, output)
}
}

0 comments on commit a87e4e3

Please sign in to comment.