Copilot commented on code in PR #11349:
URL: https://github.com/apache/gravitino/pull/11349#discussion_r3339370739
##########
flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/integration/test/FlinkCommonIT.java:
##########
@@ -812,4 +825,281 @@ && defaultValueWithNullLiterals()) {
Assertions.assertEquals(expected[i].nullable(), actual[i].nullable());
}
}
+
+ @Test
+ @EnabledIf("supportViewOperation")
+ public void testCreateView() {
+ String schemaName = "test_create_view_db";
+ String viewName = "test_view_create";
+ String tableName = "test_view_base_table";
+ doWithSchema(
+ currentCatalog(),
+ schemaName,
+ catalog -> {
+ TestUtils.assertTableResult(
+ sql("CREATE TABLE %s (id INT, name STRING)%s", tableName,
baseTableConnectorClause()),
+ ResultKind.SUCCESS);
+ TestUtils.assertTableResult(
+ sql(
+ "CREATE VIEW %s COMMENT 'view comment' AS SELECT id, name
FROM %s",
+ viewName, tableName),
+ ResultKind.SUCCESS);
+
+ org.apache.gravitino.rel.ViewCatalog viewCatalog =
catalog.asViewCatalog();
+ org.apache.gravitino.rel.View view =
+ viewCatalog.loadView(NameIdentifier.of(schemaName, viewName));
+ Assertions.assertEquals(viewName, view.name());
+ Assertions.assertEquals("view comment", view.comment());
+ Assertions.assertEquals(1, view.representations().length);
+ Assertions.assertInstanceOf(
+ org.apache.gravitino.rel.SQLRepresentation.class,
view.representations()[0]);
+
+ Optional<org.apache.flink.table.catalog.Catalog> flinkCatalog =
+ tableEnv.getCatalog(catalog.name());
+ Assertions.assertTrue(flinkCatalog.isPresent());
+ try {
+ CatalogBaseTable flinkTable =
+ flinkCatalog.get().getTable(new ObjectPath(schemaName,
viewName));
+ Assertions.assertEquals(CatalogBaseTable.TableKind.VIEW,
flinkTable.getTableKind());
+ } catch
(org.apache.flink.table.catalog.exceptions.TableNotExistException e) {
+ Assertions.fail("view should exist in Flink catalog: " +
e.getMessage());
+ }
+ },
+ true);
+ }
+
+ @Test
+ @EnabledIf("supportViewOperation")
+ public void testListViews() {
+ String schemaName = "test_list_views_db";
+ String tableName = "test_list_view_base";
+ String view1 = "test_list_view_1";
+ String view2 = "test_list_view_2";
+ doWithSchema(
+ currentCatalog(),
+ schemaName,
+ catalog -> {
+ TestUtils.assertTableResult(
+ sql("CREATE TABLE %s (id INT)%s", tableName,
baseTableConnectorClause()),
+ ResultKind.SUCCESS);
+ TestUtils.assertTableResult(
+ sql("CREATE VIEW %s AS SELECT id FROM %s", view1, tableName),
ResultKind.SUCCESS);
+ TestUtils.assertTableResult(
+ sql("CREATE VIEW %s AS SELECT id FROM %s", view2, tableName),
ResultKind.SUCCESS);
+
+ List<String> views = Arrays.asList(tableEnv.listViews());
+ Assertions.assertTrue(views.contains(view1), "view1 not found in
SHOW VIEWS");
+ Assertions.assertTrue(views.contains(view2), "view2 not found in
SHOW VIEWS");
+ Assertions.assertFalse(views.contains(tableName), "table should not
appear in listViews");
+
+ org.apache.gravitino.rel.ViewCatalog viewCatalog =
catalog.asViewCatalog();
+ NameIdentifier[] gravitinoViews =
+
viewCatalog.listViews(org.apache.gravitino.Namespace.of(schemaName));
+ List<String> gravitinoViewNames =
+
Arrays.stream(gravitinoViews).map(NameIdentifier::name).collect(Collectors.toList());
+ Assertions.assertTrue(gravitinoViewNames.contains(view1));
+ Assertions.assertTrue(gravitinoViewNames.contains(view2));
+ },
+ true);
+ }
+
+ @Test
+ @EnabledIf("supportViewOperation")
+ public void testDropView() {
+ String schemaName = "test_drop_view_db";
+ String tableName = "test_drop_view_base";
+ String viewName = "test_view_drop";
+ doWithSchema(
+ currentCatalog(),
+ schemaName,
+ catalog -> {
+ TestUtils.assertTableResult(
+ sql("CREATE TABLE %s (id INT)%s", tableName,
baseTableConnectorClause()),
+ ResultKind.SUCCESS);
+ TestUtils.assertTableResult(
+ sql("CREATE VIEW %s AS SELECT id FROM %s", viewName, tableName),
ResultKind.SUCCESS);
+
+ org.apache.gravitino.rel.ViewCatalog viewCatalog =
catalog.asViewCatalog();
+ Assertions.assertTrue(
+ viewCatalog.viewExists(NameIdentifier.of(schemaName, viewName)),
+ "view should exist before drop");
+
+ TestUtils.assertTableResult(sql("DROP VIEW %s", viewName),
ResultKind.SUCCESS);
+
+ Assertions.assertFalse(
+ viewCatalog.viewExists(NameIdentifier.of(schemaName, viewName)),
+ "view should not exist after drop");
+ },
+ true);
+ }
+
+ @Test
+ @EnabledIf("supportViewOperation")
+ public void testAlterViewRename() {
+ String schemaName = "test_rename_view_db";
+ String tableName = "test_rename_view_base";
+ String viewName = "test_view_rename_src";
+ String newViewName = "test_view_rename_dst";
+ doWithSchema(
+ currentCatalog(),
+ schemaName,
+ catalog -> {
+ TestUtils.assertTableResult(
+ sql("CREATE TABLE %s (id INT)%s", tableName,
baseTableConnectorClause()),
+ ResultKind.SUCCESS);
+ TestUtils.assertTableResult(
+ sql("CREATE VIEW %s AS SELECT id FROM %s", viewName, tableName),
ResultKind.SUCCESS);
+
+ TestUtils.assertTableResult(
+ sql("ALTER VIEW %s RENAME TO %s", viewName, newViewName),
ResultKind.SUCCESS);
+
+ org.apache.gravitino.rel.ViewCatalog viewCatalog =
catalog.asViewCatalog();
+ Assertions.assertFalse(
+ viewCatalog.viewExists(NameIdentifier.of(schemaName, viewName)),
+ "old view name should not exist");
+ Assertions.assertTrue(
+ viewCatalog.viewExists(NameIdentifier.of(schemaName,
newViewName)),
+ "new view name should exist");
+ },
+ true);
+ }
+
+ @Test
+ @EnabledIf("supportViewOperation")
+ public void testAlterViewReplaceBody() {
+ String schemaName = "test_replace_view_db";
+ String tableName = "test_replace_view_base";
+ String viewName = "test_view_replace";
+ doWithSchema(
+ currentCatalog(),
+ schemaName,
+ catalog -> {
+ TestUtils.assertTableResult(
+ sql("CREATE TABLE %s (id INT, name STRING)%s", tableName,
baseTableConnectorClause()),
+ ResultKind.SUCCESS);
+ TestUtils.assertTableResult(
+ sql("CREATE VIEW %s AS SELECT id FROM %s", viewName, tableName),
ResultKind.SUCCESS);
+
+ TestUtils.assertTableResult(
+ sql("ALTER VIEW %s AS SELECT id, name FROM %s", viewName,
tableName),
+ ResultKind.SUCCESS);
+
+ org.apache.gravitino.rel.ViewCatalog viewCatalog =
catalog.asViewCatalog();
+ org.apache.gravitino.rel.View view =
+ viewCatalog.loadView(NameIdentifier.of(schemaName, viewName));
+ Assertions.assertEquals(1, view.representations().length);
+ org.apache.gravitino.rel.SQLRepresentation rep =
+ (org.apache.gravitino.rel.SQLRepresentation)
view.representations()[0];
Review Comment:
These new view tests use fully qualified class names
(`org.apache.gravitino.rel.ViewCatalog`, `org.apache.gravitino.rel.View`,
`org.apache.gravitino.rel.SQLRepresentation`, `org.apache.gravitino.Namespace`,
and `org.apache.flink.table.catalog.exceptions.TableNotExistException`) instead
of regular imports. This violates the repo's import convention (AGENTS.md):
prefer normal Java imports and avoid FQN unless a real name conflict requires
it. None of these types collide with existing imports — note
`TableNotExistException` is already imported at the top of the file, so the FQN
in the catch is unnecessary. Only `org.apache.flink.table.catalog.Catalog`
truly needs an FQN (or alias) because `org.apache.gravitino.Catalog` is already
imported. Please add proper imports for the gravitino `rel.*` and `Namespace`
types, drop the FQN at the call sites, and use the already-imported
`TableNotExistException`.
--
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]