vldpyatkov commented on code in PR #5393:
URL: https://github.com/apache/calcite/pull/5393#discussion_r4491492042
##########
core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java:
##########
@@ -65,6 +73,87 @@ class CollectionTypeTest {
"SELECT ARRAY[ROW(MOD(\"ID\", 2), CAST(NULL AS INTEGER))] AS a,\n"
+ "\"ARRAYFIELD\"[1] AS n FROM \"T\"";
+ /** Regression tests for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7919">[CALCITE-7919]
+ * Comparison of ARRAY and ROW keys in enumerable operators</a>. */
+ @ParameterizedTest
+ @MethodSource("compositeSortCases")
+ void testSortCompositeKeys(String key, String order, boolean limit,
Review Comment:
Added *.iq tests also.
##########
core/src/test/java/org/apache/calcite/test/CollectionTypeTest.java:
##########
@@ -65,6 +73,87 @@ class CollectionTypeTest {
"SELECT ARRAY[ROW(MOD(\"ID\", 2), CAST(NULL AS INTEGER))] AS a,\n"
+ "\"ARRAYFIELD\"[1] AS n FROM \"T\"";
+ /** Regression tests for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7919">[CALCITE-7919]
+ * Comparison of ARRAY and ROW keys in enumerable operators</a>. */
+ @ParameterizedTest
+ @MethodSource("compositeSortCases")
+ void testSortCompositeKeys(String key, String order, boolean limit,
+ String[] expected) {
+ withNestedTable()
+ .query("SELECT id FROM " + compositeKeyQuery(key)
+ + " AS t ORDER BY k " + order + ", id DESC"
+ + (limit ? " OFFSET 1 ROWS FETCH NEXT 3 ROWS ONLY" : ""))
+ .withHook(Hook.PLANNER, (Consumer<RelOptPlanner>) planner -> {
+ if (limit) {
+ planner.removeRule(EnumerableRules.ENUMERABLE_SORT_RULE);
+ planner.addRule(EnumerableRules.ENUMERABLE_LIMIT_SORT_RULE);
+ }
+ })
+ .explainContains(limit ? "EnumerableLimitSort" : "EnumerableSort")
+ .returnsOrdered(limit ? Arrays.copyOfRange(expected, 1, 4) : expected);
+ }
+
+ private static List<Arguments> compositeSortCases() {
+ final List<Arguments> cases = new ArrayList<>();
+ for (String key : compositeKeys()) {
+ for (boolean limit : new boolean[]{false, true}) {
+ cases.add(
+ Arguments.of(key, "ASC NULLS FIRST", limit,
+ new String[]{"ID=4", "ID=2", "ID=0", "ID=1", "ID=3"}));
+ cases.add(
+ Arguments.of(key, "ASC NULLS LAST", limit,
+ new String[]{"ID=2", "ID=0", "ID=1", "ID=3", "ID=4"}));
+ cases.add(
+ Arguments.of(key, "DESC NULLS FIRST", limit,
+ new String[]{"ID=4", "ID=3", "ID=1", "ID=2", "ID=0"}));
+ cases.add(
+ Arguments.of(key, "DESC NULLS LAST", limit,
+ new String[]{"ID=3", "ID=1", "ID=2", "ID=0", "ID=4"}));
+ }
+ }
+ return cases;
+ }
+
+ private static List<String> compositeKeys() {
+ return Arrays.asList("ARRAY[a, b]", "ROW(a, b)", "ARRAY[ROW(a, b)]");
Review Comment:
Ok, added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]