Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.trino.spi.type.TypeId;

import java.util.Optional;
import java.util.stream.Stream;

import static com.google.common.collect.ImmutableList.toImmutableList;
import static io.trino.plugin.hive.HiveErrorCode.HIVE_INVALID_METADATA;
Expand All @@ -45,7 +46,7 @@ public ConnectorViewDefinition decodeViewData(String viewData, Table table, Cata
translateHiveViewToTrino(viewText),
Optional.of(catalogName.toString()),
Optional.ofNullable(table.getDatabaseName()),
table.getDataColumns().stream()
Stream.concat(table.getDataColumns().stream(), table.getPartitionColumns().stream())
.map(column -> new ConnectorViewDefinition.ViewColumn(column.getName(), TypeId.of(column.getType().getTypeSignature().toString())))
.collect(toImmutableList()),
Optional.ofNullable(table.getParameters().get(TABLE_COMMENT)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,21 @@ public void testUnionDistinctViews()
}
}

@Test(groups = HIVE_VIEWS)
public void testHivePartitionViews()
{
onHive().executeQuery("DROP VIEW IF EXISTS test_view_partitioned_column");
onHive().executeQuery("DROP TABLE IF EXISTS test_table_partitioned_column");
onTrino().executeQuery("CREATE TABLE test_table_partitioned_column(some_id VARCHAR(25), ds VARCHAR(25)) WITH (partitioned_by=array['ds'])");
onTrino().executeQuery("INSERT INTO test_table_partitioned_column VALUES ('1', '2022-09-17')");
onHive().executeQuery("CREATE VIEW test_view_partitioned_column PARTITIONED ON (ds) AS SELECT some_id, ds FROM test_table_partitioned_column");

String testQuery = "SELECT some_id, ds FROM test_view_partitioned_column";
assertThat(onTrino().executeQuery(testQuery)).containsOnly(row("1", "2022-09-17"));
onHive().executeQuery("DROP VIEW test_view_partitioned_column");
onHive().executeQuery("DROP TABLE test_table_partitioned_column");
}

/**
* Test a Hive view that spans over Hive and Iceberg table when metastore does not contain an up to date information about table schema, requiring
* any potential view translation to follow redirections.
Expand Down