Search in sources :

Example 31 with ConnectorTableMetadata

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

the class TpchMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
    String columnName = ((TpchColumnHandle) columnHandle).getColumnName();
    for (ColumnMetadata column : tableMetadata.getColumns()) {
        if (column.getName().equals(columnName)) {
            return column;
        }
    }
    throw new IllegalArgumentException(String.format("Table %s does not have column %s", tableMetadata.getTable(), columnName));
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 32 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testCreateBucketedTableExistingDistribution.

@Test
public void testCreateBucketedTableExistingDistribution() {
    MetadataDao metadataDao = dbi.onDemand(MetadataDao.class);
    // create orders table
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata table = getOrdersTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey"), DISTRIBUTION_NAME_PROPERTY, "orders"));
    metadata.createTable(SESSION, table);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    long tableId = raptorTableHandle.getTableId();
    assertEquals(raptorTableHandle.getTableId(), 1);
    assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_ORDERS, "orderkey", BIGINT, 1, OptionalInt.of(0), OptionalInt.empty(), false)));
    assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(16));
    assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
    // create lineitems table
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_LINEITEMS));
    table = getLineItemsTable(ImmutableMap.of(BUCKET_COUNT_PROPERTY, 16, BUCKETED_ON_PROPERTY, ImmutableList.of("orderkey"), DISTRIBUTION_NAME_PROPERTY, "orders"));
    metadata.createTable(SESSION, table);
    tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_LINEITEMS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    raptorTableHandle = (RaptorTableHandle) tableHandle;
    tableId = raptorTableHandle.getTableId();
    assertEquals(tableId, 2);
    assertTableColumnsEqual(metadataDao.listBucketColumns(tableId), ImmutableList.of(new TableColumn(DEFAULT_TEST_LINEITEMS, "orderkey", BIGINT, 1, OptionalInt.of(0), OptionalInt.empty(), false)));
    assertEquals(raptorTableHandle.getBucketCount(), OptionalInt.of(16));
    assertEquals(getTableDistributionId(tableId), Long.valueOf(1));
}
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 33 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testInvalidOrderingColumns.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "Ordering column does not exist: orderdatefoo")
public void testInvalidOrderingColumns() throws Exception {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdatefoo")));
    metadata.createTable(SESSION, ordersTable);
    fail("Expected createTable to fail");
}
Also used : ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Test(org.testng.annotations.Test)

Example 34 with ConnectorTableMetadata

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

the class TestRaptorMetadata method assertTableEqual.

private static void assertTableEqual(ConnectorTableMetadata actual, ConnectorTableMetadata expected) {
    assertEquals(actual.getTable(), expected.getTable());
    List<ColumnMetadata> actualColumns = actual.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(Collectors.toList());
    List<ColumnMetadata> expectedColumns = expected.getColumns();
    assertEquals(actualColumns.size(), expectedColumns.size());
    for (int i = 0; i < actualColumns.size(); i++) {
        ColumnMetadata actualColumn = actualColumns.get(i);
        ColumnMetadata expectedColumn = expectedColumns.get(i);
        assertEquals(actualColumn.getName(), expectedColumn.getName());
        assertEquals(actualColumn.getType(), expectedColumn.getType());
    }
    assertEquals(actual.getProperties(), expected.getProperties());
}
Also used : Assertions.assertInstanceOf(io.airlift.testing.Assertions.assertInstanceOf) TypeRegistry(com.facebook.presto.type.TypeRegistry) Test(org.testng.annotations.Test) RaptorTableIdentity(com.facebook.presto.raptor.RaptorTableIdentity) AfterMethod(org.testng.annotations.AfterMethod) TableIdentity(com.facebook.presto.spi.TableIdentity) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) Ticker.systemTicker(com.google.common.base.Ticker.systemTicker) RaptorSessionProperties(com.facebook.presto.raptor.RaptorSessionProperties) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Map(java.util.Map) RaptorColumnIdentity(com.facebook.presto.raptor.RaptorColumnIdentity) RaptorTableHandle(com.facebook.presto.raptor.RaptorTableHandle) Assert.assertFalse(org.testng.Assert.assertFalse) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) ImmutableSet(com.google.common.collect.ImmutableSet) NodeManager(com.facebook.presto.spi.NodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) DISTRIBUTION_NAME_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.DISTRIBUTION_NAME_PROPERTY) BeforeMethod(org.testng.annotations.BeforeMethod) Assert.assertNotNull(org.testng.Assert.assertNotNull) TestingNodeManager(com.facebook.presto.testing.TestingNodeManager) StorageManagerConfig(com.facebook.presto.raptor.storage.StorageManagerConfig) Collectors(java.util.stream.Collectors) ConnectorSession(com.facebook.presto.spi.ConnectorSession) SchemaDaoUtil.createTablesWithRetry(com.facebook.presto.raptor.metadata.SchemaDaoUtil.createTablesWithRetry) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) TEMPORAL_COLUMN_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.TEMPORAL_COLUMN_PROPERTY) Optional(java.util.Optional) TableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) ORGANIZED_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.ORGANIZED_PROPERTY) Assert.assertNull(org.testng.Assert.assertNull) NodeSupplier(com.facebook.presto.raptor.NodeSupplier) Assert.assertEquals(org.testng.Assert.assertEquals) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorOutputTableHandle(com.facebook.presto.spi.ConnectorOutputTableHandle) PrestoException(com.facebook.presto.spi.PrestoException) OptionalInt(java.util.OptionalInt) OptionalLong(java.util.OptionalLong) ImmutableList(com.google.common.collect.ImmutableList) DBI(org.skife.jdbi.v2.DBI) RaptorMetadata(com.facebook.presto.raptor.RaptorMetadata) RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) BooleanMapper(org.skife.jdbi.v2.util.BooleanMapper) ConnectorInsertTableHandle(com.facebook.presto.spi.ConnectorInsertTableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BUCKETED_ON_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.BUCKETED_ON_PROPERTY) TestDatabaseShardManager.createShardManager(com.facebook.presto.raptor.metadata.TestDatabaseShardManager.createShardManager) ORDERING_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.ORDERING_PROPERTY) RaptorPartitioningHandle(com.facebook.presto.raptor.RaptorPartitioningHandle) Assert.fail(org.testng.Assert.fail) ColumnIdentity(com.facebook.presto.spi.ColumnIdentity) LongMapper(org.skife.jdbi.v2.util.LongMapper) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) TRANSACTION_CONFLICT(com.facebook.presto.spi.StandardErrorCode.TRANSACTION_CONFLICT) Assertions.assertEqualsIgnoreOrder(io.airlift.testing.Assertions.assertEqualsIgnoreOrder) Handle(org.skife.jdbi.v2.Handle) RaptorConnectorId(com.facebook.presto.raptor.RaptorConnectorId) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) DATE(com.facebook.presto.spi.type.DateType.DATE) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorNewTableLayout(com.facebook.presto.spi.ConnectorNewTableLayout) ByteStreams.newDataOutput(com.google.common.io.ByteStreams.newDataOutput) Assert.assertTrue(org.testng.Assert.assertTrue) ConnectorViewDefinition(com.facebook.presto.spi.ConnectorViewDefinition) BUCKET_COUNT_PROPERTY(com.facebook.presto.raptor.RaptorTableProperties.BUCKET_COUNT_PROPERTY) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata)

Example 35 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testCreateTable.

@Test
public void testCreateTable() {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, getOrdersTable());
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);
    assertEquals(((RaptorTableHandle) tableHandle).getTableId(), 1);
    ConnectorTableMetadata table = metadata.getTableMetadata(SESSION, tableHandle);
    assertTableEqual(table, getOrdersTable());
    ColumnHandle columnHandle = metadata.getColumnHandles(SESSION, tableHandle).get("orderkey");
    assertInstanceOf(columnHandle, RaptorColumnHandle.class);
    assertEquals(((RaptorColumnHandle) columnHandle).getColumnId(), 1);
    ColumnMetadata columnMetadata = metadata.getColumnMetadata(SESSION, tableHandle, columnHandle);
    assertNotNull(columnMetadata);
    assertEquals(columnMetadata.getName(), "orderkey");
    assertEquals(columnMetadata.getType(), BIGINT);
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) 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