Skip to content

Commit

Permalink
[Enhancement] Do not display type when table comment is empty (#24803)
Browse files Browse the repository at this point in the history
Fixes #issue

Signed-off-by: Astralidea <[email protected]>
(cherry picked from commit e770adb)

# Conflicts:
#	fe/fe-core/src/test/java/com/starrocks/analysis/ShowCreateMaterializedViewStmtTest.java
#	test/sql/test_default_enable_replicated_storage/R/test_enable_mv
#	test/sql/test_materialized_column/R/test_materialized_column
#	test/sql/test_random_distribution/R/test_random_distribution
  • Loading branch information
Astralidea authored and mergify[bot] committed Jun 7, 2023
1 parent 21999b8 commit 31bf4e2
Show file tree
Hide file tree
Showing 6 changed files with 1,009 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fe/fe-core/src/main/java/com/starrocks/catalog/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public String getComment() {
if (!Strings.isNullOrEmpty(comment)) {
return comment;
}
return type.name();
return "";
}

public void setComment(String comment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ public void testShowInternalCatalogConstraints() throws Exception {
Table table = currentState.getDb("test").getTable("mv9");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals("CREATE MATERIALIZED VIEW `mv9`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals("CREATE MATERIALIZED VIEW `mv9` (k1, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"DISTRIBUTED BY HASH(`k1`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
"PROPERTIES (\n" +
Expand All @@ -109,6 +113,7 @@ public void testShowExternalCatalogConstraints() throws Exception {
Table table = currentState.getDb("test").getTable("mv10");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals("CREATE MATERIALIZED VIEW `mv10`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
"DISTRIBUTED BY HASH(`c1`) BUCKETS 10 \n" +
Expand All @@ -121,6 +126,20 @@ public void testShowExternalCatalogConstraints() throws Exception {
")\n" +
"AS SELECT `hive0`.`partitioned_db2`.`t2`.`c1`, `hive0`.`partitioned_db`.`t1`.`c2`\n" +
"FROM `hive0`.`partitioned_db`.`t1` INNER JOIN `hive0`.`partitioned_db2`.`t2` ON `hive0`.`partitioned_db`.`t1`.`c2` = `hive0`.`partitioned_db2`.`t2`.`c2`;",
=======
Assert.assertEquals("CREATE MATERIALIZED VIEW `mv10` (c1, c2)\n" +
"DISTRIBUTED BY HASH(`c1`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\",\n" +
"\"replicated_storage\" = \"true\",\n" +
"\"unique_constraints\" = \"hive0.partitioned_db2.t2.c2\",\n" +
"\"foreign_key_constraints\" = \"hive0.partitioned_db.t1(c2) REFERENCES hive0.partitioned_db2.t2(c2)\",\n" +
"\"storage_medium\" = \"HDD\"\n" +
")\n" +
"AS SELECT `hive0`.`partitioned_db2`.`t2`.`c1`, `hive0`.`partitioned_db`.`t1`.`c2`\n" +
"FROM `hive0`.`partitioned_db`.`t1` INNER JOIN `hive0`.`partitioned_db2`.`t2` ON `hive0`.`partitioned_db`.`t1`.`c2` = `hive0`.`partitioned_db2`.`t2`.`c2`;",
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
createTableStmt.get(0));
}

Expand Down Expand Up @@ -151,8 +170,12 @@ public void testShowSimpleCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv1");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv1`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv1` (k1, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"DISTRIBUTED BY HASH(`k1`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
"PROPERTIES (\n" +
Expand All @@ -178,8 +201,12 @@ public void testShowPartitionWithAliasCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv2");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv2`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv2` (k3, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"PARTITION BY (`k3`)\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
Expand All @@ -206,8 +233,12 @@ public void testShowPartitionWithFunctionCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv3");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv3`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv3` (k1, k3)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"PARTITION BY (date_trunc('month', `k1`))\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
Expand Down Expand Up @@ -235,8 +266,12 @@ public void testShowPartitionWithFunctionAliasCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv4");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv4`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv4` (k3, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"PARTITION BY (date_trunc('month', `k3`))\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
Expand Down Expand Up @@ -268,8 +303,12 @@ public void testShowPartitionWithAllPropertiesCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv5");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv5`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv5` (k3, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"PARTITION BY (date_trunc('month', `k3`))\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH ASYNC START(\"2122-12-31 00:00:00\") EVERY(INTERVAL 1 HOUR)\n" +
Expand Down Expand Up @@ -302,8 +341,12 @@ public void testShowRefreshWithNoStartTimeCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv6");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv6`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv6` (k3, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"PARTITION BY (date_trunc('month', `k3`))\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH ASYNC\n" +
Expand Down Expand Up @@ -336,8 +379,12 @@ public void testShowRefreshWithIntervalCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv7");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv7`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv7` (k3, k2)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"PARTITION BY (date_trunc('month', `k3`))\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH ASYNC EVERY(INTERVAL 1 HOUR)\n" +
Expand Down Expand Up @@ -366,8 +413,12 @@ public void testShowExternalTableCreateMvSql() throws Exception {
Table table = currentState.getDb("test").getTable("mv8");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
<<<<<<< HEAD
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv8`\n" +
"COMMENT \"MATERIALIZED_VIEW\"\n" +
=======
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `mv8` (l_orderkey, l_partkey, l_shipdate)\n" +
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))
"DISTRIBUTED BY HASH(`l_orderkey`) BUCKETS 10 \n" +
"REFRESH MANUAL\n" +
"PROPERTIES (\n" +
Expand All @@ -379,6 +430,36 @@ public void testShowExternalTableCreateMvSql() throws Exception {
ctx.getGlobalStateMgr().setMetadataMgr(oldMetadataMgr);
}

<<<<<<< HEAD
=======
@Test
public void testShowCreateDeferredMv() throws Exception {
String createMvSql = "create materialized view deferred_mv4 " +
"partition by (date_trunc('month',k3))" +
"distributed by hash(k3) buckets 10 " +
"refresh deferred manual " +
"as select k1 as k3, k2 from tbl1;";
StatementBase statementBase = UtFrameUtils.parseStmtWithNewParser(createMvSql, ctx);
GlobalStateMgr currentState = GlobalStateMgr.getCurrentState();
currentState.createMaterializedView((CreateMaterializedViewStatement) statementBase);
Table table = currentState.getDb("test").getTable("deferred_mv4");
List<String> createTableStmt = Lists.newArrayList();
GlobalStateMgr.getDdlStmt(table, createTableStmt, null, null, false, true);
Assert.assertEquals(createTableStmt.get(0), "CREATE MATERIALIZED VIEW `deferred_mv4` (k3, k2)\n" +
"PARTITION BY (date_trunc('month', `k3`))\n" +
"DISTRIBUTED BY HASH(`k3`) BUCKETS 10 \n" +
"REFRESH DEFERRED MANUAL\n" +
"PROPERTIES (\n" +
"\"replication_num\" = \"1\",\n" +
"\"replicated_storage\" = \"true\",\n" +
"\"storage_medium\" = \"HDD\"\n" +
")\n" +
"AS SELECT `tbl1`.`k1` AS `k3`, `tbl1`.`k2`\nFROM `test`.`tbl1`;");
String copySql = createTableStmt.get(0).replaceAll("deferred_mv4", "deferred_mv4_copy");
currentState.createMaterializedView(
(CreateMaterializedViewStatement) UtFrameUtils.parseStmtWithNewParser(copySql, ctx));
}
>>>>>>> e770adb8b ([Enhancement] Do not display type when table comment is empty (#24803))

@Test(expected = SemanticException.class)
public void testNoTbl(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public void testShowTableStatus() throws Exception {
Assert.assertEquals("tbl1", resultRows.get(0).get(0));
Assert.assertEquals("StarRocks", resultRows.get(0).get(1));
Assert.assertEquals("utf8_general_ci", resultRows.get(0).get(14));
Assert.assertEquals("OLAP", resultRows.get(0).get(17));
}

@Test(expected = SemanticException.class)
Expand Down
53 changes: 53 additions & 0 deletions test/sql/test_default_enable_replicated_storage/R/test_enable_mv
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- name: test_default_enable_mv
create database test_default_enable_mv;
-- result:
-- !result
use test_default_enable_mv;
-- result:
-- !result
admin set frontend config('enable_replicated_storage_as_default_engine'='true');
-- result:
-- !result
create table t1(k int, v int not null) distributed by hash(k);
-- result:
-- !result
create materialized view tvd distributed by hash(k) buckets 10 REFRESH ASYNC as select k, sum(v) from t1 group by k;
-- result:
-- !result
show create materialized view tvd;
-- result:
tvd CREATE MATERIALIZED VIEW `tvd` (k, sum(v))
DISTRIBUTED BY HASH(`k`) BUCKETS 10
REFRESH ASYNC
PROPERTIES (
"replication_num" = "3",
"replicated_storage" = "true",
"storage_medium" = "HDD"
)
AS SELECT `t1`.`k`, sum(`t1`.`v`) AS `sum(v)`
FROM `test_default_enable_mv`.`t1`
GROUP BY `t1`.`k`;
-- !result
admin set frontend config('enable_replicated_storage_as_default_engine'='false');
-- result:
-- !result
create materialized view tvb distributed by hash(k) buckets 10 REFRESH ASYNC as select k, sum(v) from t1 group by k;
-- result:
-- !result
show create materialized view tvb;
-- result:
tvb CREATE MATERIALIZED VIEW `tvb` (k, sum(v))
DISTRIBUTED BY HASH(`k`) BUCKETS 10
REFRESH ASYNC
PROPERTIES (
"replication_num" = "3",
"replicated_storage" = "false",
"storage_medium" = "HDD"
)
AS SELECT `t1`.`k`, sum(`t1`.`v`) AS `sum(v)`
FROM `test_default_enable_mv`.`t1`
GROUP BY `t1`.`k`;
-- !result
admin set frontend config('enable_replicated_storage_as_default_engine'='true');
-- result:
-- !result
Loading

0 comments on commit 31bf4e2

Please sign in to comment.