Search in sources :

Example 1 with PINOT_UNSUPPORTED_EXPRESSION

use of com.facebook.presto.pinot.PinotErrorCode.PINOT_UNSUPPORTED_EXPRESSION in project presto by prestodb.

the class PinotQueryGeneratorContext method getIndicesMappingFromPinotSchemaToPrestoSchema.

private List<Integer> getIndicesMappingFromPinotSchemaToPrestoSchema(String query, Map<VariableReferenceExpression, PinotColumnHandle> assignments) {
    LinkedHashMap<VariableReferenceExpression, Selection> expressionsInPinotOrder = new LinkedHashMap<>();
    for (VariableReferenceExpression groupByColumn : groupByColumns) {
        Selection groupByColumnDefinition = selections.get(groupByColumn);
        if (groupByColumnDefinition == null) {
            throw new IllegalStateException(format("Group By column (%s) definition not found in input selections: %s", groupByColumn, Joiner.on(",").withKeyValueSeparator(":").join(selections)));
        }
        expressionsInPinotOrder.put(groupByColumn, groupByColumnDefinition);
    }
    for (VariableReferenceExpression outputColumn : outputs) {
        Selection outputColumnDefinition = selections.get(outputColumn);
        if (outputColumnDefinition == null) {
            throw new IllegalStateException(format("Output column (%s) definition not found in input selections: %s", outputColumn, Joiner.on(",").withKeyValueSeparator(":").join(selections)));
        }
        expressionsInPinotOrder.put(outputColumn, outputColumnDefinition);
    }
    if (useSqlSyntax) {
        checkSupported(assignments.size() <= expressionsInPinotOrder.keySet().stream().filter(key -> !hiddenColumnSet.contains(key)).count(), "Expected returned expressions %s is a superset of selections %s", Joiner.on(",").withKeyValueSeparator(":").join(expressionsInPinotOrder), Joiner.on(",").withKeyValueSeparator("=").join(assignments));
    } else {
        checkSupported(assignments.size() == expressionsInPinotOrder.keySet().stream().filter(key -> !hiddenColumnSet.contains(key)).count(), "Expected returned expressions %s to match selections %s", Joiner.on(",").withKeyValueSeparator(":").join(expressionsInPinotOrder), Joiner.on(",").withKeyValueSeparator("=").join(assignments));
    }
    Map<VariableReferenceExpression, Integer> assignmentToIndex = new HashMap<>();
    Iterator<Map.Entry<VariableReferenceExpression, PinotColumnHandle>> assignmentsIterator = assignments.entrySet().iterator();
    for (int i = 0; i < assignments.size(); i++) {
        VariableReferenceExpression key = assignmentsIterator.next().getKey();
        Integer previous = assignmentToIndex.put(key, i);
        if (previous != null) {
            throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.of(query), format("Expected Pinot column handle %s to occur only once, but we have: %s", key, Joiner.on(",").withKeyValueSeparator("=").join(assignments)));
        }
    }
    ImmutableList.Builder<Integer> outputIndices = ImmutableList.builder();
    for (Map.Entry<VariableReferenceExpression, Selection> expression : expressionsInPinotOrder.entrySet()) {
        Integer index;
        if (hiddenColumnSet.contains(expression.getKey())) {
            // negative output index means to skip this value returned by pinot at query time
            index = -1;
        } else {
            index = assignmentToIndex.get(expression.getKey());
        }
        if (index == null) {
            if (useSqlSyntax) {
                // negative output index means to skip this value returned by pinot at query time
                index = -1;
            } else {
                throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.of(query), format("Expected to find a Pinot column handle for the expression %s, but we have %s", expression, Joiner.on(",").withKeyValueSeparator(":").join(assignmentToIndex)));
            }
        }
        outputIndices.add(index);
    }
    return outputIndices.build();
}
Also used : PinotPushdownUtils.checkSupported(com.facebook.presto.pinot.PinotPushdownUtils.checkSupported) PinotException(com.facebook.presto.pinot.PinotException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) PINOT_DISTINCT_COUNT_FUNCTION_NAME(com.facebook.presto.pinot.PinotPushdownUtils.PINOT_DISTINCT_COUNT_FUNCTION_NAME) OptionalInt(java.util.OptionalInt) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) Locale(java.util.Locale) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) StrictMath.toIntExact(java.lang.StrictMath.toIntExact) LinkedHashSet(java.util.LinkedHashSet) PinotColumnHandle(com.facebook.presto.pinot.PinotColumnHandle) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) SortOrder(com.facebook.presto.common.block.SortOrder) Set(java.util.Set) Collectors(java.util.stream.Collectors) PinotSessionProperties(com.facebook.presto.pinot.PinotSessionProperties) String.format(java.lang.String.format) ConnectorSession(com.facebook.presto.spi.ConnectorSession) List(java.util.List) PinotConfig(com.facebook.presto.pinot.PinotConfig) PINOT_QUERY_GENERATOR_FAILURE(com.facebook.presto.pinot.PinotErrorCode.PINOT_QUERY_GENERATOR_FAILURE) PINOT_UNSUPPORTED_EXPRESSION(com.facebook.presto.pinot.PinotErrorCode.PINOT_UNSUPPORTED_EXPRESSION) Optional(java.util.Optional) Joiner(com.google.common.base.Joiner) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) PinotException(com.facebook.presto.pinot.PinotException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) LinkedHashMap(java.util.LinkedHashMap) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

SortOrder (com.facebook.presto.common.block.SortOrder)1 PinotColumnHandle (com.facebook.presto.pinot.PinotColumnHandle)1 PinotConfig (com.facebook.presto.pinot.PinotConfig)1 PINOT_QUERY_GENERATOR_FAILURE (com.facebook.presto.pinot.PinotErrorCode.PINOT_QUERY_GENERATOR_FAILURE)1 PINOT_UNSUPPORTED_EXPRESSION (com.facebook.presto.pinot.PinotErrorCode.PINOT_UNSUPPORTED_EXPRESSION)1 PinotException (com.facebook.presto.pinot.PinotException)1 PINOT_DISTINCT_COUNT_FUNCTION_NAME (com.facebook.presto.pinot.PinotPushdownUtils.PINOT_DISTINCT_COUNT_FUNCTION_NAME)1 PinotPushdownUtils.checkSupported (com.facebook.presto.pinot.PinotPushdownUtils.checkSupported)1 PinotSessionProperties (com.facebook.presto.pinot.PinotSessionProperties)1 ConnectorSession (com.facebook.presto.spi.ConnectorSession)1 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)1 Joiner (com.google.common.base.Joiner)1 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 StrictMath.toIntExact (java.lang.StrictMath.toIntExact)1 String.format (java.lang.String.format)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1