mchades commented on code in PR #11288:
URL: https://github.com/apache/gravitino/pull/11288#discussion_r3339140690
##########
spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/integration/test/hive/SparkHiveCatalogIT.java:
##########
@@ -517,4 +525,160 @@ void testCreateTableWithTimestamp() {
SparkColumnInfo.of("ts", DataTypes.TimestampType));
checkTableColumns(tableName, expectedSparkInfo, tableInfo);
}
+
+ @Test
+ void testCreateViewViaSql() {
+ String tableName = "cv_base_table";
+ String viewName = "cv_test_view";
+ String schemaName = getDefaultDatabase();
+ dropTableIfExists(tableName);
+ createSimpleTable(tableName);
+ try {
+ // Spark V2 named catalogs do not support CREATE VIEW via SQL; this
documents the limitation.
+ AnalysisException ex =
+ Assertions.assertThrows(
+ AnalysisException.class,
+ () ->
+ sql(
+ String.format(
+ "CREATE VIEW %s.%s.%s AS SELECT * FROM %s.%s.%s",
+ getCatalogName(),
+ schemaName,
+ viewName,
+ getCatalogName(),
+ schemaName,
+ tableName)));
+ Assertions.assertTrue(
+ ex.getMessage().contains("does not support views"),
+ "Expected error about view support, got: " + ex.getMessage());
+ } finally {
+ dropTableIfExists(tableName);
+ }
+ }
+
+ @Test
+ void testSelectHiveView() {
+ String tableName = "view_base_table";
+ String viewName = "test_hive_view";
+ String schemaName = getDefaultDatabase();
+
+ dropTableIfExists(tableName);
+ createSimpleTable(tableName);
+ sql(String.format("INSERT INTO %s VALUES (1, '1', 1),(2, '2', 2),(3, '3',
3)", tableName));
+
+ ViewCatalog viewCatalog =
+
client.loadMetalake("test").loadCatalog(getCatalogName()).asViewCatalog();
Review Comment:
These three tests all repeat the same boilerplate
`client.loadMetalake("test").loadCatalog(getCatalogName()).asViewCatalog()`
chain to create views via the Gravitino API. Since `SparkEnvIT.metalakeName` is
`private`, the metalake name had to be hardcoded as `"test"`.
Consider adding a helper method in `SparkEnvIT` (e.g. `protected Catalog
getGravitinoCatalog()`) that encapsulates this lookup, so subclasses do not
need to repeat the chain or hard-code the metalake name.
--
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]