use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class BaseHiveConnectorTest method testPartitionHiddenColumn.
@Test
public void testPartitionHiddenColumn() {
@Language("SQL") String createTable = "CREATE TABLE test_partition_hidden_column " + "WITH (" + "partitioned_by = ARRAY['col1', 'col2']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 11, 21), (1, 12, 22), (2, 13, 23), " + "(3, 14, 24), (4, 15, 25), (5, 16, 26), " + "(6, 17, 27), (7, 18, 28), (8, 19, 29)" + " ) t (col0, col1, col2) ";
assertUpdate(createTable, 9);
assertTrue(getQueryRunner().tableExists(getSession(), "test_partition_hidden_column"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_partition_hidden_column");
assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("col1", "col2"));
List<String> columnNames = ImmutableList.of("col0", "col1", "col2", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME, PARTITION_COLUMN_NAME);
List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
assertEquals(columnMetadatas.size(), columnNames.size());
for (int i = 0; i < columnMetadatas.size(); i++) {
ColumnMetadata columnMetadata = columnMetadatas.get(i);
assertEquals(columnMetadata.getName(), columnNames.get(i));
if (columnMetadata.getName().equals(PARTITION_COLUMN_NAME)) {
assertTrue(columnMetadata.isHidden());
}
}
assertEquals(getPartitions("test_partition_hidden_column").size(), 9);
MaterializedResult results = computeActual(format("SELECT *, \"%s\" FROM test_partition_hidden_column", PARTITION_COLUMN_NAME));
for (MaterializedRow row : results.getMaterializedRows()) {
String actualPartition = (String) row.getField(3);
String expectedPartition = format("col1=%s/col2=%s", row.getField(1), row.getField(2));
assertEquals(actualPartition, expectedPartition);
}
assertEquals(results.getRowCount(), 9);
assertUpdate("DROP TABLE test_partition_hidden_column");
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class BaseHiveConnectorTest method verifyPartition.
private void verifyPartition(boolean hasPartition, TableMetadata tableMetadata, List<String> partitionKeys) {
Object partitionByProperty = tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY);
if (hasPartition) {
assertEquals(partitionByProperty, partitionKeys);
for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
boolean partitionKey = partitionKeys.contains(columnMetadata.getName());
assertEquals(columnMetadata.getExtraInfo(), columnExtraInfo(partitionKey));
}
} else {
assertNull(partitionByProperty);
}
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class BaseHiveConnectorTest method testFileSizeHiddenColumn.
@Test
public void testFileSizeHiddenColumn() {
@Language("SQL") String createTable = "CREATE TABLE test_file_size " + "WITH (" + "partitioned_by = ARRAY['col1']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
assertUpdate(createTable, 8);
assertTrue(getQueryRunner().tableExists(getSession(), "test_file_size"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_size");
List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME, PARTITION_COLUMN_NAME);
List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
assertEquals(columnMetadatas.size(), columnNames.size());
for (int i = 0; i < columnMetadatas.size(); i++) {
ColumnMetadata columnMetadata = columnMetadatas.get(i);
assertEquals(columnMetadata.getName(), columnNames.get(i));
if (columnMetadata.getName().equals(FILE_SIZE_COLUMN_NAME)) {
assertTrue(columnMetadata.isHidden());
}
}
assertEquals(getPartitions("test_file_size").size(), 3);
MaterializedResult results = computeActual(format("SELECT *, \"%s\" FROM test_file_size", FILE_SIZE_COLUMN_NAME));
Map<Integer, Long> fileSizeMap = new HashMap<>();
for (int i = 0; i < results.getRowCount(); i++) {
MaterializedRow row = results.getMaterializedRows().get(i);
int col0 = (int) row.getField(0);
int col1 = (int) row.getField(1);
long fileSize = (Long) row.getField(2);
assertTrue(fileSize > 0);
assertEquals(col0 % 3, col1);
if (fileSizeMap.containsKey(col1)) {
assertEquals(fileSizeMap.get(col1).longValue(), fileSize);
} else {
fileSizeMap.put(col1, fileSize);
}
}
assertEquals(fileSizeMap.size(), 3);
assertUpdate("DROP TABLE test_file_size");
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class BaseHiveConnectorTest method testFileModifiedTimeHiddenColumn.
@Test(dataProvider = "timestampPrecision")
public void testFileModifiedTimeHiddenColumn(HiveTimestampPrecision precision) {
long testStartTime = Instant.now().toEpochMilli();
@Language("SQL") String createTable = "CREATE TABLE test_file_modified_time " + "WITH (" + "partitioned_by = ARRAY['col1']" + ") AS " + "SELECT * FROM (VALUES " + "(0, 0), (3, 0), (6, 0), " + "(1, 1), (4, 1), (7, 1), " + "(2, 2), (5, 2) " + " ) t(col0, col1) ";
assertUpdate(createTable, 8);
assertTrue(getQueryRunner().tableExists(getSession(), "test_file_modified_time"));
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_file_modified_time");
List<String> columnNames = ImmutableList.of("col0", "col1", PATH_COLUMN_NAME, FILE_SIZE_COLUMN_NAME, FILE_MODIFIED_TIME_COLUMN_NAME, PARTITION_COLUMN_NAME);
List<ColumnMetadata> columnMetadatas = tableMetadata.getColumns();
assertEquals(columnMetadatas.size(), columnNames.size());
for (int i = 0; i < columnMetadatas.size(); i++) {
ColumnMetadata columnMetadata = columnMetadatas.get(i);
assertEquals(columnMetadata.getName(), columnNames.get(i));
if (columnMetadata.getName().equals(FILE_MODIFIED_TIME_COLUMN_NAME)) {
assertTrue(columnMetadata.isHidden());
}
}
assertEquals(getPartitions("test_file_modified_time").size(), 3);
Session sessionWithTimestampPrecision = withTimestampPrecision(getSession(), precision);
MaterializedResult results = computeActual(sessionWithTimestampPrecision, format("SELECT *, \"%s\" FROM test_file_modified_time", FILE_MODIFIED_TIME_COLUMN_NAME));
Map<Integer, Instant> fileModifiedTimeMap = new HashMap<>();
for (int i = 0; i < results.getRowCount(); i++) {
MaterializedRow row = results.getMaterializedRows().get(i);
int col0 = (int) row.getField(0);
int col1 = (int) row.getField(1);
Instant fileModifiedTime = ((ZonedDateTime) row.getField(2)).toInstant();
assertThat(fileModifiedTime.toEpochMilli()).isCloseTo(testStartTime, offset(2000L));
assertEquals(col0 % 3, col1);
if (fileModifiedTimeMap.containsKey(col1)) {
assertEquals(fileModifiedTimeMap.get(col1), fileModifiedTime);
} else {
fileModifiedTimeMap.put(col1, fileModifiedTime);
}
}
assertEquals(fileModifiedTimeMap.size(), 3);
assertUpdate("DROP TABLE test_file_modified_time");
}
use of io.trino.spi.connector.ColumnMetadata in project trino by trinodb.
the class TestingMetadata method addColumn.
@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) {
ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
SchemaTableName tableName = getTableName(tableHandle);
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
columns.addAll(tableMetadata.getColumns());
columns.add(column);
tables.put(tableName, new ConnectorTableMetadata(tableName, columns.build(), tableMetadata.getProperties(), tableMetadata.getComment()));
}
Aggregations