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();
}
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()));
}
}
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;
}
}
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());
}
}
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);
}
}
Aggregations