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());
}
}
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));
}
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));
}
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));
}
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));
}
Aggregations