ebyhr commented on code in PR #11729:
URL: https://github.com/apache/iceberg/pull/11729#discussion_r1879148802
##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -562,6 +562,67 @@ public void readFromViewWithCTE() throws
NoSuchTableException {
assertThat(sql("SELECT * FROM %s",
viewName)).hasSize(1).containsExactly(row(10, 1L));
}
+ @TestTemplate
+ public void readFromViewWithGroupByOrdinal() throws NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("viewWithGroupByOrdinal");
+ String sql = String.format("SELECT id FROM %s group by 1", tableName);
+
+ ViewCatalog viewCatalog = viewCatalog();
+
+ viewCatalog
+ .buildView(TableIdentifier.of(NAMESPACE, viewName))
+ .withQuery("spark", sql)
+ .withDefaultNamespace(NAMESPACE)
+ .withDefaultCatalog(catalogName)
+ .withSchema(schema(sql))
+ .create();
+
+ List<Object[]> expected =
+ IntStream.rangeClosed(1,
10).mapToObj(this::row).collect(Collectors.toList());
+
+ assertThat(sql("SELECT * FROM %s", viewName))
+ .hasSize(10)
+ .containsExactlyInAnyOrderElementsOf(expected);
+ }
+
+ @TestTemplate
+ public void readFromViewWithOrderByOrdinal() throws NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("viewWithOrderByOrdinal");
+ String sql = String.format("SELECT id FROM %s order by 1", tableName);
Review Comment:
nit: Uppercase `order by`.
##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -562,6 +562,67 @@ public void readFromViewWithCTE() throws
NoSuchTableException {
assertThat(sql("SELECT * FROM %s",
viewName)).hasSize(1).containsExactly(row(10, 1L));
}
+ @TestTemplate
+ public void readFromViewWithGroupByOrdinal() throws NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("viewWithGroupByOrdinal");
+ String sql = String.format("SELECT id FROM %s group by 1", tableName);
Review Comment:
nit: Uppercase `group by`.
##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -562,6 +562,67 @@ public void readFromViewWithCTE() throws
NoSuchTableException {
assertThat(sql("SELECT * FROM %s",
viewName)).hasSize(1).containsExactly(row(10, 1L));
}
+ @TestTemplate
+ public void readFromViewWithGroupByOrdinal() throws NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("viewWithGroupByOrdinal");
+ String sql = String.format("SELECT id FROM %s group by 1", tableName);
+
+ ViewCatalog viewCatalog = viewCatalog();
+
+ viewCatalog
+ .buildView(TableIdentifier.of(NAMESPACE, viewName))
+ .withQuery("spark", sql)
+ .withDefaultNamespace(NAMESPACE)
+ .withDefaultCatalog(catalogName)
+ .withSchema(schema(sql))
+ .create();
+
+ List<Object[]> expected =
+ IntStream.rangeClosed(1,
10).mapToObj(this::row).collect(Collectors.toList());
+
+ assertThat(sql("SELECT * FROM %s", viewName))
+ .hasSize(10)
+ .containsExactlyInAnyOrderElementsOf(expected);
+ }
+
+ @TestTemplate
+ public void readFromViewWithOrderByOrdinal() throws NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("viewWithOrderByOrdinal");
+ String sql = String.format("SELECT id FROM %s order by 1", tableName);
+
+ ViewCatalog viewCatalog = viewCatalog();
+
+ viewCatalog
+ .buildView(TableIdentifier.of(NAMESPACE, viewName))
+ .withQuery("spark", sql)
+ .withDefaultNamespace(NAMESPACE)
+ .withDefaultCatalog(catalogName)
+ .withSchema(schema(sql))
+ .create();
+
+ List<Object[]> expected =
+ IntStream.rangeClosed(1,
10).mapToObj(this::row).collect(Collectors.toList());
+
+ assertThat(sql("SELECT * FROM %s", viewName))
+ .hasSize(10)
+ .containsExactlyInAnyOrderElementsOf(expected);
+ }
+
+ @TestTemplate
+ public void createViewWithGroupByOrdinal() throws NoSuchTableException {
+ insertRows(10);
+ String viewName = viewName("createViewWithGroupByOrdinal");
+ sql("CREATE VIEW %s AS SELECT id FROM %s GROUP BY 1", viewName, tableName);
+ List<Object[]> expected =
+ IntStream.rangeClosed(1,
10).mapToObj(this::row).collect(Collectors.toList());
+
+ assertThat(sql("SELECT * FROM %s", viewName))
+ .hasSize(10)
+ .containsExactlyInAnyOrderElementsOf(expected);
Review Comment:
This test doesn't ensure whether `GROUP BY` is effective or not because it
specifies id column. Ideally, it should specify non-id column and verify the
duplicate value is eliminated.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]