rdblue commented on code in PR #9513:
URL: https://github.com/apache/iceberg/pull/9513#discussion_r1471676989
##########
spark/v3.5/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestViews.java:
##########
@@ -1149,6 +1149,159 @@ public void
createViewWithSubqueryExpressionUsingGlobalTempView() {
"because it references to the temporary object
global_temp.%s", globalTempView));
}
+ @Test
+ public void describeView() {
+ String viewName = "describeView";
+
+ sql("CREATE VIEW %s AS SELECT id, data FROM %s WHERE id <= 3", viewName,
tableName);
+ assertThat(sql("DESCRIBE %s", viewName))
+ .containsExactlyInAnyOrder(row("id", "int", ""), row("data", "string",
""));
+ }
+
+ @Test
+ public void describeExtendedView() {
+ String viewName = "describeExtendedView";
+ String sql = String.format("SELECT id, data FROM %s WHERE id <= 3",
tableName);
+
+ sql(
+ "CREATE VIEW %s (new_id COMMENT 'ID', new_data COMMENT 'DATA') COMMENT
'view comment' AS %s",
+ viewName, sql);
+ assertThat(sql("DESCRIBE EXTENDED %s", viewName))
+ .contains(
+ row("new_id", "int", "ID"),
+ row("new_data", "string", "DATA"),
+ row("Comment", "view comment", ""),
+ row("View Text", sql, ""),
+ row("View Catalog and Namespace", String.format("%s.%s",
catalogName, NAMESPACE), ""),
+ row("View Query Output Columns", "[id, data]", ""),
+ row(
+ "View Properties",
+ String.format(
+ "['format-version' = '1', 'location' = '/%s/%s',
'provider' = 'iceberg']",
+ NAMESPACE, viewName),
+ ""));
+ }
+
+ @Test
+ public void showViewProperties() {
+ String viewName = "showViewProps";
+
+ sql(
+ "CREATE VIEW %s TBLPROPERTIES ('key1'='val1', 'key2'='val2') AS SELECT
id, data FROM %s WHERE id <= 3",
+ viewName, tableName);
+ assertThat(sql("SHOW TBLPROPERTIES %s", viewName))
+ .contains(row("key1", "val1"), row("key2", "val2"));
+ }
+
+ @Test
+ public void showViewPropertiesByKey() {
+ String viewName = "showViewPropsByKey";
+
+ sql("CREATE VIEW %s AS SELECT id, data FROM %s WHERE id <= 3", viewName,
tableName);
+ assertThat(sql("SHOW TBLPROPERTIES %s",
viewName)).contains(row("provider", "iceberg"));
+
+ assertThat(sql("SHOW TBLPROPERTIES %s (provider)", viewName))
+ .contains(row("provider", "iceberg"));
+
+ assertThat(sql("SHOW TBLPROPERTIES %s (non.existing)", viewName))
+ .contains(
+ row(
+ "non.existing",
+ String.format(
+ "View %s.%s.%s does not have property: non.existing",
+ catalogName, NAMESPACE, viewName)));
+ }
+
+ @Test
+ public void showViews() throws NoSuchTableException {
+ insertRows(6);
+ String sql = String.format("SELECT * from %s", tableName);
+ sql("CREATE VIEW v1 AS %s", sql);
+ sql("CREATE VIEW prefixV2 AS %s", sql);
+ sql("CREATE VIEW prefixV3 AS %s", sql);
+ sql("CREATE GLOBAL TEMPORARY VIEW globalViewForListing AS %s", sql);
+ sql("CREATE TEMPORARY VIEW tempViewForListing AS %s", sql);
+
+ // spark stores temp views case-insensitive by default
+ Object[] tempView = row("", "tempviewforlisting", true);
+ assertThat(sql("SHOW VIEWS"))
+ .contains(
+ row(NAMESPACE.toString(), "prefixV2", false),
+ row(NAMESPACE.toString(), "prefixV3", false),
+ row(NAMESPACE.toString(), "v1", false),
+ tempView);
+
+ assertThat(sql("SHOW VIEWS IN %s", catalogName))
+ .contains(
+ row(NAMESPACE.toString(), "prefixV2", false),
+ row(NAMESPACE.toString(), "prefixV3", false),
+ row(NAMESPACE.toString(), "v1", false),
+ tempView);
Review Comment:
Also weird when filtering by NAMESPACE below.
--
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]