use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class PrometheusRecordSetProvider method getRecordSet.
@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
PrometheusSplit prometheusSplit = (PrometheusSplit) split;
ImmutableList.Builder<PrometheusColumnHandle> handles = ImmutableList.builder();
for (ColumnHandle handle : columns) {
handles.add((PrometheusColumnHandle) handle);
}
return new PrometheusRecordSet(prometheusClient, prometheusSplit, handles.build());
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class RedisMetadata method getColumnHandles.
@Override
public Map<String, ColumnHandle> getColumnHandles(ConnectorSession session, ConnectorTableHandle tableHandle) {
RedisTableHandle redisTableHandle = convertTableHandle(tableHandle);
RedisTableDescription redisTableDescription = getDefinedTables().get(redisTableHandle.toSchemaTableName());
if (redisTableDescription == null) {
throw new TableNotFoundException(redisTableHandle.toSchemaTableName());
}
ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
int index = 0;
RedisTableFieldGroup key = redisTableDescription.getKey();
if (key != null) {
List<RedisTableFieldDescription> fields = key.getFields();
if (fields != null) {
for (RedisTableFieldDescription field : fields) {
columnHandles.put(field.getName(), field.getColumnHandle(connectorId, true, index));
index++;
}
}
}
RedisTableFieldGroup value = redisTableDescription.getValue();
if (value != null) {
List<RedisTableFieldDescription> fields = value.getFields();
if (fields != null) {
for (RedisTableFieldDescription field : fields) {
columnHandles.put(field.getName(), field.getColumnHandle(connectorId, false, index));
index++;
}
}
}
for (RedisInternalFieldDescription field : RedisInternalFieldDescription.values()) {
columnHandles.put(field.getColumnName(), field.getColumnHandle(connectorId, index, hideInternalColumns));
index++;
}
return columnHandles.build();
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class RedisRecordSetProvider method getRecordSet.
@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
RedisSplit redisSplit = convertSplit(split);
List<RedisColumnHandle> redisColumns = columns.stream().map(RedisHandleResolver::convertColumnHandle).collect(ImmutableList.toImmutableList());
RowDecoder keyDecoder = decoderFactory.create(redisSplit.getKeyDataFormat(), emptyMap(), redisColumns.stream().filter(col -> !col.isInternal()).filter(RedisColumnHandle::isKeyDecoder).collect(toImmutableSet()));
RowDecoder valueDecoder = decoderFactory.create(redisSplit.getValueDataFormat(), emptyMap(), redisColumns.stream().filter(col -> !col.isInternal()).filter(col -> !col.isKeyDecoder()).collect(toImmutableSet()));
return new RedisRecordSet(redisSplit, jedisManager, redisColumns, keyDecoder, valueDecoder);
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class TpchIndexProvider method getIndex.
@Override
public ConnectorIndex getIndex(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorIndexHandle indexHandle, List<ColumnHandle> lookupSchema, List<ColumnHandle> outputSchema) {
TpchIndexHandle tpchIndexHandle = (TpchIndexHandle) indexHandle;
Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tpchIndexHandle.getFixedValues()).get();
checkArgument(lookupSchema.stream().noneMatch(handle -> fixedValues.keySet().contains(handle)), "Lookup columnHandles are not expected to overlap with the fixed value predicates");
// Establish an order for the fixedValues
List<ColumnHandle> fixedValueColumns = ImmutableList.copyOf(fixedValues.keySet());
// Extract the fixedValues as their raw values and types
List<Object> rawFixedValues = new ArrayList<>(fixedValueColumns.size());
List<Type> rawFixedTypes = new ArrayList<>(fixedValueColumns.size());
for (ColumnHandle fixedValueColumn : fixedValueColumns) {
rawFixedValues.add(fixedValues.get(fixedValueColumn).getValue());
rawFixedTypes.add(((TpchColumnHandle) fixedValueColumn).getType());
}
// Establish the schema after we append the fixed values to the lookup keys.
List<ColumnHandle> finalLookupSchema = ImmutableList.<ColumnHandle>builder().addAll(lookupSchema).addAll(fixedValueColumns).build();
Optional<TpchIndexedData.IndexedTable> indexedTable = indexedData.getIndexedTable(tpchIndexHandle.getTableName(), tpchIndexHandle.getScaleFactor(), tpchIndexHandle.getIndexColumnNames());
checkState(indexedTable.isPresent());
TpchIndexedData.IndexedTable table = indexedTable.get();
// Compute how to map from the final lookup schema to the table index key order
List<Integer> keyRemap = computeRemap(handleToNames(finalLookupSchema), table.getKeyColumns());
Function<RecordSet, RecordSet> keyFormatter = key -> new MappedRecordSet(new AppendingRecordSet(key, rawFixedValues, rawFixedTypes), keyRemap);
// Compute how to map from the output of the indexed data to the expected output schema
List<Integer> outputRemap = computeRemap(table.getOutputColumns(), handleToNames(outputSchema));
Function<RecordSet, RecordSet> outputFormatter = output -> new MappedRecordSet(output, outputRemap);
return new TpchConnectorIndex(keyFormatter, outputFormatter, table);
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class TpchIndexMetadata method resolveIndex.
@Override
public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle;
// Keep the fixed values that don't overlap with the indexableColumns
// Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now
Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()).entrySet().stream().filter(entry -> !indexableColumns.contains(entry.getKey())).filter(// strip nulls since meaningless in index join lookups
entry -> !entry.getValue().isNull()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// determine all columns available for index lookup
Set<String> lookupColumnNames = ImmutableSet.<String>builder().addAll(handleToNames(ImmutableList.copyOf(indexableColumns))).addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))).build();
// do we have an index?
if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) {
return Optional.empty();
}
TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain;
if (!tupleDomain.isNone()) {
filteredTupleDomain = TupleDomain.withColumnDomains(Maps.filterKeys(tupleDomain.getDomains().get(), not(in(fixedValues.keySet()))));
}
TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain));
}
Aggregations