use of org.apache.kudu.client.PartitionSchema.HashBucketSchema in project trino by trinodb.
the class KuduMetadata method getTableHandle.
@Override
public KuduTableHandle getTableHandle(ConnectorSession session, SchemaTableName schemaTableName) {
try {
KuduTable table = clientSession.openTable(schemaTableName);
OptionalInt bucketCount = OptionalInt.empty();
List<HashBucketSchema> bucketSchemas = table.getPartitionSchema().getHashBucketSchemas();
if (!bucketSchemas.isEmpty()) {
bucketCount = OptionalInt.of(bucketSchemas.stream().mapToInt(HashBucketSchema::getNumBuckets).reduce(1, Math::multiplyExact));
}
return new KuduTableHandle(schemaTableName, table, TupleDomain.all(), Optional.empty(), false, bucketCount, OptionalLong.empty());
} catch (NotFoundException e) {
return null;
}
}
use of org.apache.kudu.client.PartitionSchema.HashBucketSchema in project trino by trinodb.
the class KuduBucketFunction method getBucket.
@Override
public int getBucket(Page page, int position) {
checkArgument(this.bucketChannelTypes.size() == page.getChannelCount());
PartialRow partialRow = new PartialRow(this.schema);
List<Integer> bucketIds = this.hashBucketSchemas.stream().map(hashBucketSchema -> this.calculateSchemaLevelBucketId(page, partialRow, hashBucketSchema, position)).collect(toImmutableList());
return getBucket(bucketIds, hashBucketSchemas);
}
use of org.apache.kudu.client.PartitionSchema.HashBucketSchema in project trino by trinodb.
the class KuduClientSession method buildKuduSplits.
public List<KuduSplit> buildKuduSplits(KuduTableHandle tableHandle, DynamicFilter dynamicFilter) {
KuduTable table = tableHandle.getTable(this);
int primaryKeyColumnCount = table.getSchema().getPrimaryKeyColumnCount();
KuduScanToken.KuduScanTokenBuilder builder = client.newScanTokenBuilder(table);
// TODO: remove when kudu client bug is fixed: https://gerrit.cloudera.org/#/c/18166/
builder.includeTabletMetadata(false);
TupleDomain<ColumnHandle> constraint = tableHandle.getConstraint().intersect(dynamicFilter.getCurrentPredicate().simplify(100));
if (constraint.isNone()) {
return ImmutableList.of();
}
addConstraintPredicates(table, builder, constraint);
Optional<List<ColumnHandle>> desiredColumns = tableHandle.getDesiredColumns();
List<Integer> columnIndexes;
if (tableHandle.isDeleteHandle()) {
if (desiredColumns.isPresent()) {
columnIndexes = IntStream.range(0, primaryKeyColumnCount).boxed().collect(toList());
for (ColumnHandle column : desiredColumns.get()) {
KuduColumnHandle k = (KuduColumnHandle) column;
int index = k.getOrdinalPosition();
if (index >= primaryKeyColumnCount) {
columnIndexes.add(index);
}
}
columnIndexes = ImmutableList.copyOf(columnIndexes);
} else {
columnIndexes = IntStream.range(0, table.getSchema().getColumnCount()).boxed().collect(toImmutableList());
}
} else {
if (desiredColumns.isPresent()) {
columnIndexes = desiredColumns.get().stream().map(handle -> ((KuduColumnHandle) handle).getOrdinalPosition()).collect(toImmutableList());
} else {
ImmutableList.Builder<Integer> columnIndexesBuilder = ImmutableList.builder();
Schema schema = table.getSchema();
for (int ordinal = 0; ordinal < schema.getColumnCount(); ordinal++) {
ColumnSchema column = schema.getColumnByIndex(ordinal);
// Skip hidden "row_uuid" column
if (!column.isKey() || !column.getName().equals(KuduColumnHandle.ROW_ID)) {
columnIndexesBuilder.add(ordinal);
}
}
columnIndexes = columnIndexesBuilder.build();
}
}
builder.setProjectedColumnIndexes(columnIndexes);
tableHandle.getLimit().ifPresent(builder::limit);
List<KuduScanToken> tokens = builder.build();
ImmutableList.Builder<KuduSplit> tokenBuilder = ImmutableList.builder();
List<HashBucketSchema> hashBucketSchemas = table.getPartitionSchema().getHashBucketSchemas();
for (KuduScanToken token : tokens) {
List<Integer> hashBuckets = token.getTablet().getPartition().getHashBuckets();
int bucket = KuduBucketFunction.getBucket(hashBuckets, hashBucketSchemas);
tokenBuilder.add(toKuduSplit(tableHandle, token, primaryKeyColumnCount, bucket));
}
return tokenBuilder.build();
}
Aggregations