use of com.facebook.presto.metadata.TableMetadata in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method createPartitionedTableAs.
public void createPartitionedTableAs(Session session, HiveStorageFormat storageFormat) throws Exception {
@Language("SQL") String createTable = "" + "CREATE TABLE test_create_partitioned_table_as " + "WITH (" + "format = '" + storageFormat + "', " + "partitioned_by = ARRAY[ 'SHIP_PRIORITY', 'ORDER_STATUS' ]" + ") " + "AS " + "SELECT orderkey AS order_key, shippriority AS ship_priority, orderstatus AS order_status " + "FROM tpch.tiny.orders";
assertUpdate(session, createTable, "SELECT count(*) from orders");
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, "test_create_partitioned_table_as");
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("ship_priority", "order_status"));
List<?> partitions = getPartitions("test_create_partitioned_table_as");
assertEquals(partitions.size(), 3);
assertQuery(session, "SELECT * from test_create_partitioned_table_as", "SELECT orderkey, shippriority, orderstatus FROM orders");
assertUpdate(session, "DROP TABLE test_create_partitioned_table_as");
assertFalse(getQueryRunner().tableExists(session, "test_create_partitioned_table_as"));
}
use of com.facebook.presto.metadata.TableMetadata in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method verifyPartitionedBucketedTableAsFewRows.
private void verifyPartitionedBucketedTableAsFewRows(HiveStorageFormat storageFormat, String tableName) {
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, tableName);
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
assertEquals(tableMetadata.getMetadata().getProperties().get(PARTITIONED_BY_PROPERTY), ImmutableList.of("partition_key"));
assertEquals(tableMetadata.getMetadata().getProperties().get(BUCKETED_BY_PROPERTY), ImmutableList.of("bucket_key"));
assertEquals(tableMetadata.getMetadata().getProperties().get(BUCKET_COUNT_PROPERTY), 11);
List<?> partitions = getPartitions(tableName);
assertEquals(partitions.size(), 3);
MaterializedResult actual = computeActual("SELECT * from " + tableName);
MaterializedResult expected = resultBuilder(getSession(), canonicalizeType(createUnboundedVarcharType()), canonicalizeType(createUnboundedVarcharType()), canonicalizeType(createUnboundedVarcharType())).row("a", "b", "c").row("aa", "bb", "cc").row("aaa", "bbb", "ccc").build();
assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
}
use of com.facebook.presto.metadata.TableMetadata in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method getTableMetadata.
private TableMetadata getTableMetadata(String catalog, String schema, String tableName) {
Session session = getSession();
Metadata metadata = ((DistributedQueryRunner) getQueryRunner()).getCoordinator().getMetadata();
return transaction(getQueryRunner().getTransactionManager(), getQueryRunner().getAccessControl()).readOnly().execute(session, transactionSession -> {
Optional<TableHandle> tableHandle = metadata.getTableHandle(transactionSession, new QualifiedObjectName(catalog, schema, tableName));
assertTrue(tableHandle.isPresent());
return metadata.getTableMetadata(transactionSession, tableHandle.get());
});
}
use of com.facebook.presto.metadata.TableMetadata in project presto by prestodb.
the class TestHiveIntegrationSmokeTest method testInsertUnpartitionedTable.
private void testInsertUnpartitionedTable(Session session, HiveStorageFormat storageFormat) throws Exception {
String tableName = "test_insert_unpartitioned_table";
@Language("SQL") String createTable = "" + "CREATE TABLE " + tableName + " " + "(" + " order_key BIGINT," + " comment VARCHAR," + " order_status VARCHAR" + ") " + "WITH (" + "format = '" + storageFormat + "'" + ") ";
assertUpdate(session, createTable);
TableMetadata tableMetadata = getTableMetadata(catalog, TPCH_SCHEMA, tableName);
assertEquals(tableMetadata.getMetadata().getProperties().get(STORAGE_FORMAT_PROPERTY), storageFormat);
for (int i = 0; i < 3; i++) {
assertUpdate(session, format("INSERT INTO " + tableName + " " + "SELECT orderkey, comment, orderstatus " + "FROM tpch.tiny.orders " + "WHERE orderkey %% 3 = %d", i), format("SELECT count(*) from orders where orderkey %% 3 = %d", i));
}
assertQuery(session, "SELECT * from " + tableName, "SELECT orderkey, comment, orderstatus FROM orders");
assertUpdate(session, "DROP TABLE " + tableName);
assertFalse(getQueryRunner().tableExists(session, tableName));
}
use of com.facebook.presto.metadata.TableMetadata in project presto by prestodb.
the class TableScanMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
TableScanNode tableScanNode = (TableScanNode) node;
TableMetadata tableMetadata = metadata.getTableMetadata(session, tableScanNode.getTable());
String actualTableName = tableMetadata.getTable().getTableName();
return new MatchResult(expectedTableName.equalsIgnoreCase(actualTableName) && domainMatches(tableScanNode, session, metadata));
}
Aggregations