use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class HivePartitionManager method parseValuesAndFilterPartition.
private Optional<Map<ColumnHandle, NullableValue>> parseValuesAndFilterPartition(String partitionName, List<HiveColumnHandle> partitionColumns, List<Type> partitionTypes, Constraint<ColumnHandle> constraint) {
List<String> partitionValues = extractPartitionKeyValues(partitionName);
Map<ColumnHandle, Domain> domains = constraint.getSummary().getDomains().get();
ImmutableMap.Builder<ColumnHandle, NullableValue> builder = ImmutableMap.builder();
for (int i = 0; i < partitionColumns.size(); i++) {
HiveColumnHandle column = partitionColumns.get(i);
NullableValue parsedValue = parsePartitionValue(partitionName, partitionValues.get(i), partitionTypes.get(i), timeZone);
Domain allowedDomain = domains.get(column);
if (allowedDomain != null && !allowedDomain.includesNullableValue(parsedValue.getValue())) {
return Optional.empty();
}
builder.put(column, parsedValue);
}
Map<ColumnHandle, NullableValue> values = builder.build();
if (!constraint.predicate().test(values)) {
return Optional.empty();
}
return Optional.of(values);
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class HivePartitionManager method toCompactTupleDomain.
private static TupleDomain<HiveColumnHandle> toCompactTupleDomain(TupleDomain<ColumnHandle> effectivePredicate, int threshold) {
checkArgument(effectivePredicate.getDomains().isPresent());
ImmutableMap.Builder<HiveColumnHandle, Domain> builder = ImmutableMap.builder();
for (Map.Entry<ColumnHandle, Domain> entry : effectivePredicate.getDomains().get().entrySet()) {
HiveColumnHandle hiveColumnHandle = (HiveColumnHandle) entry.getKey();
ValueSet values = entry.getValue().getValues();
ValueSet compactValueSet = values.getValuesProcessor().<Optional<ValueSet>>transform(ranges -> ranges.getRangeCount() > threshold ? Optional.of(ValueSet.ofRanges(ranges.getSpan())) : Optional.empty(), discreteValues -> discreteValues.getValues().size() > threshold ? Optional.of(ValueSet.all(values.getType())) : Optional.empty(), allOrNone -> Optional.empty()).orElse(values);
builder.put(hiveColumnHandle, Domain.create(compactValueSet, entry.getValue().isNullAllowed()));
}
return TupleDomain.withColumnDomains(builder.build());
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class HiveBucketing method getHiveBucket.
private static Optional<HiveBucket> getHiveBucket(Table table, Map<ColumnHandle, NullableValue> bindings) {
if (bindings.isEmpty()) {
return Optional.empty();
}
List<String> bucketColumns = table.getStorage().getBucketProperty().get().getBucketedBy();
Map<String, ObjectInspector> objectInspectors = new HashMap<>();
// Get column name to object inspector mapping
for (StructField field : getTableStructFields(table)) {
objectInspectors.put(field.getFieldName(), field.getFieldObjectInspector());
}
// Verify the bucket column types are supported
for (String column : bucketColumns) {
ObjectInspector inspector = objectInspectors.get(column);
if ((inspector == null) || (inspector.getCategory() != Category.PRIMITIVE)) {
return Optional.empty();
}
if (!SUPPORTED_TYPES.contains(((PrimitiveObjectInspector) inspector).getPrimitiveCategory())) {
return Optional.empty();
}
}
// Get bindings for bucket columns
Map<String, Object> bucketBindings = new HashMap<>();
for (Entry<ColumnHandle, NullableValue> entry : bindings.entrySet()) {
HiveColumnHandle colHandle = (HiveColumnHandle) entry.getKey();
if (!entry.getValue().isNull() && bucketColumns.contains(colHandle.getName())) {
bucketBindings.put(colHandle.getName(), entry.getValue().getValue());
}
}
// Check that we have bindings for all bucket columns
if (bucketBindings.size() != bucketColumns.size()) {
return Optional.empty();
}
// Get bindings of bucket columns
ImmutableList.Builder<Entry<ObjectInspector, Object>> columnBindings = ImmutableList.builder();
for (String column : bucketColumns) {
columnBindings.add(immutableEntry(objectInspectors.get(column), bucketBindings.get(column)));
}
return getHiveBucket(columnBindings.build(), table.getStorage().getBucketProperty().get().getBucketCount());
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class RenameColumnTask method execute.
@Override
public ListenableFuture<?> execute(RenameColumn statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, QueryStateMachine stateMachine, List<Expression> parameters) {
Session session = stateMachine.getSession();
QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTable());
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
String source = statement.getSource().toLowerCase(ENGLISH);
String target = statement.getTarget().toLowerCase(ENGLISH);
if (!tableHandle.isPresent()) {
throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
}
accessControl.checkCanRenameColumn(session.getRequiredTransactionId(), session.getIdentity(), tableName);
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableHandle.get());
if (!columnHandles.containsKey(source)) {
throw new SemanticException(MISSING_COLUMN, statement, "Column '%s' does not exist", source);
}
if (columnHandles.containsKey(target)) {
throw new SemanticException(COLUMN_ALREADY_EXISTS, statement, "Column '%s' already exists", target);
}
metadata.renameColumn(session, tableHandle.get(), columnHandles.get(source), target);
return immediateFuture(null);
}
use of com.facebook.presto.spi.ColumnHandle in project presto by prestodb.
the class InformationSchemaSplitManager method getSplits.
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
InformationSchemaTableLayoutHandle handle = (InformationSchemaTableLayoutHandle) layout;
Map<ColumnHandle, NullableValue> bindings = extractFixedValues(handle.getConstraint()).orElse(ImmutableMap.of());
List<HostAddress> localAddress = ImmutableList.of(nodeManager.getCurrentNode().getHostAndPort());
Map<String, NullableValue> filters = bindings.entrySet().stream().collect(toMap(entry -> ((InformationSchemaColumnHandle) entry.getKey()).getColumnName(), Entry::getValue));
ConnectorSplit split = new InformationSchemaSplit(handle.getTable(), filters, localAddress);
return new FixedSplitSource(ImmutableList.of(split));
}
Aggregations