-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,640 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
partiql-planner/src/test/kotlin/org/partiql/planner/HeaderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
package org.partiql.planner | ||
|
||
import org.junit.jupiter.api.Disabled | ||
import org.junit.jupiter.api.Test | ||
|
||
class HeaderTest { | ||
|
||
@Test | ||
@Disabled | ||
// @Disabled | ||
fun print() { | ||
println(PartiQLHeader) | ||
println(PartiQLHeader.toString()) | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
partiql-planner/src/test/kotlin/org/partiql/planner/typer/PartiQLTyperTestBase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package org.partiql.planner.typer | ||
|
||
import com.amazon.ionelement.api.ionString | ||
import com.amazon.ionelement.api.ionStructOf | ||
import org.junit.jupiter.api.DynamicContainer | ||
import org.junit.jupiter.api.DynamicTest | ||
import org.partiql.errors.Problem | ||
import org.partiql.errors.ProblemCallback | ||
import org.partiql.errors.ProblemSeverity | ||
import org.partiql.parser.PartiQLParserBuilder | ||
import org.partiql.plan.Statement | ||
import org.partiql.planner.PartiQLPlanner | ||
import org.partiql.planner.PartiQLPlannerBuilder | ||
import org.partiql.planner.test.PartiQLTest | ||
import org.partiql.planner.test.PartiQLTestProvider | ||
import org.partiql.plugins.memory.MemoryCatalog | ||
import org.partiql.plugins.memory.MemoryPlugin | ||
import org.partiql.types.StaticType | ||
import java.util.Random | ||
import java.util.stream.Stream | ||
|
||
abstract class PartiQLTyperTestBase { | ||
sealed class TestResult { | ||
data class Success(val expectedType: StaticType) : TestResult() { | ||
override fun toString(): String = "Success_$expectedType" | ||
} | ||
|
||
object Failure : TestResult() { | ||
override fun toString(): String = "Failure" | ||
} | ||
} | ||
|
||
internal class ProblemCollector : ProblemCallback { | ||
private val problemList = mutableListOf<Problem>() | ||
|
||
val problems: List<Problem> | ||
get() = problemList | ||
|
||
val hasErrors: Boolean | ||
get() = problemList.any { it.details.severity == ProblemSeverity.ERROR } | ||
|
||
val hasWarnings: Boolean | ||
get() = problemList.any { it.details.severity == ProblemSeverity.WARNING } | ||
|
||
override fun invoke(problem: Problem) { | ||
problemList.add(problem) | ||
} | ||
} | ||
|
||
companion object { | ||
internal val session: ((String) -> PartiQLPlanner.Session) = { catalog -> | ||
PartiQLPlanner.Session( | ||
queryId = Random().nextInt().toString(), | ||
userId = "test-user", | ||
currentCatalog = catalog, | ||
catalogConfig = mapOf( | ||
catalog to ionStructOf( | ||
"connector_name" to ionString("memory") | ||
) | ||
) | ||
) | ||
} | ||
} | ||
|
||
val inputs = PartiQLTestProvider().apply { load() } | ||
|
||
val testingPipeline: ((String, String, MemoryCatalog.Provider, ProblemCallback) -> PartiQLPlanner.Result) = { query, catalog, catalogProvider, collector -> | ||
val ast = PartiQLParserBuilder.standard().build().parse(query).root | ||
val planner = PartiQLPlannerBuilder().plugins(listOf(MemoryPlugin(catalogProvider))).build() | ||
planner.plan(ast, session(catalog), collector) | ||
} | ||
|
||
fun testGen( | ||
testCategory: String, | ||
tests: List<PartiQLTest>, | ||
argsMap: Map<TestResult, Set<List<StaticType>>>, | ||
): Stream<DynamicContainer> { | ||
val catalogProvider = MemoryCatalog.Provider() | ||
|
||
return tests.map { test -> | ||
val group = test.statement | ||
val children = argsMap.flatMap { (key, value) -> | ||
value.mapIndexed { index: Int, types: List<StaticType> -> | ||
val testName = "${testCategory}_${key}_$index" | ||
catalogProvider[testName] = MemoryCatalog.of( | ||
*( | ||
types.mapIndexed { i, t -> | ||
"t${i + 1}" to t | ||
}.toTypedArray() | ||
) | ||
) | ||
val displayName = "$group | $testName | $types" | ||
val statement = test.statement | ||
// Assert | ||
DynamicTest.dynamicTest(displayName) { | ||
val pc = ProblemCollector() | ||
if (key is TestResult.Success) { | ||
val result = testingPipeline(statement, testName, catalogProvider, pc) | ||
val root = (result.plan.statement as Statement.Query).root | ||
val actualType = root.type | ||
assert(actualType == key.expectedType) { | ||
""" | ||
expected Type is : ${key.expectedType} | ||
actual Type is : $actualType | ||
""".trimIndent() | ||
} | ||
} else { | ||
val result = testingPipeline(statement, testName, catalogProvider, pc) | ||
val root = (result.plan.statement as Statement.Query).root | ||
val actualType = root.type | ||
assert(actualType == StaticType.MISSING) { | ||
""" | ||
expected Type is : missing | ||
actual Type is : $actualType | ||
""".trimIndent() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
DynamicContainer.dynamicContainer(group, children) | ||
}.stream() | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
partiql-planner/src/test/kotlin/org/partiql/planner/typer/operator/OpArithmeticTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.partiql.planner.typer.operator | ||
|
||
import org.junit.jupiter.api.DynamicContainer | ||
import org.junit.jupiter.api.TestFactory | ||
import org.partiql.planner.typer.PartiQLTyperTestBase | ||
import org.partiql.planner.util.CastType | ||
import org.partiql.planner.util.allNumberType | ||
import org.partiql.planner.util.allSupportedType | ||
import org.partiql.planner.util.cartesianProduct | ||
import org.partiql.planner.util.castTable | ||
import org.partiql.types.StaticType | ||
import java.util.stream.Stream | ||
|
||
class OpArithmeticTest : PartiQLTyperTestBase() { | ||
@TestFactory | ||
fun arithmetic(): Stream<DynamicContainer> { | ||
val tests = listOf( | ||
"expr-61", | ||
"expr-62", | ||
"expr-63", | ||
"expr-64", | ||
"expr-65", | ||
).map { inputs.get("basics", it)!! } | ||
|
||
val argsMap: Map<TestResult, Set<List<StaticType>>> = buildMap { | ||
val successArgs = (allNumberType + listOf(StaticType.NULL, StaticType.MISSING)) | ||
.let { cartesianProduct(it, it) } | ||
val failureArgs = cartesianProduct( | ||
allSupportedType, | ||
allSupportedType | ||
).filterNot { | ||
successArgs.contains(it) | ||
}.toSet() | ||
|
||
successArgs.forEach { args: List<StaticType> -> | ||
val arg0 = args.first() | ||
val arg1 = args[1] | ||
if (args.contains(StaticType.MISSING)) { | ||
(this[TestResult.Success(StaticType.MISSING)] ?: setOf(args)).let { | ||
put(TestResult.Success(StaticType.MISSING), it + setOf(args)) | ||
} | ||
} else if (args.contains(StaticType.NULL)) { | ||
(this[TestResult.Success(StaticType.NULL)] ?: setOf(args)).let { | ||
put(TestResult.Success(StaticType.NULL), it + setOf(args)) | ||
} | ||
} else if (arg0 == arg1) { | ||
(this[TestResult.Success(arg1)] ?: setOf(args)).let { | ||
put(TestResult.Success(arg1), it + setOf(args)) | ||
} | ||
} else if (castTable(arg1, arg0) == CastType.COERCION) { | ||
(this[TestResult.Success(arg0)] ?: setOf(args)).let { | ||
put(TestResult.Success(arg0), it + setOf(args)) | ||
} | ||
} else { | ||
(this[TestResult.Success(arg1)] ?: setOf(args)).let { | ||
put(TestResult.Success(arg1), it + setOf(args)) | ||
} | ||
} | ||
Unit | ||
} | ||
|
||
put(TestResult.Failure, failureArgs) | ||
} | ||
|
||
return super.testGen("arithmetic", tests, argsMap) | ||
} | ||
} |
Oops, something went wrong.