Search in sources :

Example 6 with TableMetadata

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"));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) Language(org.intellij.lang.annotations.Language)

Example 7 with TableMetadata

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());
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) MaterializedResult(com.facebook.presto.testing.MaterializedResult)

Example 8 with TableMetadata

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());
    });
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Metadata(com.facebook.presto.metadata.Metadata) TableHandle(com.facebook.presto.metadata.TableHandle) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) HiveQueryRunner.createBucketedSession(com.facebook.presto.hive.HiveQueryRunner.createBucketedSession) Session(com.facebook.presto.Session)

Example 9 with TableMetadata

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));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) Language(org.intellij.lang.annotations.Language) Constraint(com.facebook.presto.spi.Constraint)

Example 10 with TableMetadata

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));
}
Also used : TableMetadata(com.facebook.presto.metadata.TableMetadata) TableScanNode(com.facebook.presto.sql.planner.plan.TableScanNode)

Aggregations

TableMetadata (com.facebook.presto.metadata.TableMetadata)18 Language (org.intellij.lang.annotations.Language)10 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)6 Constraint (com.facebook.presto.spi.Constraint)5 MaterializedResult (com.facebook.presto.testing.MaterializedResult)4 Session (com.facebook.presto.Session)3 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)3 ConnectorId (com.facebook.presto.connector.ConnectorId)2 Metadata (com.facebook.presto.metadata.Metadata)2 TableHandle (com.facebook.presto.metadata.TableHandle)2 ColumnHandle (com.facebook.presto.spi.ColumnHandle)2 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)2 PrestoException (com.facebook.presto.spi.PrestoException)2 Type (com.facebook.presto.spi.type.Type)2 TableScanNode (com.facebook.presto.sql.planner.plan.TableScanNode)2 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 HiveQueryRunner.createBucketedSession (com.facebook.presto.hive.HiveQueryRunner.createBucketedSession)1 MetadataUtil.createQualifiedObjectName (com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName)1 NewTableLayout (com.facebook.presto.metadata.NewTableLayout)1