use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.
the class HivePartitionManager method parsePartition.
public static HivePartition parsePartition(SchemaTableName tableName, String partitionName, List<HiveColumnHandle> partitionColumns, List<Type> partitionColumnTypes) {
List<String> partitionValues = extractPartitionValues(partitionName);
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), partitionColumnTypes.get(i));
builder.put(column, parsedValue);
}
Map<ColumnHandle, NullableValue> values = builder.build();
return new HivePartition(tableName, partitionName, values);
}
use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.
the class HiveBucketing method getHiveBucket.
private static OptionalInt getHiveBucket(Table table, Map<ColumnHandle, NullableValue> bindings) {
if (bindings.isEmpty()) {
return OptionalInt.empty();
}
List<String> bucketColumns = table.getStorage().getBucketProperty().get().getBucketedBy();
Map<String, HiveType> hiveTypes = new HashMap<>();
for (Column column : table.getDataColumns()) {
hiveTypes.put(column.getName(), column.getType());
}
// Verify the bucket column types are supported
for (String column : bucketColumns) {
if (!SUPPORTED_TYPES_FOR_BUCKET_FILTER.contains(hiveTypes.get(column))) {
return OptionalInt.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 OptionalInt.empty();
}
// Get bindings of bucket columns
ImmutableList.Builder<TypeInfo> typeInfos = ImmutableList.builder();
Object[] values = new Object[bucketColumns.size()];
for (int i = 0; i < bucketColumns.size(); i++) {
String column = bucketColumns.get(i);
typeInfos.add(hiveTypes.get(column).getTypeInfo());
values[i] = bucketBindings.get(column);
}
BucketingVersion bucketingVersion = getBucketingVersion(table);
return OptionalInt.of(getHiveBucket(bucketingVersion, table.getStorage().getBucketProperty().get().getBucketCount(), typeInfos.build(), values));
}
use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.
the class JmxSplitManager method getSplits.
@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy) {
JmxTableHandle tableHandle = (JmxTableHandle) table;
// TODO is there a better way to get the node column?
Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream().filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME)).findFirst();
checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME);
TupleDomain<ColumnHandle> nodeFilter = tableHandle.getNodeFilter();
List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
return nodeFilter.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
}).map(node -> new JmxSplit(ImmutableList.of(node.getHostAndPort()))).collect(toList());
return new FixedSplitSource(splits);
}
use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.
the class TestJmxMetadata method testApplyFilterWithConstraint.
@Test
public void testApplyFilterWithConstraint() {
JmxTableHandle handle = metadata.getTableHandle(SESSION, new SchemaTableName(JMX_SCHEMA_NAME, "java.lang:*"));
JmxColumnHandle nodeColumnHandle = new JmxColumnHandle("node", createUnboundedVarcharType());
NullableValue nodeColumnValue = NullableValue.of(createUnboundedVarcharType(), utf8Slice(localNode.getNodeIdentifier()));
JmxColumnHandle objectNameColumnHandle = new JmxColumnHandle("object_name", createUnboundedVarcharType());
NullableValue objectNameColumnValue = NullableValue.of(createUnboundedVarcharType(), utf8Slice("presto.memory:type=MemoryPool,name=reserved"));
TupleDomain<ColumnHandle> tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(nodeColumnHandle, nodeColumnValue, objectNameColumnHandle, objectNameColumnValue));
Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(SESSION, handle, new Constraint(tupleDomain));
assertTrue(result.isPresent());
assertEquals(result.get().getRemainingFilter(), TupleDomain.fromFixedValues(ImmutableMap.of(objectNameColumnHandle, objectNameColumnValue)));
assertEquals(((JmxTableHandle) result.get().getHandle()).getNodeFilter(), TupleDomain.fromFixedValues(ImmutableMap.of(nodeColumnHandle, nodeColumnValue)));
}
use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.
the class HiveSplitSource method matchesUserDefinedCachedPredicates.
/**
* Validate the partitions key against all the user defined predicates
* to determine whether or not that split should be cached.
*
* @return true if partition key matches the user defined cache predicates
* false otherwise
*/
private boolean matchesUserDefinedCachedPredicates(List<HivePartitionKey> partitionKeys) {
if (userDefinedCachePredicates == null || userDefinedCachePredicates.isEmpty() || partitionKeys == null || partitionKeys.isEmpty()) {
return false;
}
try {
Map<String, HivePartitionKey> hivePartitionKeyMap = partitionKeys.stream().collect(Collectors.toMap(HivePartitionKey::getName, Function.identity()));
for (TupleDomain<ColumnMetadata> tupleDomain : userDefinedCachePredicates) {
if (!tupleDomain.getDomains().isPresent()) {
continue;
}
Map<ColumnMetadata, Domain> domainMap = tupleDomain.getDomains().get();
Collection<String> columnsDefinedInPredicate = domainMap.keySet().stream().map(ColumnMetadata::getName).collect(Collectors.toList());
if (!hivePartitionKeyMap.keySet().containsAll(columnsDefinedInPredicate)) {
continue;
}
boolean allMatches = domainMap.entrySet().stream().allMatch(entry -> {
ColumnMetadata columnMetadata = entry.getKey();
Domain domain = entry.getValue();
String partitionStringValue = hivePartitionKeyMap.get(columnMetadata.getName()).getValue();
NullableValue nullableValue;
if (partitionStringValue.equals("\\N")) {
nullableValue = NullableValue.asNull(columnMetadata.getType());
} else {
nullableValue = HiveUtil.parsePartitionValue(columnMetadata.getName(), partitionStringValue, columnMetadata.getType());
}
return domain.includesNullableValue(nullableValue.getValue());
});
if (allMatches) {
return true;
}
}
} catch (Exception ex) {
log.warn(ex, "Unable to match partition keys %s with cached predicates. Ignoring this partition key. Error = %s", partitionKeys, ex.getMessage());
}
return false;
}
Aggregations