Search in sources :

Example 41 with SchemaTableName

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

the class ColumnJdbcTable method cursor.

@Override
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint) {
    Session session = toSession(transactionHandle, connectorSession);
    Optional<String> catalogFilter = stringFilter(constraint, 0);
    Optional<String> schemaFilter = stringFilter(constraint, 1);
    Optional<String> tableFilter = stringFilter(constraint, 2);
    Builder table = InMemoryRecordSet.builder(METADATA);
    for (String catalog : filter(listCatalogs(session, metadata, accessControl).keySet(), catalogFilter)) {
        QualifiedTablePrefix prefix = FilterUtil.tablePrefix(catalog, schemaFilter, tableFilter);
        for (Entry<SchemaTableName, List<ColumnMetadata>> entry : listTableColumns(session, metadata, accessControl, prefix).entrySet()) {
            addColumnRows(table, catalog, entry.getKey(), entry.getValue());
        }
    }
    return table.build().cursor();
}
Also used : QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Builder(com.facebook.presto.spi.InMemoryRecordSet.Builder) List(java.util.List) SchemaTableName(com.facebook.presto.spi.SchemaTableName) SystemConnectorSessionUtil.toSession(com.facebook.presto.connector.system.SystemConnectorSessionUtil.toSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession)

Example 42 with SchemaTableName

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

the class SystemPageSourceProvider method createPageSource.

@Override
public ConnectorPageSource createPageSource(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<ColumnHandle> columns) {
    requireNonNull(columns, "columns is null");
    SystemTransactionHandle systemTransaction = (SystemTransactionHandle) transactionHandle;
    SystemSplit systemSplit = (SystemSplit) split;
    SchemaTableName tableName = systemSplit.getTableHandle().getSchemaTableName();
    SystemTable systemTable = tables.get(tableName);
    checkArgument(systemTable != null, "Table %s does not exist", tableName);
    List<ColumnMetadata> tableColumns = systemTable.getTableMetadata().getColumns();
    Map<String, Integer> columnsByName = new HashMap<>();
    for (int i = 0; i < tableColumns.size(); i++) {
        ColumnMetadata column = tableColumns.get(i);
        if (columnsByName.put(column.getName(), i) != null) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, "Duplicate column name: " + column.getName());
        }
    }
    ImmutableList.Builder<Integer> userToSystemFieldIndex = ImmutableList.builder();
    for (ColumnHandle column : columns) {
        String columnName = ((SystemColumnHandle) column).getColumnName();
        Integer index = columnsByName.get(columnName);
        if (index == null) {
            throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Column does not exist: %s.%s", tableName, columnName));
        }
        userToSystemFieldIndex.add(index);
    }
    TupleDomain<ColumnHandle> constraint = systemSplit.getConstraint();
    ImmutableMap.Builder<Integer, Domain> newConstraints = ImmutableMap.builder();
    for (Map.Entry<ColumnHandle, Domain> entry : constraint.getDomains().get().entrySet()) {
        String columnName = ((SystemColumnHandle) entry.getKey()).getColumnName();
        newConstraints.put(columnsByName.get(columnName), entry.getValue());
    }
    TupleDomain<Integer> newContraint = withColumnDomains(newConstraints.build());
    try {
        return new MappedPageSource(systemTable.pageSource(systemTransaction.getConnectorTransactionHandle(), session, newContraint), userToSystemFieldIndex.build());
    } catch (UnsupportedOperationException e) {
        return new RecordPageSource(new MappedRecordSet(toRecordSet(systemTransaction.getConnectorTransactionHandle(), systemTable, session, newContraint), userToSystemFieldIndex.build()));
    }
}
Also used : ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) ImmutableCollectors.toImmutableList(com.facebook.presto.util.ImmutableCollectors.toImmutableList) PrestoException(com.facebook.presto.spi.PrestoException) RecordPageSource(com.facebook.presto.spi.RecordPageSource) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) ColumnHandle(com.facebook.presto.spi.ColumnHandle) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableMap(com.google.common.collect.ImmutableMap) MappedPageSource(com.facebook.presto.split.MappedPageSource) SystemTable(com.facebook.presto.spi.SystemTable) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 43 with SchemaTableName

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

the class KafkaQueryRunner method createKafkaQueryRunner.

public static DistributedQueryRunner createKafkaQueryRunner(EmbeddedKafka embeddedKafka, Iterable<TpchTable<?>> tables) throws Exception {
    DistributedQueryRunner queryRunner = null;
    try {
        queryRunner = new DistributedQueryRunner(createSession(), 2);
        queryRunner.installPlugin(new TpchPlugin());
        queryRunner.createCatalog("tpch", "tpch");
        embeddedKafka.start();
        for (TpchTable<?> table : tables) {
            embeddedKafka.createTopics(kafkaTopicName(table));
        }
        Map<SchemaTableName, KafkaTopicDescription> topicDescriptions = createTpchTopicDescriptions(queryRunner.getCoordinator().getMetadata(), tables);
        installKafkaPlugin(embeddedKafka, queryRunner, topicDescriptions);
        TestingPrestoClient prestoClient = queryRunner.getClient();
        log.info("Loading data...");
        long startTime = System.nanoTime();
        for (TpchTable<?> table : tables) {
            loadTpchTopic(embeddedKafka, prestoClient, table);
        }
        log.info("Loading complete in %s", nanosSince(startTime).toString(SECONDS));
        return queryRunner;
    } catch (Throwable e) {
        closeAllSuppress(e, queryRunner, embeddedKafka);
        throw e;
    }
}
Also used : TestingPrestoClient(com.facebook.presto.tests.TestingPrestoClient) DistributedQueryRunner(com.facebook.presto.tests.DistributedQueryRunner) TpchPlugin(com.facebook.presto.tpch.TpchPlugin) SchemaTableName(com.facebook.presto.spi.SchemaTableName)

Example 44 with SchemaTableName

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

the class TestJmxSplitManager method testHistoryRecordSetProvider.

@Test
public void testHistoryRecordSetProvider() throws Exception {
    for (SchemaTableName schemaTableName : metadata.listTables(SESSION, HISTORY_SCHEMA_NAME)) {
        // wait for at least two samples
        List<Long> timeStamps = ImmutableList.of();
        for (int waited = 0; waited < TIMEOUT_TIME; waited += SLEEP_TIME) {
            RecordSet recordSet = getRecordSet(schemaTableName);
            timeStamps = readTimeStampsFrom(recordSet);
            if (timeStamps.size() >= 2) {
                break;
            }
            Thread.sleep(SLEEP_TIME);
        }
        assertTrue(timeStamps.size() >= 2);
        // we don't have equality check here because JmxHistoryDumper scheduling can lag
        assertTrue(timeStamps.get(1) - timeStamps.get(0) >= JMX_STATS_DUMP.toMillis());
    }
}
Also used : RecordSet(com.facebook.presto.spi.RecordSet) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Test(org.testng.annotations.Test)

Example 45 with SchemaTableName

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

the class KafkaConnectorFactory method create.

@Override
public Connector create(String connectorId, Map<String, String> config, ConnectorContext context) {
    requireNonNull(connectorId, "connectorId is null");
    requireNonNull(config, "config is null");
    try {
        Bootstrap app = new Bootstrap(new JsonModule(), new KafkaConnectorModule(), binder -> {
            binder.bind(KafkaConnectorId.class).toInstance(new KafkaConnectorId(connectorId));
            binder.bind(TypeManager.class).toInstance(context.getTypeManager());
            binder.bind(NodeManager.class).toInstance(context.getNodeManager());
            if (tableDescriptionSupplier.isPresent()) {
                binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KafkaTopicDescription>>>() {
                }).toInstance(tableDescriptionSupplier.get());
            } else {
                binder.bind(new TypeLiteral<Supplier<Map<SchemaTableName, KafkaTopicDescription>>>() {
                }).to(KafkaTableDescriptionSupplier.class).in(Scopes.SINGLETON);
            }
        });
        Injector injector = app.strictConfig().doNotInitializeLogging().setRequiredConfigurationProperties(config).initialize();
        return injector.getInstance(KafkaConnector.class);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : JsonModule(io.airlift.json.JsonModule) SchemaTableName(com.facebook.presto.spi.SchemaTableName) NodeManager(com.facebook.presto.spi.NodeManager) TypeLiteral(com.google.inject.TypeLiteral) Injector(com.google.inject.Injector) Bootstrap(io.airlift.bootstrap.Bootstrap) TypeManager(com.facebook.presto.spi.type.TypeManager) Supplier(java.util.function.Supplier) Map(java.util.Map)

Aggregations

SchemaTableName (com.facebook.presto.spi.SchemaTableName)159 ImmutableList (com.google.common.collect.ImmutableList)49 List (java.util.List)42 Test (org.testng.annotations.Test)40 TableNotFoundException (com.facebook.presto.spi.TableNotFoundException)35 ImmutableMap (com.google.common.collect.ImmutableMap)35 ConnectorTableMetadata (com.facebook.presto.spi.ConnectorTableMetadata)31 PrestoException (com.facebook.presto.spi.PrestoException)31 ColumnMetadata (com.facebook.presto.spi.ColumnMetadata)25 ConnectorMetadata (com.facebook.presto.spi.connector.ConnectorMetadata)19 ArrayList (java.util.ArrayList)19 Collectors.toList (java.util.stream.Collectors.toList)17 ConnectorSession (com.facebook.presto.spi.ConnectorSession)16 Map (java.util.Map)16 ColumnHandle (com.facebook.presto.spi.ColumnHandle)15 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)14 SchemaTablePrefix (com.facebook.presto.spi.SchemaTablePrefix)14 Optional (java.util.Optional)14 Table (com.facebook.presto.hive.metastore.Table)13 Path (org.apache.hadoop.fs.Path)12