Skip to content
Draft
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 @@ -376,12 +376,12 @@ public void apply(@Nonnull final List<String> lines) {
*/
static String buildInlineDescriptor(@Nonnull final CheckResultMetadataConfig.ColumnDescriptor col) {
if (col.isArray && col.fields != null) {
final String typePrefix = col.structTypeName != null ? col.structTypeName + ", " : "";
final String typePrefix = isUserVisibleTypeName(col.structTypeName) ? col.structTypeName + ", " : "";
final String fields = col.fields.stream().map(YamlExecutionContext::buildInlineDescriptor)
.collect(Collectors.joining(", "));
return "{" + col.name + ": {array: [" + typePrefix + fields + "]}}";
} else if (col.fields != null) {
final String typePrefix = col.structTypeName != null ? col.structTypeName + ", " : "";
final String typePrefix = isUserVisibleTypeName(col.structTypeName) ? col.structTypeName + ", " : "";
final String fields = col.fields.stream().map(YamlExecutionContext::buildInlineDescriptor)
.collect(Collectors.joining(", "));
return "{" + col.name + ": [" + typePrefix + fields + "]}";
Expand All @@ -390,6 +390,10 @@ static String buildInlineDescriptor(@Nonnull final CheckResultMetadataConfig.Col
}
}

private static boolean isUserVisibleTypeName(@Nullable final String typeName) {
return typeName != null && !typeName.startsWith("__type__");
}

/**
* Converts an SQL array type name (e.g., {@code "ARRAY(INTEGER)"}) to its {@code {array: ...}} inline YAML
* representation. Non-array type names are returned unchanged.
Expand Down Expand Up @@ -527,8 +531,12 @@ public void apply(@Nonnull final List<String> lines) {
final String itemPrefix = " ".repeat(indentOf(lines.get(queryLineIdx)));
// Scan forward past any query-string continuation lines to find the first config entry
// at the same indentation level, and insert the explain line before it.
final int insertIdx = findInsertionPoint(lines, queryLineIdx + 1, itemPrefix,
// supported_version must remain the first config after query, so skip past it if present.
final int firstConfigIdx = findInsertionPoint(lines, queryLineIdx + 1, itemPrefix,
line -> line.startsWith(itemPrefix + "- "));
final int insertIdx = (firstConfigIdx < lines.size() && lines.get(firstConfigIdx).startsWith(itemPrefix + "- supported_version:"))
? findInsertionPoint(lines, firstConfigIdx + 1, itemPrefix, line -> line.startsWith(itemPrefix + "- "))
: firstConfigIdx;
lines.add(insertIdx, itemPrefix + "- explain: \"" + actual + "\"");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ private static List<?> checkStructTypeName(@Nonnull final List<?> valueList,
@Nonnull final ColumnDescriptor actualCol) {
if (!valueList.isEmpty() && valueList.get(0) instanceof String) {
final String expectedTypeName = (String)valueList.get(0);
// Internal anonymous type names are not user-visible and must not be checked.
if (expectedTypeName.startsWith("__type__")) {
return valueList.subList(1, valueList.size());
}
if (actualCol.structTypeName == null || !expectedTypeName.equalsIgnoreCase(actualCol.structTypeName)) {
return null;
}
Expand Down
40 changes: 20 additions & 20 deletions yaml-tests/src/test/java/YamlIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public void compositeAggregates(YamlTest.Runner runner) throws Exception {
runner.runYamsql("composite-aggregates.yamsql");
}

@TestTemplate
public void copyBasic(YamlTest.Runner runner) throws Exception {
runner.runYamsql("copy-basic.yamsql");
}

@TestTemplate
void createDrop(YamlTest.Runner runner) throws Exception {
runner.runYamsql("create-drop.yamsql");
Expand Down Expand Up @@ -202,6 +207,21 @@ public void inPredicate(YamlTest.Runner runner) throws Exception {
runner.runYamsql("in-predicate.yamsql");
}

@TestTemplate
public void indexDdl(YamlTest.Runner runner) throws Exception {
runner.runYamsql("index-ddl.yamsql");
}

@TestTemplate
public void indexDdlValuesOnly(YamlTest.Runner runner) throws Exception {
runner.runYamsql("index-ddl-values-only.yamsql");
}

@TestTemplate
public void indexDdlAggregatesOnly(YamlTest.Runner runner) throws Exception {
runner.runYamsql("index-ddl-aggregates-only.yamsql");
}

@TestTemplate
public void indexedFunctions(YamlTest.Runner runner) throws Exception {
runner.runYamsql("indexed-functions.yamsql");
Expand Down Expand Up @@ -262,26 +282,6 @@ public void multiClusterIsolation(YamlTest.Runner runner) throws Exception {
runner.runYamsql("multi-cluster-isolation.yamsql");
}

@TestTemplate
public void copyBasic(YamlTest.Runner runner) throws Exception {
runner.runYamsql("copy-basic.yamsql");
}

@TestTemplate
public void indexDdl(YamlTest.Runner runner) throws Exception {
runner.runYamsql("index-ddl.yamsql");
}

@TestTemplate
public void indexDdlValuesOnly(YamlTest.Runner runner) throws Exception {
runner.runYamsql("index-ddl-values-only.yamsql");
}

@TestTemplate
public void indexDdlAggregatesOnly(YamlTest.Runner runner) throws Exception {
runner.runYamsql("index-ddl-aggregates-only.yamsql");
}

@TestTemplate
public void nested(YamlTest.Runner runner) throws Exception {
runner.runYamsql("nested-tests.yamsql");
Expand Down
10 changes: 10 additions & 0 deletions yaml-tests/src/test/resources/aggregate-empty-table.yamsql
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ test_block:
- query: select sum(col1) from t3 having sum(col1) is null
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I1 <,>) | MAP (_ AS _0) | AGG (sum_l(_._0.COL1) AS _0) GROUP BY () | ON EMPTY NULL | FILTER _._0._0 IS_NULL | MAP (_._0._0 AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: [{!null _}]
-
# Note: The initial ON EMPTY NULL before the FILTER correctly gets eliminated here, since the NULL record it
Expand All @@ -664,47 +665,56 @@ test_block:
- query: select count(col1) from t3 having count(col1) is null
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I1 <,>) | MAP (_ AS _0) | AGG (count(_._0.COL1) AS _0) GROUP BY () | FILTER coalesce_long(_._0._0, promote(0l AS LONG)) IS_NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select count(*) from t3 having count(*) is null
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I2 <,>) | MAP (_ AS _0) | AGG (count_star(*) AS _0) GROUP BY () | FILTER coalesce_long(_._0._0, 0l) IS_NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select max(col1) from t3 group by col2 having col2 is null
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I2 <,>) | MAP (_ AS _0) | AGG (max_l(_._0.COL1) AS _0) GROUP BY (_._0.COL2 AS _0) | FILTER _._0._0 IS_NULL | MAP (_._1._0 AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select count(col1) from t3 group by col2 having col2 is null
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I2 <,>) | MAP (_ AS _0) | AGG (count(_._0.COL1) AS _0) GROUP BY (_._0.COL2 AS _0) | FILTER _._0._0 IS_NULL | MAP (_._1._0 AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select count(col1) from t3 group by col2 having col2 is null or col2 = 42
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I2 <,>) | MAP (_ AS _0) | AGG (count(_._0.COL1) AS _0) GROUP BY (_._0.COL2 AS _0) | FILTER _._0._0 IS_NULL OR _._0._0 EQUALS promote(@c17 AS LONG) | MAP (_._1._0 AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select count(col1) from t3 having count(col1) is null or count(col1) > 100
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I1 <,>) | MAP (_ AS _0) | AGG (count(_._0.COL1) AS _0) GROUP BY () | ON EMPTY NULL | FILTER coalesce_long(_._0._0, promote(0l AS LONG)) IS_NULL OR coalesce_long(_._0._0, promote(0l AS LONG)) GREATER_THAN promote(@c20 AS LONG) | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select count(*) from t3 having count(*) is null or count(*) > 100
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I2 <,>) | MAP (_ AS _0) | AGG (count_star(*) AS _0) GROUP BY () | ON EMPTY NULL | FILTER coalesce_long(_._0._0, 0l) IS_NULL OR coalesce_long(_._0._0, 0l) GREATER_THAN promote(@c20 AS LONG) | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: []
-
- query: select sum(col1) from t3 having sum(col1) is null or sum(col1) > 100
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I1 <,>) | MAP (_ AS _0) | AGG (sum_l(_._0.COL1) AS _0) GROUP BY () | ON EMPTY NULL | FILTER _._0._0 IS_NULL OR _._0._0 GREATER_THAN promote(@c20 AS LONG) | MAP (_._0._0 AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: [{!null _}]
-
# Note: The ON EMPTY NULL cannot be eliminated here, as NULL gets mapped to a count of 0, and the predicate accepts 0.
- query: select count(col1) from t3 having count(col1) = 0
- supported_version: 4.12.3.0
- explain: "ISCAN(T3_I1 <,>) | MAP (_ AS _0) | AGG (count(_._0.COL1) AS _0) GROUP BY () | ON EMPTY NULL | FILTER coalesce_long(_._0._0, promote(0l AS LONG)) EQUALS promote(@c13 AS LONG) | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
- resultMetadata: [{_0: BIGINT}]
- result: [{0}]
-
# Same query as right above, but with the SUM() aggregate instead of COUNT(). Unlike COUNT(), SUM() may yield
Expand Down
Loading
Loading