Search in sources :

Example 1 with PinotException

use of com.facebook.presto.pinot.PinotException in project presto by prestodb.

the class TestPinotExpressionConverters method testAggregationProjectUnsupported.

private void testAggregationProjectUnsupported(String sqlExpression, SessionHolder sessionHolder) {
    try {
        RowExpression pushDownExpression = getRowExpression(sqlExpression, sessionHolder);
        String actualPinotExpression = pushDownExpression.accept(new PinotAggregationProjectConverter(functionAndTypeManager, functionAndTypeManager, standardFunctionResolution, sessionHolder.getConnectorSession()), testInput).getDefinition();
        fail("expected to not reach here: Generated " + actualPinotExpression);
    } catch (PinotException e) {
        assertEquals(e.getErrorCode(), PINOT_UNSUPPORTED_EXPRESSION.toErrorCode());
    }
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 2 with PinotException

use of com.facebook.presto.pinot.PinotException in project presto by prestodb.

the class PinotFilterExpressionConverter method handleDateAndTimestampMagicLiteralFunction.

private PinotExpression handleDateAndTimestampMagicLiteralFunction(CallExpression timestamp, Function<VariableReferenceExpression, Selection> context) {
    if (timestamp.getArguments().size() == 1) {
        RowExpression input = timestamp.getArguments().get(0);
        Type expectedType = timestamp.getType();
        if (typeManager.canCoerce(input.getType(), expectedType) || input.getType() == BigintType.BIGINT || input.getType() == IntegerType.INTEGER) {
            return input.accept(this, context);
        }
        throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Non implicit Date/Timestamp Literal is not supported: " + timestamp);
    }
    throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("The Date/Timestamp Literal is not supported. Received: %s", timestamp));
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) IntegerType(com.facebook.presto.common.type.IntegerType) Type(com.facebook.presto.common.type.Type) BigintType(com.facebook.presto.common.type.BigintType) VarcharType(com.facebook.presto.common.type.VarcharType) OperatorType(com.facebook.presto.common.function.OperatorType) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) DateType(com.facebook.presto.common.type.DateType) TimestampType(com.facebook.presto.common.type.TimestampType) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 3 with PinotException

use of com.facebook.presto.pinot.PinotException in project presto by prestodb.

the class PinotFilterExpressionConverter method handleCast.

private PinotExpression handleCast(CallExpression cast, Function<VariableReferenceExpression, Selection> context) {
    if (cast.getArguments().size() == 1) {
        RowExpression input = cast.getArguments().get(0);
        Type expectedType = cast.getType();
        if (typeManager.canCoerce(input.getType(), expectedType)) {
            return input.accept(this, context);
        }
        // `TIMESTAMP` type is cast correctly to milliseconds value.
        if (expectedType == DateType.DATE) {
            try {
                PinotExpression expression = input.accept(this, context);
                if (input.getType() == TimestampType.TIMESTAMP || input.getType() == TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) {
                    return expression;
                }
                // It converts ISO DateTime to daysSinceEpoch value so Pinot could understand this.
                if (input.getType() == VarcharType.VARCHAR) {
                    // Remove the leading & trailing quote then parse
                    Integer daysSinceEpoch = (int) TimeUnit.MILLISECONDS.toDays(DATE_FORMATTER.parseMillis(expression.getDefinition().substring(1, expression.getDefinition().length() - 1)));
                    return new PinotExpression(daysSinceEpoch.toString(), expression.getOrigin());
                }
            } catch (Exception e) {
                throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Cast date value expression is not supported: " + cast);
            }
        }
        throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Non implicit casts not supported: " + cast);
    }
    throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("This type of CAST operator not supported. Received: %s", cast));
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) IntegerType(com.facebook.presto.common.type.IntegerType) Type(com.facebook.presto.common.type.Type) BigintType(com.facebook.presto.common.type.BigintType) VarcharType(com.facebook.presto.common.type.VarcharType) OperatorType(com.facebook.presto.common.function.OperatorType) TimestampWithTimeZoneType(com.facebook.presto.common.type.TimestampWithTimeZoneType) DateType(com.facebook.presto.common.type.DateType) TimestampType(com.facebook.presto.common.type.TimestampType) RowExpression(com.facebook.presto.spi.relation.RowExpression) PinotException(com.facebook.presto.pinot.PinotException)

Example 4 with PinotException

use of com.facebook.presto.pinot.PinotException in project presto by prestodb.

the class PinotFilterExpressionConverter method handleBetween.

private PinotExpression handleBetween(CallExpression between, Function<VariableReferenceExpression, Selection> context) {
    if (between.getArguments().size() == 3) {
        RowExpression value = between.getArguments().get(0);
        RowExpression min = between.getArguments().get(1);
        RowExpression max = between.getArguments().get(2);
        return derived(format("(%s BETWEEN %s AND %s)", value.accept(this, context).getDefinition(), min.accept(this, context).getDefinition(), max.accept(this, context).getDefinition()));
    }
    throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("Between operator not supported: %s", between));
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 5 with PinotException

use of com.facebook.presto.pinot.PinotException in project presto by prestodb.

the class PinotAggregationProjectConverter method handleArithmeticExpression.

private PinotExpression handleArithmeticExpression(CallExpression expression, OperatorType operatorType, Map<VariableReferenceExpression, PinotQueryGeneratorContext.Selection> context) {
    List<RowExpression> arguments = expression.getArguments();
    if (arguments.size() == 1) {
        String prefix = operatorType == OperatorType.NEGATION ? "-" : "";
        return derived(prefix + arguments.get(0).accept(this, context).getDefinition());
    }
    if (arguments.size() == 2) {
        PinotExpression left = arguments.get(0).accept(this, context);
        PinotExpression right = arguments.get(1).accept(this, context);
        String prestoOperator = operatorType.getOperator();
        String pinotOperator = PRESTO_TO_PINOT_OPERATORS.get(prestoOperator);
        if (pinotOperator == null) {
            throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Unsupported binary expression " + prestoOperator);
        }
        return derived(format("%s(%s, %s)", pinotOperator, left.getDefinition(), right.getDefinition()));
    }
    throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("Don't know how to interpret %s as an arithmetic expression", expression));
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) RowExpression(com.facebook.presto.spi.relation.RowExpression) PinotPushdownUtils.getLiteralAsString(com.facebook.presto.pinot.PinotPushdownUtils.getLiteralAsString)

Aggregations

PinotException (com.facebook.presto.pinot.PinotException)17 RowExpression (com.facebook.presto.spi.relation.RowExpression)10 OperatorType (com.facebook.presto.common.function.OperatorType)5 PinotPushdownUtils.getLiteralAsString (com.facebook.presto.pinot.PinotPushdownUtils.getLiteralAsString)5 Type (com.facebook.presto.common.type.Type)4 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)4 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)4 SortOrder (com.facebook.presto.common.block.SortOrder)3 BigintType (com.facebook.presto.common.type.BigintType)3 DateType (com.facebook.presto.common.type.DateType)3 IntegerType (com.facebook.presto.common.type.IntegerType)3 PinotColumnHandle (com.facebook.presto.pinot.PinotColumnHandle)3 PinotConfig (com.facebook.presto.pinot.PinotConfig)3 PINOT_QUERY_GENERATOR_FAILURE (com.facebook.presto.pinot.PinotErrorCode.PINOT_QUERY_GENERATOR_FAILURE)3 PINOT_UNSUPPORTED_EXPRESSION (com.facebook.presto.pinot.PinotErrorCode.PINOT_UNSUPPORTED_EXPRESSION)3 PINOT_DISTINCT_COUNT_FUNCTION_NAME (com.facebook.presto.pinot.PinotPushdownUtils.PINOT_DISTINCT_COUNT_FUNCTION_NAME)3 PinotPushdownUtils.checkSupported (com.facebook.presto.pinot.PinotPushdownUtils.checkSupported)3 PinotSessionProperties (com.facebook.presto.pinot.PinotSessionProperties)3 ConnectorSession (com.facebook.presto.spi.ConnectorSession)3 CallExpression (com.facebook.presto.spi.relation.CallExpression)3