Search in sources :

Example 56 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 57 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 58 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 59 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 60 with ConnectorTableMetadata

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

the class H2QueryRunner method insertRows.

private static void insertRows(ConnectorTableMetadata tableMetadata, Handle handle, RecordSet data) {
    List<ColumnMetadata> columns = tableMetadata.getColumns().stream().filter(columnMetadata -> !columnMetadata.isHidden()).collect(toImmutableList());
    String vars = Joiner.on(',').join(nCopies(columns.size(), "?"));
    String sql = format("INSERT INTO %s VALUES (%s)", tableMetadata.getTable().getTableName(), vars);
    RecordCursor cursor = data.cursor();
    while (true) {
        // insert 1000 rows at a time
        PreparedBatch batch = handle.prepareBatch(sql);
        for (int row = 0; row < 1000; row++) {
            if (!cursor.advanceNextPosition()) {
                batch.execute();
                return;
            }
            PreparedBatchPart part = batch.add();
            for (int column = 0; column < columns.size(); column++) {
                Type type = columns.get(column).getType();
                if (BOOLEAN.equals(type)) {
                    part.bind(column, cursor.getBoolean(column));
                } else if (BIGINT.equals(type)) {
                    part.bind(column, cursor.getLong(column));
                } else if (INTEGER.equals(type)) {
                    part.bind(column, (int) cursor.getLong(column));
                } else if (DOUBLE.equals(type)) {
                    part.bind(column, cursor.getDouble(column));
                } else if (type instanceof VarcharType) {
                    part.bind(column, cursor.getSlice(column).toStringUtf8());
                } else if (DATE.equals(type)) {
                    long millisUtc = TimeUnit.DAYS.toMillis(cursor.getLong(column));
                    // H2 expects dates in to be millis at midnight in the JVM timezone
                    long localMillis = DateTimeZone.UTC.getMillisKeepLocal(DateTimeZone.getDefault(), millisUtc);
                    part.bind(column, new Date(localMillis));
                } else {
                    throw new IllegalArgumentException("Unsupported type " + type);
                }
            }
        }
        batch.execute();
    }
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) ResultSetMapper(org.skife.jdbi.v2.tweak.ResultSetMapper) Time(java.sql.Time) TpchRecordSet.createTpchRecordSet(com.facebook.presto.tpch.TpchRecordSet.createTpchRecordSet) LINE_ITEM(io.airlift.tpch.TpchTable.LINE_ITEM) StatementContext(org.skife.jdbi.v2.StatementContext) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) BigDecimal(java.math.BigDecimal) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) DecimalType(com.facebook.presto.spi.type.DecimalType) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) ResultSet(java.sql.ResultSet) PreparedBatch(org.skife.jdbi.v2.PreparedBatch) UNKNOWN(com.facebook.presto.type.UnknownType.UNKNOWN) DateTimeZoneIndex.getDateTimeZone(com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) REGION(io.airlift.tpch.TpchTable.REGION) TINYINT(com.facebook.presto.spi.type.TinyintType.TINYINT) Collections.nCopies(java.util.Collections.nCopies) Timestamp(java.sql.Timestamp) TpchMetadata(com.facebook.presto.tpch.TpchMetadata) TINY_SCHEMA_NAME(com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TpchTable(io.airlift.tpch.TpchTable) RecordCursor(com.facebook.presto.spi.RecordCursor) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) PreparedBatchPart(org.skife.jdbi.v2.PreparedBatchPart) INTEGER(com.facebook.presto.spi.type.IntegerType.INTEGER) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) Joiner(com.google.common.base.Joiner) DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) Strings.padEnd(com.google.common.base.Strings.padEnd) NATION(io.airlift.tpch.TpchTable.NATION) TIMESTAMP_WITH_TIME_ZONE(com.facebook.presto.spi.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) ORDERS(io.airlift.tpch.TpchTable.ORDERS) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Type(com.facebook.presto.spi.type.Type) DBI(org.skife.jdbi.v2.DBI) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Language(org.intellij.lang.annotations.Language) Session(com.facebook.presto.Session) TIME(com.facebook.presto.spi.type.TimeType.TIME) SMALLINT(com.facebook.presto.spi.type.SmallintType.SMALLINT) TIME_WITH_TIME_ZONE(com.facebook.presto.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE) RecordSet(com.facebook.presto.spi.RecordSet) Date(java.sql.Date) CharType(com.facebook.presto.spi.type.CharType) TimeUnit(java.util.concurrent.TimeUnit) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Handle(org.skife.jdbi.v2.Handle) DATE(com.facebook.presto.spi.type.DateType.DATE) REAL(com.facebook.presto.spi.type.RealType.REAL) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Closeable(java.io.Closeable) VarcharType(com.facebook.presto.spi.type.VarcharType) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) DecimalType(com.facebook.presto.spi.type.DecimalType) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) Type(com.facebook.presto.spi.type.Type) CharType(com.facebook.presto.spi.type.CharType) VarcharType(com.facebook.presto.spi.type.VarcharType) Chars.isCharType(com.facebook.presto.spi.type.Chars.isCharType) RecordCursor(com.facebook.presto.spi.RecordCursor) Varchars.isVarcharType(com.facebook.presto.spi.type.Varchars.isVarcharType) VarcharType(com.facebook.presto.spi.type.VarcharType) PreparedBatchPart(org.skife.jdbi.v2.PreparedBatchPart) PreparedBatch(org.skife.jdbi.v2.PreparedBatch) Date(java.sql.Date)

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