public static FunctionCall getCall(CurrentPath node) { return new FunctionCall(QualifiedName.of("$current_path"), ImmutableList.of()); } }
public static FunctionCall getCall(CurrentUser node) { return new FunctionCall(QualifiedName.of("$current_user"), ImmutableList.of()); } }
private ColumnStatisticsAggregation createAggregation(QualifiedName functionName, SymbolReference input, Type inputType, Type outputType) { Signature signature = metadata.getFunctionRegistry().resolveFunction(functionName, TypeSignatureProvider.fromTypes(ImmutableList.of(inputType))); Type resolvedType = metadata.getType(getOnlyElement(signature.getArgumentTypes())); verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType); return new ColumnStatisticsAggregation( new AggregationNode.Aggregation( new FunctionCall(functionName, ImmutableList.of(input)), signature, Optional.empty()), outputType); }
private ColumnStatisticsAggregation createAggregation(QualifiedName functionName, SymbolReference input, Type inputType, Type outputType) { Signature signature = metadata.getFunctionRegistry().resolveFunction(functionName, TypeSignatureProvider.fromTypes(ImmutableList.of(inputType))); Type resolvedType = metadata.getType(getOnlyElement(signature.getArgumentTypes())); verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType); return new ColumnStatisticsAggregation( new AggregationNode.Aggregation( new FunctionCall(functionName, ImmutableList.of(input)), signature, Optional.empty()), outputType); }
private WindowNode.Function newWindowNodeFunction(String functionName, Optional<Window> window, String... symbols) { return new WindowNode.Function( new FunctionCall( QualifiedName.of(functionName), window, false, Arrays.stream(symbols).map(SymbolReference::new).collect(Collectors.toList())), signature, frame); } }
@Override public Expression rewriteTryExpression(TryExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Expression expression = treeRewriter.rewrite(node.getInnerExpression(), context); return new FunctionCall( QualifiedName.of("$internal$try"), ImmutableList.of(new LambdaExpression(ImmutableList.of(), expression))); } }
private WindowNode.Function newWindowNodeFunction(String functionName, Optional<Window> window, String... symbols) { return new WindowNode.Function( new FunctionCall( QualifiedName.of(functionName), window, false, Arrays.stream(symbols).map(SymbolReference::new).collect(Collectors.toList())), signature, frame); } }
@Override public Expression rewriteTryExpression(TryExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter) { Expression expression = treeRewriter.rewrite(node.getInnerExpression(), context); return new FunctionCall( QualifiedName.of("$internal$try"), ImmutableList.of(new LambdaExpression(ImmutableList.of(), expression))); } }
@Override public Result apply(SampleNode sample, Captures captures, Context context) { return Result.ofPlanNode(new FilterNode( sample.getId(), sample.getSource(), new ComparisonExpression( ComparisonExpression.Operator.LESS_THAN, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()), new DoubleLiteral(Double.toString(sample.getSampleRatio()))))); } }
private WindowNode.Function newWindowNodeFunction(String functionName, String... symbols) { return new WindowNode.Function( new FunctionCall( QualifiedName.of(functionName), Arrays.stream(symbols).map(SymbolReference::new).collect(Collectors.toList())), signature, frame); }
@Override public Node visitPosition(SqlBaseParser.PositionContext context) { List<Expression> arguments = Lists.reverse(visit(context.valueExpression(), Expression.class)); return new FunctionCall(getLocation(context), QualifiedName.of("strpos"), arguments); }
@Override public Node visitConcatenation(SqlBaseParser.ConcatenationContext context) { return new FunctionCall( getLocation(context.CONCAT()), QualifiedName.of("concat"), ImmutableList.of( (Expression) visit(context.left), (Expression) visit(context.right))); }
@Override public Node visitConcatenation(SqlBaseParser.ConcatenationContext context) { return new FunctionCall( getLocation(context.CONCAT()), QualifiedName.of("concat"), ImmutableList.of( (Expression) visit(context.left), (Expression) visit(context.right))); }
@Override public Node visitSubstring(SqlBaseParser.SubstringContext context) { return new FunctionCall(getLocation(context), QualifiedName.of("substr"), visit(context.valueExpression(), Expression.class)); }
@Test public void testSetSessionWithParameters() { List<Expression> expressionList = new ArrayList<>(); expressionList.add(new StringLiteral("ban")); expressionList.add(new Parameter(0)); testSetSessionWithParameters("bar", new FunctionCall(QualifiedName.of("concat"), expressionList), "banana", ImmutableList.of(new StringLiteral("ana"))); }
@Test public void testSetSessionWithParameters() { List<Expression> expressionList = new ArrayList<>(); expressionList.add(new StringLiteral("ban")); expressionList.add(new Parameter(0)); testSetSessionWithParameters("bar", new FunctionCall(QualifiedName.of("concat"), expressionList), "banana", ImmutableList.of(new StringLiteral("ana"))); }
@Test public void doesNotFireOnPlanWithSingleWindowNode() { tester().assertThat(new GatherAndMergeWindows.SwapAdjacentWindowsBySpecifications(0)) .on(p -> p.window(new WindowNode.Specification( ImmutableList.of(p.symbol("a")), Optional.empty()), ImmutableMap.of(p.symbol("avg_1"), new WindowNode.Function(new FunctionCall(QualifiedName.of("avg"), ImmutableList.of()), signature, frame)), p.values(p.symbol("a")))) .doesNotFire(); }
@Test public void testSetSession() { testSetSession(new StringLiteral("baz"), "baz"); testSetSession(new FunctionCall(QualifiedName.of("concat"), ImmutableList.of( new StringLiteral("ban"), new StringLiteral("ana"))), "banana"); }
@Test public void testFilter() { PlanNode node = filter(baseTableScan, and( greaterThan(AE, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of())), lessThan(BE, bigintLiteral(10)))); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Non-deterministic functions should be purged assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, bigintLiteral(10)))); }
@Test public void testFilter() { PlanNode node = filter(baseTableScan, and( greaterThan(AE, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of())), lessThan(BE, bigintLiteral(10)))); Expression effectivePredicate = effectivePredicateExtractor.extract(node); // Non-deterministic functions should be purged assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(lessThan(BE, bigintLiteral(10)))); }