Search in sources :

Example 6 with NullableValue

use of com.facebook.presto.spi.predicate.NullableValue 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));
}
Also used : ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) HostAddress(com.facebook.presto.spi.HostAddress) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) List(java.util.List) InternalNodeManager(com.facebook.presto.metadata.InternalNodeManager) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toMap(java.util.stream.Collectors.toMap) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TupleDomain.extractFixedValues(com.facebook.presto.spi.predicate.TupleDomain.extractFixedValues) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Entry(java.util.Map.Entry) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ColumnHandle(com.facebook.presto.spi.ColumnHandle) NullableValue(com.facebook.presto.spi.predicate.NullableValue) HostAddress(com.facebook.presto.spi.HostAddress) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 7 with NullableValue

use of com.facebook.presto.spi.predicate.NullableValue in project presto by prestodb.

the class InformationSchemaPageSourceProvider method getInternalTable.

private InternalTable getInternalTable(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, ConnectorSplit connectorSplit, List<ColumnHandle> columns) {
    InformationSchemaTransactionHandle transaction = (InformationSchemaTransactionHandle) transactionHandle;
    InformationSchemaSplit split = (InformationSchemaSplit) connectorSplit;
    requireNonNull(columns, "columns is null");
    InformationSchemaTableHandle handle = split.getTableHandle();
    Map<String, NullableValue> filters = split.getFilters();
    Session session = Session.builder(metadata.getSessionPropertyManager()).setTransactionId(transaction.getTransactionId()).setQueryId(new QueryId(connectorSession.getQueryId())).setIdentity(connectorSession.getIdentity()).setSource("information_schema").setCatalog(// default catalog is not be used
    "").setSchema(// default schema is not be used
    "").setTimeZoneKey(connectorSession.getTimeZoneKey()).setLocale(connectorSession.getLocale()).setStartTime(connectorSession.getStartTime()).build();
    return getInformationSchemaTable(session, handle.getCatalogName(), handle.getSchemaTableName(), filters);
}
Also used : QueryId(com.facebook.presto.spi.QueryId) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Session(com.facebook.presto.Session)

Example 8 with NullableValue

use of com.facebook.presto.spi.predicate.NullableValue 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();
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) OperatorNotFoundException(com.facebook.presto.metadata.OperatorNotFoundException) HashMap(java.util.HashMap) NullableValue(com.facebook.presto.spi.predicate.NullableValue) TableLayoutResult(com.facebook.presto.metadata.TableLayoutResult) InternalTable(com.facebook.presto.metadata.InternalTable) QualifiedObjectName(com.facebook.presto.metadata.QualifiedObjectName) Constraint(com.facebook.presto.spi.Constraint) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Signature(com.facebook.presto.metadata.Signature) TableHandle(com.facebook.presto.metadata.TableHandle) TableLayout(com.facebook.presto.metadata.TableLayout) MethodHandle(java.lang.invoke.MethodHandle)

Example 9 with NullableValue

use of com.facebook.presto.spi.predicate.NullableValue in project presto by prestodb.

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout) {
    JmxTableLayoutHandle jmxLayout = (JmxTableLayoutHandle) layout;
    JmxTableHandle tableHandle = jmxLayout.getTable();
    TupleDomain<ColumnHandle> predicate = jmxLayout.getConstraint();
    //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);
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return predicate.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(tableHandle, ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NodeManager(com.facebook.presto.spi.NodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain.fromFixedValues(com.facebook.presto.spi.predicate.TupleDomain.fromFixedValues) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Inject(javax.inject.Inject) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) List(java.util.List) NODE_COLUMN_NAME(com.facebook.presto.connector.jmx.JmxMetadata.NODE_COLUMN_NAME) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ColumnHandle(com.facebook.presto.spi.ColumnHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) NullableValue(com.facebook.presto.spi.predicate.NullableValue) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Aggregations

NullableValue (com.facebook.presto.spi.predicate.NullableValue)9 ColumnHandle (com.facebook.presto.spi.ColumnHandle)7 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ConnectorSession (com.facebook.presto.spi.ConnectorSession)3 Constraint (com.facebook.presto.spi.Constraint)3 TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Optional (java.util.Optional)3 ConnectorSplit (com.facebook.presto.spi.ConnectorSplit)2 ConnectorSplitSource (com.facebook.presto.spi.ConnectorSplitSource)2 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)2 FixedSplitSource (com.facebook.presto.spi.FixedSplitSource)2 Domain (com.facebook.presto.spi.predicate.Domain)2 Type (com.facebook.presto.spi.type.Type)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 ProtectMode.getProtectModeFromString (org.apache.hadoop.hive.metastore.ProtectMode.getProtectModeFromString)2