public static FunctionCall getCall(CurrentUser node) { return new FunctionCall(QualifiedName.of("$current_user"), ImmutableList.of()); } }
public static Expression functionCall(String name, Expression... arguments) { return new FunctionCall(QualifiedName.of(name), ImmutableList.copyOf(arguments)); }
private static Expression getHashFunctionCall(Expression previousHashValue, Symbol symbol) { FunctionCall functionCall = new FunctionCall( QualifiedName.of(HASH_CODE), Optional.empty(), false, ImmutableList.of(symbol.toSymbolReference())); List<Expression> arguments = ImmutableList.of(previousHashValue, orNullHashCode(functionCall)); return new FunctionCall(QualifiedName.of("combine_hash"), arguments); }
@Test public void testShowTables() { assertStatement("SHOW TABLES", new ShowTables(Optional.empty(), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM a", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES FROM \"awesome schema\"", new ShowTables(Optional.of(QualifiedName.of("awesome schema")), Optional.empty(), Optional.empty())); assertStatement("SHOW TABLES IN a LIKE '%$_%' ESCAPE '$'", new ShowTables(Optional.of(QualifiedName.of("a")), Optional.of("%$_%"), Optional.of("$"))); }
@Test public void testQualifiedName() { assertEquals(QualifiedName.of("a", "b", "c", "d").toString(), "a.b.c.d"); assertEquals(QualifiedName.of("A", "b", "C", "d").toString(), "a.b.c.d"); assertTrue(QualifiedName.of("a", "b", "c", "d").hasSuffix(QualifiedName.of("b", "c", "d"))); assertTrue(QualifiedName.of("a", "b", "c", "d").hasSuffix(QualifiedName.of("a", "b", "c", "d"))); assertFalse(QualifiedName.of("a", "b", "c", "d").hasSuffix(QualifiedName.of("a", "c", "d"))); assertFalse(QualifiedName.of("a", "b", "c", "d").hasSuffix(QualifiedName.of("z", "a", "b", "c", "d"))); assertEquals(QualifiedName.of("a", "b", "c", "d"), QualifiedName.of("a", "b", "c", "d")); }
private static AggregationNode.Aggregation countWithFilter(Expression condition) { FunctionCall countCall = new FunctionCall( QualifiedName.of("count"), Optional.empty(), Optional.of(condition), Optional.empty(), false, ImmutableList.<Expression>of()); /* arguments */ return new AggregationNode.Aggregation( countCall, new Signature("count", FunctionKind.AGGREGATE, BIGINT.getTypeSignature()), Optional.<Symbol>empty()); /* mask */ }
@Test public void testShowGrants() { assertStatement("SHOW GRANTS ON TABLE t", new ShowGrants(true, Optional.of(QualifiedName.of("t")))); assertStatement("SHOW GRANTS ON t", new ShowGrants(false, Optional.of(QualifiedName.of("t")))); assertStatement("SHOW GRANTS", new ShowGrants(false, Optional.empty())); }
public static FunctionCall getCall(CurrentPath node) { return new FunctionCall(QualifiedName.of("$current_path"), ImmutableList.of()); } }
@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); }
public static Optional<Expression> getHashExpression(List<Symbol> symbols) { if (symbols.isEmpty()) { return Optional.empty(); } Expression result = new LongLiteral(String.valueOf(INITIAL_HASH_VALUE)); for (Symbol symbol : symbols) { Expression hashField = new FunctionCall( QualifiedName.of(HASH_CODE), Optional.empty(), false, ImmutableList.of(new SymbolReference(symbol.getName()))); hashField = new CoalesceExpression(hashField, new LongLiteral(String.valueOf(NULL_HASH_CODE))); result = new FunctionCall(QualifiedName.of("combine_hash"), ImmutableList.of(result, hashField)); } return Optional.of(result); }
private static FunctionCall fakeFunction() { return new FunctionCall(QualifiedName.of("test"), ImmutableList.of()); }
@Test public void testShowColumns() { assertStatement("SHOW COLUMNS FROM a", new ShowColumns(QualifiedName.of("a"))); assertStatement("SHOW COLUMNS FROM a.b", new ShowColumns(QualifiedName.of("a", "b"))); assertStatement("SHOW COLUMNS FROM \"awesome table\"", new ShowColumns(QualifiedName.of("awesome table"))); assertStatement("SHOW COLUMNS FROM \"awesome schema\".\"awesome table\"", new ShowColumns(QualifiedName.of("awesome schema", "awesome table"))); }
private static FunctionCall function(String name, Expression... inputs) { return new FunctionCall(QualifiedName.of(name), Arrays.asList(inputs)); }
private AggregationNode computeCounts(UnionNode sourceNode, List<Symbol> originalColumns, List<Symbol> markers, List<Symbol> aggregationOutputs) { ImmutableMap.Builder<Symbol, Aggregation> aggregations = ImmutableMap.builder(); for (int i = 0; i < markers.size(); i++) { Symbol output = aggregationOutputs.get(i); aggregations.put(output, new Aggregation( new FunctionCall(QualifiedName.of("count"), ImmutableList.of(markers.get(i).toSymbolReference())), COUNT_AGGREGATION, Optional.empty())); } return new AggregationNode(idAllocator.getNextId(), sourceNode, aggregations.build(), singleGroupingSet(originalColumns), ImmutableList.of(), Step.SINGLE, Optional.empty(), Optional.empty()); }