|
| 1 | +package org.partiql.lang.eval |
| 2 | + |
| 3 | +import org.junit.jupiter.params.ParameterizedTest |
| 4 | +import org.junit.jupiter.params.provider.MethodSource |
| 5 | +import org.partiql.lang.eval.evaluatortestframework.EvaluatorTestTarget |
| 6 | +import org.partiql.lang.util.testdsl.IonResultTestCase |
| 7 | + |
| 8 | +/** |
| 9 | + * This test class is effectively the same as [EvaluatorTests] however it: |
| 10 | + * |
| 11 | + * - enables the static type inferencer ([org.partiql.lang.eval.visitors.StaticTypeInferenceVisitorTransform]) |
| 12 | + * - sets the [org.partiql.lang.eval.CompileOptions.thunkReturnTypeAssertions] compile option |
| 13 | + * - only runs in permissive mode. |
| 14 | + * |
| 15 | + * The intent here is to test if the inferencer agrees with the runtime behavior of the evaluator. |
| 16 | + */ |
| 17 | +class EvaluatorStaticTypeTests { |
| 18 | + |
| 19 | + companion object { |
| 20 | + private val mockDb = EVALUATOR_TEST_SUITE.mockDb() |
| 21 | + |
| 22 | + // These tests are known to be failing. If they are fixed but not removed from this list |
| 23 | + // the test will fail. (This forces us to keep this list up-to-date.) |
| 24 | + private val FAILING_TESTS = hashSetOf( |
| 25 | + // https://github.com/partiql/partiql-lang-kotlin/issues/497 |
| 26 | + "selectIndexStruct", |
| 27 | + |
| 28 | + // https://github.com/partiql/partiql-lang-kotlin/issues/498 |
| 29 | + "ordinalAccessWithNegativeIndex", |
| 30 | + "ordinalAccessWithNegativeIndexAndBindings", |
| 31 | + |
| 32 | + // https://github.com/partiql/partiql-lang-kotlin/issues/499 |
| 33 | + "selectJoinOnClauseScoping", |
| 34 | + |
| 35 | + // Unimplemented features: |
| 36 | + |
| 37 | + // Support non-struct types for wildcard projections in STIVT |
| 38 | + // https://github.com/partiql/partiql-lang-kotlin/issues/500 |
| 39 | + "functionCall", |
| 40 | + |
| 41 | + "selectCorrelatedLeftJoin", |
| 42 | + "selectCorrelatedLeftJoinOnClause", |
| 43 | + "simpleCase", |
| 44 | + "simpleCaseNoElse", |
| 45 | + "searchedCase", |
| 46 | + "searchedCaseNoElse", |
| 47 | + |
| 48 | + // STIR's should support non-sequence types in UNPIVOT expression |
| 49 | + // https://github.com/partiql/partiql-lang-kotlin/issues/501 |
| 50 | + "selectCorrelatedUnpivot", |
| 51 | + "nestedSelectJoinWithUnpivot", |
| 52 | + "unpivotMissingWithAsAndAt", |
| 53 | + "unpivotMissingCrossJoinWithAsAndAt", |
| 54 | + |
| 55 | + // TODO: why are these failing? |
| 56 | + "selectDistinctStarBags", |
| 57 | + "selectDistinctStarLists", |
| 58 | + "selectDistinctStarMixed", |
| 59 | + "nestedSelectJoinLimit", |
| 60 | + |
| 61 | + // STIR does not support path wildcards -i.e. `foo[*]` yet |
| 62 | + "pathFieldStructLiteral", |
| 63 | + "pathIndexStructLiteral", |
| 64 | + "pathIndexStructOutOfBoundsLowLiteral", |
| 65 | + "pathIndexStructOutOfBoundsHighLiteral", |
| 66 | + "pathUnpivotWildcard", |
| 67 | + "pathUnpivotWildcardFieldsAfter", |
| 68 | + "pathSimpleWildcard", |
| 69 | + "pathWildcardPath", |
| 70 | + "pathWildcard", |
| 71 | + "pathDoubleWildCard", |
| 72 | + "pathDoubleUnpivotWildCard", |
| 73 | + "pathWildCardOverScalar", |
| 74 | + "pathUnpivotWildCardOverScalar", |
| 75 | + "pathWildCardOverScalarMultiple", |
| 76 | + "pathUnpivotWildCardOverScalarMultiple", |
| 77 | + "pathWildCardOverStructMultiple", |
| 78 | + "pathUnpivotWildCardOverStructMultiple", |
| 79 | + "selectFromScalarAndAtUnpivotWildCardOverScalar", |
| 80 | + "selectFromListAndAtUnpivotWildCardOverScalar", |
| 81 | + "selectFromBagAndAtUnpivotWildCardOverScalar", |
| 82 | + "selectPathUnpivotWildCardOverStructMultiple", |
| 83 | + "selectStarSingleSourceHoisted", |
| 84 | + "selectImplicitAndExplicitAliasSingleSourceHoisted", |
| 85 | + |
| 86 | + // these are intended to test the `IN` operator but also use path wildcards which aren't supported |
| 87 | + // by STIR |
| 88 | + "inPredicate", |
| 89 | + "inPredicateSingleItem", |
| 90 | + "inPredicateSingleExpr", |
| 91 | + "inPredicateSingleItemListVar", |
| 92 | + "notInPredicate", |
| 93 | + "notInPredicateSingleItem", |
| 94 | + "notInPredicateSingleExpr", |
| 95 | + "notInPredicateSingleItemListVar", |
| 96 | + "notInPredicateSingleListVar", |
| 97 | + "notInPredicateSubQuerySelectValue", |
| 98 | + "inPredicateWithTableConstructor", |
| 99 | + "notInPredicateWithTableConstructor", |
| 100 | + "inPredicateSingleListVar", |
| 101 | + "inPredicateSubQuerySelectValue", |
| 102 | + "inPredicateWithExpressionOnRightSide", |
| 103 | + "notInPredicateWithExpressionOnRightSide", |
| 104 | + |
| 105 | + "parameters", |
| 106 | + // STIR does not support aggregates |
| 107 | + "selectDistinctAggregationWithGroupBy", |
| 108 | + "selectDistinctWithGroupBy", |
| 109 | + "selectDistinctWithJoin", |
| 110 | + "selectDistinctStarScalars", |
| 111 | + "selectDistinctStarUnknowns", |
| 112 | + "selectDistinctStarIntegers", |
| 113 | + // STIR does support `FROM` sources that aren't a collection of structs. |
| 114 | + "projectOfListOfList", |
| 115 | + "projectOfBagOfBag", |
| 116 | + "projectOfListOfBag", |
| 117 | + "projectOfBagOfList", |
| 118 | + "projectOfSexp", |
| 119 | + "emptySymbolInGlobals", |
| 120 | + "semicolonAtEndOfExpression", |
| 121 | + // STIR does not support unpivot in path i.e. `<expr>.*` |
| 122 | + "unpivotMissing", |
| 123 | + "unpivotEmptyStruct", |
| 124 | + "pathUnpivotEmptyStruct1", |
| 125 | + "pathUnpivotEmptyStruct2", |
| 126 | + "pathUnpivotEmptyStruct3", |
| 127 | + "projectOfUnpivotPath", |
| 128 | + |
| 129 | + // PIVOT not supported by STIR |
| 130 | + "pivotUnpivotWithWhereLimit", |
| 131 | + "unpivotStructWithMissingField", |
| 132 | + |
| 133 | + // STIR does not support `CompilePipeline.undefinedVariableBehavior` |
| 134 | + // (these are likely to be a permanent entries to this list since STR/STIR will probably |
| 135 | + // never support undefined variables). |
| 136 | + "undefinedUnqualifiedVariableWithUndefinedVariableBehaviorMissing", |
| 137 | + "undefinedUnqualifiedVariableIsNullExprWithUndefinedVariableBehaviorMissing", |
| 138 | + "undefinedUnqualifiedVariableIsMissingExprWithUndefinedVariableBehaviorMissing", |
| 139 | + |
| 140 | + ) |
| 141 | + |
| 142 | + @JvmStatic |
| 143 | + @Suppress("unused") |
| 144 | + fun evaluatorStaticTypeTests() = EVALUATOR_TEST_SUITE.getAllTests( |
| 145 | + EvaluatorTests.AST_EVALUATOR_SKIP_LIST.union(FAILING_TESTS) |
| 146 | + ).map { |
| 147 | + it.copy( |
| 148 | + compileOptionsBuilderBlock = { |
| 149 | + it.compileOptionsBuilderBlock(this) |
| 150 | + |
| 151 | + // set permissive mode |
| 152 | + typingMode(TypingMode.PERMISSIVE) |
| 153 | + thunkOptions { |
| 154 | + // enable evaluation time type checking |
| 155 | + evaluationTimeTypeChecks(ThunkReturnTypeAssertions.ENABLED) |
| 156 | + } |
| 157 | + } |
| 158 | + ) |
| 159 | + } |
| 160 | + } |
| 161 | + |
| 162 | + @ParameterizedTest |
| 163 | + @MethodSource("evaluatorStaticTypeTests") |
| 164 | + fun allTests(tc: IonResultTestCase) = |
| 165 | + tc.runTestCase( |
| 166 | + db = mockDb, |
| 167 | + // the planner doesn't yet support type inferencing pass needed to make this work |
| 168 | + EvaluatorTestTarget.COMPILER_PIPELINE, |
| 169 | + ) |
| 170 | + // Enable the static type inferencer for this |
| 171 | + { this.globalTypeBindings(mockDb.typeBindings) } |
| 172 | +} |
0 commit comments