Skip to content

Commit

Permalink
Avoid stripping the comment parameter for views and materialized views
Browse files Browse the repository at this point in the history
  • Loading branch information
findinpath committed Nov 21, 2023
1 parent 49072b6 commit 74ce6b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public void testCreateView()
TestView view = new TestView(getQueryRunner()::execute, viewName, "SELECT * FROM " + table.getName())) {
assertQuery(format("SELECT * FROM %s", view.getName()), "VALUES 'test'");
assertQuery(format("SELECT table_type FROM information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", view.getName(), SCHEMA), "VALUES 'VIEW'");
// Ensure all relations are being listed
assertQuery(format("SELECT table_type FROM information_schema.tables WHERE table_name LIKE '%%%s' AND table_schema='%s'", view.getName(), SCHEMA), "VALUES 'VIEW'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static io.trino.plugin.hive.HiveMetadata.TABLE_COMMENT;
import static io.trino.plugin.hive.ViewReaderUtil.isTrinoMaterializedView;
import static io.trino.plugin.hive.ViewReaderUtil.isTrinoView;
import static io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.metastoreFunctionName;
import static io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.toResourceUris;
import static io.trino.plugin.hive.metastore.thrift.ThriftMetastoreUtil.updateStatisticsParameters;
Expand All @@ -64,12 +66,16 @@ public static DatabaseInput convertDatabase(Database database)

public static TableInput convertTable(Table table)
{
TableInput input = new TableInput();
Map<String, String> tableParameters = table.getParameters();
Optional<String> comment = Optional.ofNullable(table.getParameters().get(TABLE_COMMENT));
Map<String, String> tableParameters = table.getParameters().entrySet().stream()
.filter(entry -> !entry.getKey().equals(TABLE_COMMENT))
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
if (!(isTrinoView(table) || isTrinoMaterializedView(table))) {
tableParameters = table.getParameters().entrySet().stream()
.filter(entry -> !entry.getKey().equals(TABLE_COMMENT))
.collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue));
comment.ifPresent(input::setDescription);
}

TableInput input = new TableInput();
input.setName(table.getTableName());
input.setOwner(table.getOwner().orElse(null));
input.setTableType(table.getTableType());
Expand All @@ -78,7 +84,6 @@ public static TableInput convertTable(Table table)
input.setParameters(tableParameters);
table.getViewOriginalText().ifPresent(input::setViewOriginalText);
table.getViewExpandedText().ifPresent(input::setViewExpandedText);
comment.ifPresent(input::setDescription);
return input;
}

Expand Down

0 comments on commit 74ce6b4

Please sign in to comment.