Search in sources :

Example 16 with ConnectorTableMetadata

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

the class InformationSchemaMetadata method getColumnMetadata.

@Override
public ColumnMetadata getColumnMetadata(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnHandle columnHandle) {
    InformationSchemaTableHandle informationSchemaTableHandle = checkTableHandle(tableHandle);
    ConnectorTableMetadata tableMetadata = TABLES.get(informationSchemaTableHandle.getSchemaTableName());
    String columnName = ((InformationSchemaColumnHandle) 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 17 with ConnectorTableMetadata

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

the class LogicalPlanner method createTableCreationPlan.

private RelationPlan createTableCreationPlan(Analysis analysis, Query query) {
    QualifiedObjectName destination = analysis.getCreateTableDestination().get();
    RelationPlan plan = createRelationPlan(analysis, query);
    ConnectorTableMetadata tableMetadata = createTableMetadata(destination, getOutputTableColumns(plan), analysis.getCreateTableProperties(), analysis.getParameters());
    Optional<NewTableLayout> newTableLayout = metadata.getNewTableLayout(session, destination.getCatalogName(), tableMetadata);
    List<String> columnNames = tableMetadata.getColumns().stream().filter(column -> !column.isHidden()).map(ColumnMetadata::getName).collect(toImmutableList());
    return createTableWriterPlan(analysis, plan, new CreateName(destination.getCatalogName(), tableMetadata, newTableLayout), columnNames, newTableLayout);
}
Also used : NewTableLayout(com.facebook.presto.metadata.NewTableLayout) CreateName(com.facebook.presto.sql.planner.plan.TableWriterNode.CreateName) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 18 with ConnectorTableMetadata

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

the class TestingMetadata method addColumn.

@Override
public void addColumn(ConnectorSession session, ConnectorTableHandle tableHandle, ColumnMetadata column) {
    ConnectorTableMetadata tableMetadata = getTableMetadata(session, tableHandle);
    SchemaTableName tableName = getTableName(tableHandle);
    ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
    columns.addAll(tableMetadata.getColumns());
    columns.add(column);
    tables.put(tableName, new ConnectorTableMetadata(tableName, columns.build(), tableMetadata.getProperties()));
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) ImmutableList(com.google.common.collect.ImmutableList) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 19 with ConnectorTableMetadata

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

the class TestingMetadata method createTable.

@Override
public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) {
    ConnectorTableMetadata existingTable = tables.putIfAbsent(tableMetadata.getTable(), tableMetadata);
    checkArgument(existingTable == null, "Table %s already exists", tableMetadata.getTable());
}
Also used : ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

Example 20 with ConnectorTableMetadata

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

the class TestingMetadata method getTableMetadata.

@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle) {
    requireNonNull(tableHandle, "tableHandle is null");
    SchemaTableName tableName = getTableName(tableHandle);
    ConnectorTableMetadata tableMetadata = tables.get(tableName);
    checkArgument(tableMetadata != null, "Table %s does not exist", tableName);
    return tableMetadata;
}
Also used : SchemaTableName(com.facebook.presto.spi.SchemaTableName) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata)

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