use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestInCodeGenerator method testInteger.
@Test
public void testInteger() {
FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
List<RowExpression> values = new ArrayList<>();
values.add(constant((long) Integer.MIN_VALUE, INTEGER));
values.add(constant((long) Integer.MAX_VALUE, INTEGER));
values.add(constant(3L, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(constant(null, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(new CallExpression(CAST.name(), functionAndTypeManager.lookupCast(CAST, DOUBLE.getTypeSignature(), INTEGER.getTypeSignature()), INTEGER, Collections.singletonList(constant(12345678901234.0, DOUBLE))));
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
for (int i = 6; i <= 32; ++i) {
values.add(constant((long) i, INTEGER));
}
assertEquals(checkSwitchGenerationCase(INTEGER, values), DIRECT_SWITCH);
values.add(constant(33L, INTEGER));
assertEquals(checkSwitchGenerationCase(INTEGER, values), SET_CONTAINS);
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class DruidAggregationProjectConverter method handleDateTruncationViaDateTruncation.
private DruidExpression handleDateTruncationViaDateTruncation(CallExpression function, Map<VariableReferenceExpression, DruidQueryGeneratorContext.Selection> context) {
RowExpression timeInputParameter = function.getArguments().get(1);
String inputColumn;
String inputTimeZone;
String inputFormat;
CallExpression timeConversion = getExpressionAsFunction(timeInputParameter, timeInputParameter);
if (!timeConversion.getDisplayName().toLowerCase(ENGLISH).equals(FROM_UNIXTIME)) {
throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Unsupported time function: " + timeConversion.getDisplayName() + " to pushdown for Druid connector.");
}
inputColumn = timeConversion.getArguments().get(0).accept(this, context).getDefinition();
inputTimeZone = timeConversion.getArguments().size() > 1 ? getStringFromConstant(timeConversion.getArguments().get(1)) : DateTimeZone.UTC.getID();
inputFormat = "seconds";
RowExpression intervalParameter = function.getArguments().get(0);
if (!(intervalParameter instanceof ConstantExpression)) {
throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Unsupported interval unit: " + intervalParameter + " to pushdown for Druid connector.");
}
return derived("dateTrunc(" + inputColumn + "," + inputFormat + ", " + inputTimeZone + ", " + getStringFromConstant(intervalParameter) + ")");
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class DruidPushdownUtils method handlePushDownSingleDistinctCount.
/**
* Try to push down query like: `SELECT count(distinct $COLUMN) FROM myTable` to Druid as `SELECT distinctCount($COLUMN) FROM myTable`.
* This function only handles the case of an AggregationNode (COUNT on $COLUMN) on top of an AggregationNode(of non-aggregate on $COLUMN).
*
* @return true if push down successfully otherwise false.
*/
private static boolean handlePushDownSingleDistinctCount(ImmutableList.Builder<DruidAggregationColumnNode> nodeBuilder, AggregationNode aggregationNode, VariableReferenceExpression outputColumn, AggregationNode.Aggregation aggregation) {
if (!aggregation.getCall().getDisplayName().equalsIgnoreCase(COUNT_FUNCTION_NAME)) {
return false;
}
List<RowExpression> arguments = aggregation.getCall().getArguments();
if (arguments.size() != 1) {
return false;
}
RowExpression aggregationArgument = arguments.get(0);
// Handle the case of Count Aggregation on top of a Non-Agg GroupBy Aggregation.
if (!(aggregationNode.getSource() instanceof AggregationNode)) {
return false;
}
AggregationNode sourceAggregationNode = (AggregationNode) aggregationNode.getSource();
Set<String> sourceAggregationGroupSet = getGroupKeys(sourceAggregationNode.getGroupingKeys());
Set<String> aggregationGroupSet = getGroupKeys(aggregationNode.getGroupingKeys());
aggregationGroupSet.add(aggregationArgument.toString());
if (!sourceAggregationGroupSet.containsAll(aggregationGroupSet) && aggregationGroupSet.containsAll(sourceAggregationGroupSet)) {
return false;
}
nodeBuilder.add(new AggregationFunctionColumnNode(outputColumn, new CallExpression(aggregation.getCall().getSourceLocation(), DRUID_COUNT_DISTINCT_FUNCTION_NAME, aggregation.getFunctionHandle(), aggregation.getCall().getType(), ImmutableList.of(aggregationArgument))));
return true;
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class PageFunctionCompiler method compileProjectionInternal.
private Supplier<PageProjection> compileProjectionInternal(SqlFunctionProperties sqlFunctionProperties, Map<SqlFunctionId, SqlInvokedFunction> sessionFunctions, List<RowExpression> projections, boolean isOptimizeCommonSubExpression, Optional<String> classNameSuffix) {
requireNonNull(projections, "projections is null");
checkArgument(!projections.isEmpty() && projections.stream().allMatch(projection -> projection instanceof CallExpression || projection instanceof SpecialFormExpression));
PageFieldsToInputParametersRewriter.Result result = rewritePageFieldsToInputParameters(projections);
List<RowExpression> rewrittenExpression = result.getRewrittenExpressions();
CallSiteBinder callSiteBinder = new CallSiteBinder();
// generate Work
ClassDefinition pageProjectionWorkDefinition = definePageProjectWorkClass(sqlFunctionProperties, sessionFunctions, rewrittenExpression, callSiteBinder, isOptimizeCommonSubExpression, classNameSuffix);
Class<? extends Work> pageProjectionWorkClass;
try {
pageProjectionWorkClass = defineClass(pageProjectionWorkDefinition, Work.class, callSiteBinder.getBindings(), getClass().getClassLoader());
} catch (PrestoException prestoException) {
throw prestoException;
} catch (Exception e) {
throw new PrestoException(COMPILER_ERROR, e);
}
return () -> new GeneratedPageProjection(rewrittenExpression, rewrittenExpression.stream().allMatch(determinismEvaluator::isDeterministic), result.getInputChannels(), constructorMethodHandle(pageProjectionWorkClass, List.class, SqlFunctionProperties.class, Page.class, SelectedPositions.class));
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class LambdaBytecodeGenerator method variableReferenceCompiler.
private static RowExpressionVisitor<BytecodeNode, Scope> variableReferenceCompiler(Map<String, ParameterAndType> parameterMap) {
return new RowExpressionVisitor<BytecodeNode, Scope>() {
@Override
public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) {
throw new UnsupportedOperationException();
}
@Override
public BytecodeNode visitCall(CallExpression call, Scope scope) {
throw new UnsupportedOperationException();
}
@Override
public BytecodeNode visitConstant(ConstantExpression literal, Scope scope) {
throw new UnsupportedOperationException();
}
@Override
public BytecodeNode visitLambda(LambdaDefinitionExpression lambda, Scope context) {
throw new UnsupportedOperationException();
}
@Override
public BytecodeNode visitVariableReference(VariableReferenceExpression reference, Scope context) {
ParameterAndType parameterAndType = parameterMap.get(reference.getName());
Parameter parameter = parameterAndType.getParameter();
Class<?> type = parameterAndType.getType();
return new BytecodeBlock().append(parameter).append(unboxPrimitiveIfNecessary(context, type));
}
@Override
public BytecodeNode visitSpecialForm(SpecialFormExpression specialForm, Scope context) {
throw new UnsupportedOperationException();
}
};
}
Aggregations