Skip to content
Open
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 @@ -20,7 +20,8 @@

package com.apple.foundationdb.relational.yamltests.command;

import com.apple.foundationdb.relational.api.RelationalResultSet;

Check notice on line 23 in yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/command/QueryConfig.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 76.1% (178/234 lines) | Changed lines: 47.4% (9/19 lines)
import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
import com.apple.foundationdb.relational.recordlayer.ErrorCapturingResultSet;
import com.apple.foundationdb.relational.util.Assert;
import com.apple.foundationdb.relational.yamltests.CustomYamlConstructor;
Expand Down Expand Up @@ -242,6 +243,7 @@
}

private static QueryConfig getCheckErrorConfig(@Nullable Object value, @Nonnull final YamlReference reference) {
final String expectedCode = resolveErrorCode(value, reference);
return new QueryConfig(QUERY_CONFIG_ERROR, value, reference) {

@Override
Expand Down Expand Up @@ -269,15 +271,51 @@
@Override
void checkErrorInternal(@Nonnull SQLException e, @Nonnull String queryDescription) {
logger.debug("⛳️ Checking error code resulted from executing '{}'", queryDescription);
if (!e.getSQLState().equals(getVal())) {
reportTestFailure("‼️ expecting '" + getVal() + "' error code, got '" + e.getSQLState() + "' instead at " + getReference() + "!", e);
final String actualCode = e.getSQLState();
if (!actualCode.equals(expectedCode)) {
reportTestFailure("‼️ expecting '" + formatErrorCode(expectedCode) + "' error code, got '" + formatErrorCode(actualCode) + "' instead at " + getReference() + "!", e);
} else {
logger.debug("✅ error codes '{}' match!", getVal());
logger.debug("✅ error codes '{}' match!", expectedCode);
}
}
};
}

/**
* Resolves an error value from a yamsql file to a 5-character SQLSTATE code.
* Accepts either a raw 5-character SQLSTATE code (e.g. {@code "42601"}) or an
* {@link ErrorCode} enum name (e.g. {@code "SYNTAX_ERROR"}) for readability.
*/
private static String resolveErrorCode(@Nullable Object value, @Nonnull YamlReference reference) {
if (value == null) {
return null;
}
final String str = value.toString();
if (str.length() == 5) {
return str;
}
try {
return ErrorCode.valueOf(str).getErrorCode();
} catch (IllegalArgumentException e) {
throw new IllegalArgumentException("'" + str + "' is not a valid ErrorCode enum name or a 5-character SQLSTATE code at " + reference, e);
}
}

/**
* Formats a 5-character SQLSTATE code for display. If the code maps to a known
* {@link ErrorCode}, returns {@code "ENUM_NAME (code)"}; otherwise returns the raw code.
*/
private static String formatErrorCode(@Nullable String code) {
if (code == null) {
return "null";
}
final ErrorCode errorCode = ErrorCode.get(code);
if (errorCode == ErrorCode.UNKNOWN) {
return code;
}
return errorCode.name() + " (" + code + ")";
}

private static QueryConfig getCheckCountConfig(@Nullable Object value, @Nonnull final YamlReference reference) {
return new QueryConfig(QUERY_CONFIG_COUNT, value, reference) {

Expand Down
48 changes: 24 additions & 24 deletions yaml-tests/src/test/resources/aggregate-empty-table.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ test_block:
- result: [{0}]
-
- query: select count(*) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T2;
- explain: "AISCAN(T2_I1 <,> BY_GROUP -> [_0: VALUE:[0]]) | MAP (_ AS _0) | ON EMPTY NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
Expand Down Expand Up @@ -143,19 +143,19 @@ test_block:
- result: [{0}]
-
- query: select count(col2) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T2;
- explain: "AISCAN(T2_I3 <,> BY_GROUP -> [_0: VALUE:[0]]) | MAP (_ AS _0) | ON EMPTY NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
Expand Down Expand Up @@ -272,15 +272,15 @@ test_block:
- result: [{!null _}]
-
- query: select sum(col1) from T2 where col1 = 0 group by col2;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select sum(col1) from T2 where col2 = 0 group by col2;
- explain: "AISCAN(T2_I6 [EQUALS promote(@c10 AS LONG)] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) | MAP (_._1 AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select sum(col1) from T2 where col1 > 0 group by col2;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select sum(col1) from T2 where col2 > 0 group by col2;
- explain: "AISCAN(T2_I6 [[GREATER_THAN promote(@c10 AS LONG)]] BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) | MAP (_._1 AS _0)"
Expand Down Expand Up @@ -374,19 +374,19 @@ test_block:
- result: [{0}]
-
- query: select count(*) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(*) from T2;
- explain: "AISCAN(T2_I1 <,> BY_GROUP -> [_0: VALUE:[0]]) | MAP (_ AS _0) | ON EMPTY NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
Expand Down Expand Up @@ -450,19 +450,19 @@ test_block:
- result: [{0}]
-
- query: select count(col2) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 where col1 = 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T1 where col1 > 0 group by col1;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select count(col2) from T2;
- explain: "AISCAN(T2_I3 <,> BY_GROUP -> [_0: VALUE:[0]]) | MAP (_ AS _0) | ON EMPTY NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
Expand Down Expand Up @@ -577,14 +577,14 @@ test_block:
- result: [{!l 0}]
-
- query: select sum(col1) from T2 where col1 = 0 group by col2;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
- query: select sum(col1) from T2 where col2 = 0 group by col2;
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select sum(col1) from T2 where col1 > 0 group by col2;
- error: "0AF00"
- error: UNSUPPORTED_QUERY
# -
# # TODO ([POST] Enhance SUM aggregate index to disambiguate null results and 0 results)
# - query: select sum(col1) from T2 where col2 > 0 group by col2;
Expand Down
14 changes: 7 additions & 7 deletions yaml-tests/src/test/resources/aggregate-index-tests.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ test_block:
- query: select b, c, d, e, max(x) from t5 where a = 0 group by a, b, c, d, e order by b, max(x), c, d, e
- explain: "AISCAN(MV16 [EQUALS promote(@c18 AS LONG)] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: KEY:[3], _3: KEY:[4], _4: KEY:[5], _5: KEY:[2]]) | MAP (_._1 AS B, _._2 AS C, _._3 AS D, _._4 AS E, _._5 AS _4)"
- initialVersionLessThan: 4.3.5.0
- error: "0AF00"
- error: UNSUPPORTED_QUERY
- initialVersionAtLeast: 4.3.5.0
- resultMetadata: [{B: STRING}, {C: BIGINT}, {D: BIGINT}, {E: STRING}, {_4: BIGINT}]
- result: [
Expand Down Expand Up @@ -412,7 +412,7 @@ test_block:
- query: select b, c, d, e, min(x) from t5 where a = 0 group by a, b, c, d, e order by b, min(x), c, d, e
- explain: "AISCAN(MV17 [EQUALS promote(@c18 AS LONG)] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: KEY:[3], _3: KEY:[4], _4: KEY:[5], _5: KEY:[2]]) | MAP (_._1 AS B, _._2 AS C, _._3 AS D, _._4 AS E, _._5 AS _4)"
- initialVersionLessThan: 4.3.5.0
- error: "0AF00"
- error: UNSUPPORTED_QUERY
- initialVersionAtLeast: 4.3.5.0
- resultMetadata: [{B: STRING}, {C: BIGINT}, {D: BIGINT}, {E: STRING}, {_4: BIGINT}]
- result: [
Expand Down Expand Up @@ -443,7 +443,7 @@ test_block:
- query: select b, c, d, e, max(x) from t5 where a = 0 group by a, b, c, d, e order by b, c, max(x), d, e
- explain: "AISCAN(MV18 [EQUALS promote(@c18 AS LONG)] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: KEY:[2], _3: KEY:[4], _4: KEY:[5], _5: KEY:[3]]) | MAP (_._1 AS B, _._2 AS C, _._3 AS D, _._4 AS E, _._5 AS _4)"
- initialVersionLessThan: 4.3.5.0
- error: "0AF00"
- error: UNSUPPORTED_QUERY
- initialVersionAtLeast: 4.3.5.0
- resultMetadata: [{B: STRING}, {C: BIGINT}, {D: BIGINT}, {E: STRING}, {_4: BIGINT}]
- result: [
Expand Down Expand Up @@ -474,7 +474,7 @@ test_block:
- query: select b, c, d, e, min(x) from t5 where a = 0 group by a, b, c, d, e order by b, c, min(x), d, e
- explain: "AISCAN(MV19 [EQUALS promote(@c18 AS LONG)] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: KEY:[2], _3: KEY:[4], _4: KEY:[5], _5: KEY:[3]]) | MAP (_._1 AS B, _._2 AS C, _._3 AS D, _._4 AS E, _._5 AS _4)"
- initialVersionLessThan: 4.3.5.0
- error: "0AF00"
- error: UNSUPPORTED_QUERY
- initialVersionAtLeast: 4.3.5.0
- resultMetadata: [{B: STRING}, {C: BIGINT}, {D: BIGINT}, {E: STRING}, {_4: BIGINT}]
- result: [
Expand Down Expand Up @@ -583,7 +583,7 @@ test_block:
- query: select b, c, d, e, max(x) from t5 where a = 0 group by a, b, c, d, e having b IN ('foo', 'bar') and d IN (1, 2) order by max(x), c, e
- explain: "[IN arrayDistinct(@c33)] INUNION q0 -> { [IN arrayDistinct(promote(@c41 AS ARRAY(LONG)))] INUNION q1 -> { AISCAN(MV16 [EQUALS promote(@c18 AS LONG), EQUALS q0] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: KEY:[3], _3: KEY:[4], _4: KEY:[5], _5: KEY:[2]]) | FILTER _._3 EQUALS q1 | MAP (_._1 AS B, _._2 AS C, _._3 AS D, _._4 AS E, _._5 AS _4) } COMPARE BY (_._4, _.C, _.E, _.D) } COMPARE BY (_._4, _.C, _.E, _.B)"
- initialVersionLessThan: 4.3.5.0
- error: "0AF00"
- error: UNSUPPORTED_QUERY
- initialVersionAtLeast: 4.3.5.0
- resultMetadata: [{B: STRING}, {C: BIGINT}, {D: BIGINT}, {E: STRING}, {_4: BIGINT}]
- result: [
Expand All @@ -600,7 +600,7 @@ test_block:
- query: select b, c, d, e, min(x) from t5 where a = 0 group by a, b, c, d, e having b IN ('foo', 'bar') and d IN (1, 2) order by min(x), c, e
- explain: "[IN arrayDistinct(@c33)] INUNION q0 -> { [IN arrayDistinct(promote(@c41 AS ARRAY(LONG)))] INUNION q1 -> { AISCAN(MV17 [EQUALS promote(@c18 AS LONG), EQUALS q0] BY_GROUP -> [_0: KEY:[0], _1: KEY:[1], _2: KEY:[3], _3: KEY:[4], _4: KEY:[5], _5: KEY:[2]]) | FILTER _._3 EQUALS q1 | MAP (_._1 AS B, _._2 AS C, _._3 AS D, _._4 AS E, _._5 AS _4) } COMPARE BY (_._4, _.C, _.E, _.D) } COMPARE BY (_._4, _.C, _.E, _.B)"
- initialVersionLessThan: 4.3.5.0
- error: "0AF00"
- error: UNSUPPORTED_QUERY
- initialVersionAtLeast: 4.3.5.0
- resultMetadata: [{B: STRING}, {C: BIGINT}, {D: BIGINT}, {E: STRING}, {_4: BIGINT}]
- result: [
Expand Down Expand Up @@ -688,7 +688,7 @@ test_block:
# Even though the aggregate index will be rolled-up to col2 because of the implicit grouping produced by the equality
# predicate, it is not possible to reference it in the projected columns.
- query: select col2, sum(col3) as s from T2 where col2 = 2
- error: "42803"
- error: GROUPING_ERROR
-
# A sum aggregate that matches no records should return null
- query: select sum(col3) as s from T2 where col2 = 90
Expand Down
10 changes: 5 additions & 5 deletions yaml-tests/src/test/resources/array-join-at.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ test_block:
-
# Applying AT to a normal table source item (that does not produce an array) is invalid.
- query: SELECT "id", "at" FROM T1 AT "at"
- error: "42809" # "AT clause requires an array-typed column, but 'T1' is a table"
- error: WRONG_OBJECT_TYPE
-
# Unnesting two arrays from the same row, with AT on both, in a cross-product manner.
# Notice the ordinals are independent; each `at2` restarts at 1 for each element of the outer array.
Expand Down Expand Up @@ -196,11 +196,11 @@ test_block:
-
# Unnesting the same array twice, but with the same AS alias assigned both.
- query: SELECT T2."id", "val", "at1", "at2" FROM T2, T2."arr1" AS "val" AT "at1", T2."arr1" AS "val" AT "at2"
- error: "42702" # "Ambiguous reference val"
- error: AMBIGUOUS_COLUMN
-
# Unnesting the same array twice, but with the same AT alias on both.
- query: SELECT T2."id", "at", "val1", "val2" FROM T2, T2."arr1" AS "val1" AT "at", T2."arr1" AS "val2" AT "at"
- error: "42702" # "Ambiguous reference at"
- error: AMBIGUOUS_COLUMN
-
# An AT variable can be used within the subscript [] operator to access another array. This enables “parallel”
# unnesting of two arrays within the same row.
Expand Down Expand Up @@ -274,11 +274,11 @@ test_block:
-
# Applying AT to a common table expression is invalid (CTE is not an array).
- query: WITH "cte" AS (SELECT * FROM T1) SELECT "id" FROM "cte" AT "at"
- error: "42809"
- error: WRONG_OBJECT_TYPE
-
# ORDER BY on the AT ordinal cannot be planned without and index.
- query: SELECT "id", "val", "at" FROM T1, T1."arr1_nn" AS "val" AT "at" WHERE T1."id" = 2 ORDER BY "at" DESC
- error: "0AF00"
- error: UNSUPPORTED_QUERY
-
# STRING array with AT via VALUES. Verifies ordinals also work with non-integer element types.
- query: SELECT "val", "at"
Expand Down
4 changes: 2 additions & 2 deletions yaml-tests/src/test/resources/arrays-cardinality.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ test_block:
tests:
- # Incorrect argument type: Passing a non-array (here: INTEGER) raises error 22000.
- query: SELECT CARDINALITY("id") FROM "dummy"
- error: "22000"
- error: CANNOT_CONVERT_TYPE
- # Incorrect argument type (constant case)
- query: SELECT CARDINALITY(1) FROM "dummy"
- error: "22000"
- error: CANNOT_CONVERT_TYPE
- # NULL argument array (constant case): NULL gets mapped to NULL.
- query: SELECT CARDINALITY(CAST(NULL AS INTEGER ARRAY)) FROM "tab1" WHERE "id" = 1
- resultMetadata: [{_0: INTEGER}]
Expand Down
6 changes: 3 additions & 3 deletions yaml-tests/src/test/resources/arrays-operators.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ test_block:
-
# Comparison of an INTEGER ARRAY field to [], casted to an ARRAY type that is not compatible with INTEGER ARRAY.
- query: SELECT * FROM T1 WHERE "arr" = CAST([] AS STRING ARRAY)
- error: "42804"
- error: DATATYPE_MISMATCH
-
# Comparison of a nullable ARRAY field to [], casted to the correct type.
- query: SELECT "pk" FROM T1 WHERE "arr" = CAST([] AS INTEGER ARRAY)
Expand Down Expand Up @@ -268,8 +268,8 @@ test_block:
# Comparison of an INTEGER ARRAY to a constant BIGINT ARRAY. The INTEGER ARRAY could be promoted to a BIGINT ARRAY
# but this is not yet supported.
- query: SELECT "pk" FROM T1 WHERE "arr" = CAST([1] AS BIGINT ARRAY)
- error: "42804"
- error: DATATYPE_MISMATCH
- # Some more constant comparisons of different but promotable ARRAY types. This is not yet supported.
- query: SELECT 1I = 1L, [1I] = [1L] FROM "dummy"
- error: "42804"
- error: DATATYPE_MISMATCH
...
14 changes: 7 additions & 7 deletions yaml-tests/src/test/resources/arrays-unnesting.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ test_block:
-
# ORDER BY on the array is not possible without an index.
- query: SELECT "items" FROM T1 ORDER BY "items"
- error: "0AF00" # "Cascades planner could not plan query"
- error: UNSUPPORTED_QUERY
-
# Likewise on the `T1_indexed` table; the `T1_index` does not match.
- query: SELECT "items" FROM "T1_indexed" ORDER BY "items"
- error: "0AF00" # "Cascades planner could not plan query"
- error: UNSUPPORTED_QUERY
-
# Unnesting the array using PartiQL-style unnesting.
- query: SELECT "id", "item" FROM "T1_indexed" AS "row", "row"."items" AS "item"
Expand Down Expand Up @@ -141,11 +141,11 @@ test_block:
# Same query but with an added `ORDER BY "item"`.
# TODO Issue #3896: The `T1_index` is not leveraged here.
- query: SELECT SQ."item" FROM "T1_indexed" AS "row", (SELECT "item" FROM "row"."items" AS "item") AS SQ ORDER BY SQ."item"
- error: "0AF00" # "Cascades planner could not plan query"
- error: UNSUPPORTED_QUERY
-
# Same ORDER BY on the array, but on the view-indexed table.
- query: SELECT "items" FROM "T2" ORDER BY "items"
- error: "0AF00" # "Cascades planner could not plan query"
- error: UNSUPPORTED_QUERY
-
# Example query from the SQL reference (`Indexes.rst`, section "Indexes on nested fields").
- query: SELECT SQ."rating" FROM "restaurant" AS RR, (SELECT "rating" FROM RR."reviews") SQ
Expand All @@ -158,19 +158,19 @@ test_block:
# Unnesting an ARRAY of scalars (integers) directly.
# The `"integer".*` syntax is disallowed because "integer" is a scalar here, not a STRUCT.
- query: SELECT "id", "integer".* FROM T3, T3."integers" AS "integer"
- error: "42F10"
- error: INVALID_COLUMN_REFERENCE
-
# Same `.*` rejection as above, but here the array comes from a table function rather than a base-table column.
- query: SELECT "b".* FROM (SELECT "a" FROM VALUES ([1, 2, 3, 4]) AS T("a")) AS "sq", "sq"."a" AS "b"
- error: "42F10"
- error: INVALID_COLUMN_REFERENCE
-
# Wrapping the unnested scalar into a one-field struct lifts it back into a record type, so `.*` expansion is allowed.
- query: SELECT "b".* FROM (SELECT "a" FROM VALUES ([1, 2, 3, 4]) AS T("a")) AS "sq", (SELECT ("x") AS wrapped FROM "sq"."a" AS "x") AS "b"
- result: [{wrapped: {1}}, {wrapped: {2}}, {wrapped: {3}}, {wrapped: {4}}]
-
# Same .* rejection as above, but on an unnested VECTOR element. VECTOR has no fields to expand.
- query: SELECT "id", "v".* FROM T4, T4."vectors" AS "v"
- error: "42F10"
- error: INVALID_COLUMN_REFERENCE
-
# Unnest the ARRAY of integers via a subquery and wrap each integer into a tuple with a `( … )` expression.
# Note: As an alternative to the `AS "wrapped_int"` we might write `AS SQ ("wrapped_int")`, but this is not
Expand Down
2 changes: 1 addition & 1 deletion yaml-tests/src/test/resources/arrays.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_block:
# Attempting to insert a NULL value into a not-nullable ARRAY column.
- query: INSERT INTO A_NOT_NULL VALUES (0, NULL)
- supported_version: 4.11.1.0
- error: "XX000"
- error: INTERNAL_ERROR
-
# INSERT + basic SELECT for a not-nullable INTEGER ARRAY.
- query: INSERT INTO A_NOT_NULL VALUES (0, []), (1, [1]), (2, [1, 2])
Expand Down
Loading
Loading