use of com.facebook.presto.metadata.OperatorNotFoundException in project presto by prestodb.
the class InformationSchemaPageSourceProvider method buildPartitions.
private InternalTable buildPartitions(Session session, String catalogName, Map<String, NullableValue> filters) {
QualifiedObjectName tableName = extractQualifiedTableName(catalogName, filters);
InternalTable.Builder table = InternalTable.builder(informationSchemaTableColumns(TABLE_INTERNAL_PARTITIONS));
Optional<TableHandle> tableHandle = metadata.getTableHandle(session, tableName);
if (!tableHandle.isPresent()) {
throw new TableNotFoundException(tableName.asSchemaTableName());
}
List<TableLayoutResult> layouts = metadata.getLayouts(session, tableHandle.get(), Constraint.alwaysTrue(), Optional.empty());
if (layouts.size() == 1) {
Map<ColumnHandle, String> columnHandles = ImmutableBiMap.copyOf(metadata.getColumnHandles(session, tableHandle.get())).inverse();
Map<ColumnHandle, MethodHandle> methodHandles = new HashMap<>();
for (ColumnHandle columnHandle : columnHandles.keySet()) {
try {
ColumnMetadata columnMetadata = metadata.getColumnMetadata(session, tableHandle.get(), columnHandle);
Signature operator = metadata.getFunctionRegistry().getCoercion(columnMetadata.getType(), createUnboundedVarcharType());
MethodHandle methodHandle = metadata.getFunctionRegistry().getScalarFunctionImplementation(operator).getMethodHandle();
methodHandles.put(columnHandle, methodHandle);
} catch (OperatorNotFoundException exception) {
// Do not put the columnHandle in the map.
}
}
TableLayout layout = Iterables.getOnlyElement(layouts).getLayout();
layout.getDiscretePredicates().ifPresent(predicates -> {
int partitionNumber = 1;
for (TupleDomain<ColumnHandle> domain : predicates.getPredicates()) {
for (Entry<ColumnHandle, NullableValue> entry : TupleDomain.extractFixedValues(domain).get().entrySet()) {
ColumnHandle columnHandle = entry.getKey();
String columnName = columnHandles.get(columnHandle);
String value = null;
if (entry.getValue().getValue() != null) {
if (methodHandles.containsKey(columnHandle)) {
try {
value = ((Slice) methodHandles.get(columnHandle).invokeWithArguments(entry.getValue().getValue())).toStringUtf8();
} catch (Throwable throwable) {
throw Throwables.propagate(throwable);
}
} else {
value = "<UNREPRESENTABLE VALUE>";
}
}
table.add(catalogName, tableName.getSchemaName(), tableName.getObjectName(), partitionNumber, columnName, value);
}
partitionNumber++;
}
});
}
return table.build();
}
Aggregations