Search in sources :

Example 36 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestRaptorMetadata method testTableProperties.

@Test
public void testTableProperties() throws Exception {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey"), TEMPORAL_COLUMN_PROPERTY, "orderdate"));
    metadata.createTable(SESSION, ordersTable);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    // verify sort columns
    List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
    assertTableColumnsEqual(sortColumns, ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderdate", DATE, 4, OptionalInt.empty(), OptionalInt.of(0), true), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, OptionalInt.empty(), OptionalInt.of(1), false)));
    // verify temporal column
    assertEquals(metadataDao.getTemporalColumnId(tableId), Long.valueOf(4));
    // verify no organization
    assertFalse(metadataDao.getTableInformation(tableId).isOrganized());
    metadata.dropTable(SESSION, tableHandle);
}
Also used : RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 37 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestRaptorMetadata method testTemporalColumn.

@Test
public void testTemporalColumn() throws Exception {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(TEMPORAL_COLUMN_PROPERTY, "orderdate"));
    metadata.createTable(SESSION, ordersTable);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    // verify sort columns are not set
    List<TableColumn> sortColumns = metadataDao.listSortColumns(tableId);
    assertEquals(sortColumns.size(), 0);
    assertEquals(sortColumns, ImmutableList.of());
    // verify temporal column is set
    assertEquals(metadataDao.getTemporalColumnId(tableId), Long.valueOf(4));
    metadata.dropTable(SESSION, tableHandle);
}
Also used : RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 38 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestRaptorMetadata method testCreateBucketedTable.

@Test
public void testCreateBucketedTable() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("custkey", "orderkey")));
    metadata.createTable(SESSION, ordersTable);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    assertEquals(raptorTableHandle.getTableId(), 1);
    long tableId = raptorTableHandle.getTableId();
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, OptionalInt.of(0), OptionalInt.empty(), false), new TableColumn(DEFAULT_TEST_ORDERS, "orderkey", BIGINT, 1, OptionalInt.of(1), OptionalInt.empty(), false)));
    assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(16));
    assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
    metadata.dropTable(SESSION, tableHandle);
    // create a new table and verify it has a different distribution
    metadata.createTable(SESSION, ordersTable);
    tableId = ((RaptorTableHandle) metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS)).getTableId();
    assertEquals(tableId, 2);
    assertEquals(getTableDistributionId(tableId), Long.valueOf(2));
}
Also used : RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Test(org.testng.annotations.Test)

Example 39 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class RedisMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    requireNonNull(prefix, "prefix is null");
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();
    List<SchemaTableName> tableNames;
    if (prefix.getSchemaName() == null) {
        tableNames = listTables(session, null);
    } else {
        tableNames = ImmutableList.of(new SchemaTableName(prefix.getSchemaName(), prefix.getTableName()));
    }
    for (SchemaTableName tableName : tableNames) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 40 with ConnectorTableMetadata

use of com.facebook.presto.spi.ConnectorTableMetadata in project presto by prestodb.

the class TestExampleMetadata method getTableMetadata.

@Test
public void getTableMetadata() {
    // known table
    ConnectorTableMetadata tableMetadata = metadata.getTableMetadata(SESSION, NUMBERS_TABLE_HANDLE);
    assertEquals(tableMetadata.getTable(), new SchemaTableName("example", "numbers"));
    assertEquals(tableMetadata.getColumns(), ImmutableList.of(new ColumnMetadata("text", createUnboundedVarcharType()), new ColumnMetadata("value", BIGINT)));
    // unknown tables should produce null
    assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle(CONNECTOR_ID, "unknown", "unknown")));
    assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle(CONNECTOR_ID, "example", "unknown")));
    assertNull(metadata.getTableMetadata(SESSION, new ExampleTableHandle(CONNECTOR_ID, "unknown", "numbers")));
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Aggregations

ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)60 SchemaTableName (com.facebook.presto.spi.SchemaTableName)28 Test (org.testng.annotations.Test)28 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)26 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)23 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)17 ImmutableList (com.google.common.collect.ImmutableList)14 ConnectorSession (com.facebook.presto.spi.ConnectorSession)13 ColumnHandle (com.facebook.presto.spi.ColumnHandle)12 TestingConnectorSession (com.facebook.presto.testing.TestingConnectorSession)12 ImmutableMap (com.google.common.collect.ImmutableMap)12 List (java.util.List)11 ConnectorOutputTableHandle (com.facebook.presto.spi.ConnectorOutputTableHandle)10 RaptorTableHandle (com.facebook.presto.raptor.RaptorTableHandle)8 PrestoException (com.facebook.presto.spi.PrestoException)7 ConnectorPageSource (com.facebook.presto.spi.ConnectorPageSource)6 Constraint (com.facebook.presto.spi.Constraint)6 Path (org.apache.hadoop.fs.Path)6 Table (com.facebook.presto.hive.metastore.Table)5 ConnectorPageSink (com.facebook.presto.spi.ConnectorPageSink)5