Search in sources :

Example 11 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testSortOrderProperty.

@Test
public void testSortOrderProperty() throws Exception {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey")));
    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), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, OptionalInt.empty(), OptionalInt.of(1), false)));
    // verify temporal column is not set
    assertEquals(metadataDao.getTemporalColumnId(tableId), null);
    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 12 with ConnectorTableMetadata

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

the class TestRaptorMetadata method testTablePropertiesWithOrganization.

@Test
public void testTablePropertiesWithOrganization() throws Exception {
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableMetadata ordersTable = getOrdersTable(ImmutableMap.of(ORDERING_PROPERTY, ImmutableList.of("orderdate", "custkey"), ORGANIZED_PROPERTY, true));
    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), false), new TableColumn(DEFAULT_TEST_ORDERS, "custkey", BIGINT, 2, OptionalInt.empty(), OptionalInt.of(1), false)));
    // verify organization
    assertTrue(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 13 with ConnectorTableMetadata

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

the class TpchMetadata method listTableColumns.

@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix) {
    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> tableColumns = ImmutableMap.builder();
    for (String schemaName : getSchemaNames(session, prefix.getSchemaName())) {
        for (TpchTable<?> tpchTable : TpchTable.getTables()) {
            if (prefix.getTableName() == null || tpchTable.getTableName().equals(prefix.getTableName())) {
                ConnectorTableMetadata tableMetadata = getTableMetadata(schemaName, tpchTable);
                tableColumns.put(new SchemaTableName(schemaName, tpchTable.getTableName()), tableMetadata.getColumns());
            }
        }
    }
    return tableColumns.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 14 with ConnectorTableMetadata

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

the class SystemTablesMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    SystemTableHandle systemTableHandle = checkTableHandle(tableHandle);
    ConnectorTableMetadata tableMetadata = tables.get(systemTableHandle.getSchemaTableName());
    String columnName = ((SystemColumnHandle) columnHandle).getColumnName();
    ColumnMetadata columnMetadata = findColumnMetadata(tableMetadata, columnName);
    checkArgument(columnMetadata != null, "Column %s on table %s does not exist", columnName, tableMetadata.getTable());
    return columnMetadata;
}
Also used : MetadataUtil.findColumnMetadata(com.facebook.presto.metadata.MetadataUtil.findColumnMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 15 with ConnectorTableMetadata

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

the class CreateTableTask method execute.

@Override
public ListenableFuture<?> execute(CreateTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
    checkArgument(!statement.getElements().isEmpty(), "no columns for table");
    Session session = stateMachine.getSession();
    QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getName());
    Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
    if (tableHandle.isPresent()) {
        if (!statement.isNotExists()) {
            throw new SemanticException(TABLE_ALREADY_EXISTS, statement, "Table '%s' already exists", tableName);
        }
        return immediateFuture(null);
    }
    List<ColumnMetadata> columns = new ArrayList<>();
    Map<String, Object> inheritedProperties = ImmutableMap.of();
    boolean includingProperties = false;
    for (TableElement element : statement.getElements()) {
        if (element instanceof ColumnDefinition) {
            ColumnDefinition column = (ColumnDefinition) element;
            Type type = metadata.getType(parseTypeSignature(column.getType()));
            if ((type == null) || type.equals(UNKNOWN)) {
                throw new SemanticException(TYPE_MISMATCH, column, "Unknown type for column '%s' ", column.getName());
            }
            columns.add(new ColumnMetadata(column.getName(), type, column.getComment().orElse(null), false));
        } else if (element instanceof LikeClause) {
            LikeClause likeClause = (LikeClause) element;
            QualifiedObjectName likeTableName = createQualifiedObjectName(session, statement, likeClause.getTableName());
            if (!metadata.getCatalogHandle(session, likeTableName.getCatalogName()).isPresent()) {
                throw new SemanticException(MISSING_CATALOG, statement, "LIKE table catalog '%s' does not exist", likeTableName.getCatalogName());
            }
            if (!tableName.getCatalogName().equals(likeTableName.getCatalogName())) {
                throw new SemanticException(NOT_SUPPORTED, statement, "LIKE table across catalogs is not supported");
            }
            TableHandle likeTable = metadata.getTableHandle(session, likeTableName).orElseThrow(() -> new SemanticException(MISSING_TABLE, statement, "LIKE table '%s' does not exist", likeTableName));
            TableMetadata likeTableMetadata = metadata.getTableMetadata(session, likeTable);
            Optional<LikeClause.PropertiesOption> propertiesOption = likeClause.getPropertiesOption();
            if (propertiesOption.isPresent() && propertiesOption.get().equals(LikeClause.PropertiesOption.INCLUDING)) {
                if (includingProperties) {
                    throw new SemanticException(NOT_SUPPORTED, statement, "Only one LIKE clause can specify INCLUDING PROPERTIES");
                }
                includingProperties = true;
                inheritedProperties = likeTableMetadata.getMetadata().getProperties();
            }
            likeTableMetadata.getColumns().stream().filter(column -> !column.isHidden()).forEach(columns::add);
        } else {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, "Invalid TableElement: " + element.getClass().getName());
        }
    }
    accessControl.checkCanCreateTable(session.getRequiredTransactionId(), session.getIdentity(), tableName);
    ConnectorId connectorId = metadata.getCatalogHandle(session, tableName.getCatalogName()).orElseThrow(() -> new PrestoException(NOT_FOUND, "Catalog does not exist: " + tableName.getCatalogName()));
    Map<String, Object> properties = metadata.getTablePropertyManager().getProperties(connectorId, tableName.getCatalogName(), statement.getProperties(), session, metadata, parameters);
    Map<String, Object> finalProperties = combineProperties(statement.getProperties().keySet(), properties, inheritedProperties);
    ConnectorTableMetadata tableMetadata = new ConnectorTableMetadata(tableName.asSchemaTableName(), columns, finalProperties);
    metadata.createTable(session, tableName.getCatalogName(), tableMetadata);
    return immediateFuture(null);
}
Also used : LikeClause(com.facebook.presto.sql.tree.LikeClause) TableMetadata(com.facebook.presto.metadata.TableMetadata) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Optional(java.util.Optional) ArrayList(java.util.ArrayList) PrestoException(com.facebook.presto.spi.PrestoException) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) MetadataUtil.createQualifiedObjectName(com.facebook.presto.metadata.MetadataUtil.createQualifiedObjectName) TableElement(com.facebook.presto.sql.tree.TableElement) ColumnDefinition(com.facebook.presto.sql.tree.ColumnDefinition) Type(com.facebook.presto.spi.type.Type) TableHandle(com.facebook.presto.metadata.TableHandle) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) Session(com.facebook.presto.Session) SemanticException(com.facebook.presto.sql.analyzer.SemanticException) ConnectorId(com.facebook.presto.connector.ConnectorId)

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