Search in sources :

Example 1 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class RaptorQueryRunner method createSession.

public static Session createSession(String schema) {
    SessionPropertyManager sessionPropertyManager = new SessionPropertyManager();
    sessionPropertyManager.addConnectorSessionProperties(new ConnectorId("raptor"), new RaptorSessionProperties(new StorageManagerConfig()).getSessionProperties());
    return testSessionBuilder(sessionPropertyManager).setCatalog("raptor").setSchema(schema).setSystemProperty("processing_optimization", "columnar_dictionary").setSystemProperty("dictionary_aggregation", "true").build();
}
Also used : SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) ConnectorId(com.facebook.presto.connector.ConnectorId) StorageManagerConfig(com.facebook.presto.raptor.storage.StorageManagerConfig)

Example 2 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class TestLocalBinarySpilledQueries method createLocalQueryRunner.

private static LocalQueryRunner createLocalQueryRunner() {
    Session defaultSession = testSessionBuilder().setCatalog("local").setSchema(TINY_SCHEMA_NAME).setSystemProperty(SystemSessionProperties.SPILL_ENABLED, "true").setSystemProperty(SystemSessionProperties.OPERATOR_MEMORY_LIMIT_BEFORE_SPILL, //spill constantly
    "1B").build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);
    // add the tpch catalog
    // local queries run directly against the generator
    localQueryRunner.createCatalog(defaultSession.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
    localQueryRunner.getMetadata().addFunctions(CUSTOM_FUNCTIONS);
    SessionPropertyManager sessionPropertyManager = localQueryRunner.getMetadata().getSessionPropertyManager();
    sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES);
    sessionPropertyManager.addConnectorSessionProperties(new ConnectorId(TESTING_CATALOG), TEST_CATALOG_PROPERTIES);
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 3 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class TestLocalQueries method createLocalQueryRunner.

public static LocalQueryRunner createLocalQueryRunner() {
    Session defaultSession = testSessionBuilder().setCatalog("local").setSchema(TINY_SCHEMA_NAME).setSystemProperty(REORDER_JOINS, "true").build();
    LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);
    // add the tpch catalog
    // local queries run directly against the generator
    localQueryRunner.createCatalog(defaultSession.getCatalog().get(), new TpchConnectorFactory(1), ImmutableMap.of());
    localQueryRunner.getMetadata().addFunctions(CUSTOM_FUNCTIONS);
    SessionPropertyManager sessionPropertyManager = localQueryRunner.getMetadata().getSessionPropertyManager();
    sessionPropertyManager.addSystemSessionProperties(TEST_SYSTEM_PROPERTIES);
    sessionPropertyManager.addConnectorSessionProperties(new ConnectorId(TESTING_CATALOG), TEST_CATALOG_PROPERTIES);
    return localQueryRunner;
}
Also used : TpchConnectorFactory(com.facebook.presto.tpch.TpchConnectorFactory) SessionPropertyManager(com.facebook.presto.metadata.SessionPropertyManager) LocalQueryRunner(com.facebook.presto.testing.LocalQueryRunner) Session(com.facebook.presto.Session) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 4 with ConnectorId

use of com.facebook.presto.connector.ConnectorId in project presto by prestodb.

the class CatalogSystemTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Builder table = InMemoryRecordSet.builder(CATALOG_TABLE);
    for (Map.Entry<String, ConnectorId> entry : listCatalogs(session, metadata, accessControl).entrySet()) {
        table.addRow(entry.getKey(), entry.getValue().toString());
    }
    return table.build().cursor();
}
Also used : TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) Map(java.util.Map) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession) ConnectorId(com.facebook.presto.connector.ConnectorId)

Example 5 with ConnectorId

use of com.facebook.presto.connector.ConnectorId 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

ConnectorId (com.facebook.presto.connector.ConnectorId)76 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)39 ConnectorSession (com.facebook.presto.spi.ConnectorSession)14 Session (com.facebook.presto.Session)12 PrestoException (com.facebook.presto.spi.PrestoException)9 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)7 Test (org.testng.annotations.Test)7 ConnectorId.createInformationSchemaConnectorId (com.facebook.presto.connector.ConnectorId.createInformationSchemaConnectorId)5 ConnectorId.createSystemTablesConnectorId (com.facebook.presto.connector.ConnectorId.createSystemTablesConnectorId)5 TableHandle (com.facebook.presto.metadata.TableHandle)5 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)5 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)5 ImmutableList (com.google.common.collect.ImmutableList)5 QualifiedObjectName (com.facebook.presto.metadata.QualifiedObjectName)4 QualifiedObjectName.convertFromSchemaTableName (com.facebook.presto.metadata.QualifiedObjectName.convertFromSchemaTableName)4 SessionPropertyManager (com.facebook.presto.metadata.SessionPropertyManager)4 ConnectorInsertTableHandle (com.facebook.presto.spi.ConnectorInsertTableHandle)4 SemanticException (com.facebook.presto.sql.analyzer.SemanticException)4 TransactionManager (com.facebook.presto.transaction.TransactionManager)4