Skip to content

Commit 490c708

Browse files
committed
add test cases
1 parent c71c11f commit 490c708

File tree

2 files changed

+105
-48
lines changed

2 files changed

+105
-48
lines changed

partiql-eval/src/test/kotlin/org/partiql/eval/internal/PartiQLEngineDefaultTest.kt

Lines changed: 94 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,54 +1291,107 @@ class PartiQLEngineDefaultTest {
12911291
).assert()
12921292

12931293
@Test
1294+
// TODO: Add to conformance tests
12941295
fun wildCard() =
12951296
SuccessTestCase(
12961297
input = """
1297-
[
1298-
{
1299-
'id':'5',
1300-
'books':[
1301-
{
1302-
'title':'A',
1303-
'price':5.0
1304-
},
1305-
{
1306-
'title':'B',
1307-
'price':2.0
1308-
}
1309-
]
1310-
},
1311-
{
1312-
'id':'6',
1313-
'books':[
1314-
{
1315-
'title':'A',
1316-
'price':5.0
1317-
},
1318-
{
1319-
'title':'E',
1320-
'price':2.0
1321-
}
1322-
]
1323-
},
1324-
{
1325-
'id':7,
1326-
'books':[]
1327-
}
1328-
][*].books[*].title
1298+
[
1299+
{ 'id':'5',
1300+
'books':[
1301+
{ 'title':'A',
1302+
'price':5.0,
1303+
'authors': [{'name': 'John'}, {'name': 'Doe'}]
1304+
},
1305+
{ 'title':'B',
1306+
'price':2.0,
1307+
'authors': [{'name': 'Zoe'}, {'name': 'Bill'}]
1308+
}
1309+
]
1310+
},
1311+
{ 'id':'6',
1312+
'books':[
1313+
{ 'title':'A',
1314+
'price':5.0,
1315+
'authors': [{'name': 'John'}, {'name': 'Doe'}]
1316+
},
1317+
{ 'title':'E',
1318+
'price':2.0,
1319+
'authors': [{'name': 'Zoe'}, {'name': 'Bill'}]
1320+
}
1321+
]
1322+
},
1323+
{ 'id':7,
1324+
'books':[]
1325+
}
1326+
][*].books[*].authors[*].name
13291327
""".trimIndent(),
1330-
expected = bagValue(listOf(stringValue("A"), stringValue("B"), stringValue("A"), stringValue("E")))
1328+
expected = bagValue(
1329+
listOf(
1330+
stringValue("John"), stringValue("Doe"), stringValue("Zoe"), stringValue("Bill"),
1331+
stringValue("John"), stringValue("Doe"), stringValue("Zoe"), stringValue("Bill")
1332+
)
1333+
)
13311334
).assert()
13321335

13331336
@Test
1334-
fun wildCard2() {
1335-
val query = """
1336-
{'a':1, 'b':2}.*
1337-
""".trimIndent()
1338-
val expected = bagValue(listOf(int32Value(1), int32Value(2)))
1337+
// TODO: add to conformance tests
1338+
// Note that the existing pipeline produced identical result when supplying with
1339+
// SELECT VALUE v2.name FROM e as v0, v0.books as v1, unpivot v1.authors as v2;
1340+
// But it produces different result when supplying with e[*].books[*].authors.*
1341+
// <<
1342+
// <<{ 'name': 'John'},{'name': 'Doe'} >>,
1343+
// ...
1344+
// >>
1345+
fun unpivot() =
13391346
SuccessTestCase(
1340-
query,
1341-
expected
1347+
input = """
1348+
[
1349+
{ 'id':'5',
1350+
'books':[
1351+
{ 'title':'A',
1352+
'price':5.0,
1353+
'authors': {
1354+
'first': {'name': 'John'},
1355+
'second': {'name': 'Doe'}
1356+
}
1357+
},
1358+
{ 'title':'B',
1359+
'price':2.0,
1360+
'authors': {
1361+
'first': {'name': 'Zoe'},
1362+
'second': {'name': 'Bill'}
1363+
}
1364+
}
1365+
]
1366+
},
1367+
{ 'id':'6',
1368+
'books':[
1369+
{ 'title':'A',
1370+
'price':5.0,
1371+
'authors': {
1372+
'first': {'name': 'John'},
1373+
'second': {'name': 'Doe'}
1374+
}
1375+
},
1376+
{ 'title':'E',
1377+
'price':2.0,
1378+
'authors': {
1379+
'first': {'name': 'Zoe'},
1380+
'second': {'name': 'Bill'}
1381+
}
1382+
}
1383+
]
1384+
},
1385+
{ 'id':7,
1386+
'books':[]
1387+
}
1388+
][*].books[*].authors.*.name
1389+
""".trimIndent(),
1390+
expected = bagValue(
1391+
listOf(
1392+
stringValue("John"), stringValue("Doe"), stringValue("Zoe"), stringValue("Bill"),
1393+
stringValue("John"), stringValue("Doe"), stringValue("Zoe"), stringValue("Bill")
1394+
)
1395+
)
13421396
).assert()
1343-
}
13441397
}

partiql-planner/src/main/kotlin/org/partiql/planner/internal/typer/PlanTyper.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,19 @@ internal class PlanTyper(
171171
val kType = STRING
172172

173173
// value type, possibly coerced.
174-
val vType = when (val t = rex.type) {
175-
is StructType -> {
176-
if (t.contentClosed || t.constraints.contains(TupleConstraint.Open(false))) {
177-
unionOf(t.fields.map { it.value }.toSet()).flatten()
178-
} else {
179-
ANY
174+
val vType = rex.type.allTypes.map { type ->
175+
when (type) {
176+
is StructType -> {
177+
if (type.contentClosed || type.constraints.contains(TupleConstraint.Open(false))) {
178+
unionOf(type.fields.map { it.value }.toSet()).flatten()
179+
} else {
180+
ANY
181+
}
180182
}
183+
else -> type
181184
}
182-
else -> t
185+
}.let {
186+
unionOf(it.toSet())
183187
}
184188

185189
// rewrite

0 commit comments

Comments
 (0)