use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.
the class TestSqlParser method testPosition.
@Test
public void testPosition() throws Exception {
assertExpression("position('a' in 'b')", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
assertExpression("position('a' in ('b'))", new FunctionCall(QualifiedName.of("strpos"), ImmutableList.of(new StringLiteral("b"), new StringLiteral("a"))));
}
use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.
the class TestSqlParser method testSetSession.
@Test
public void testSetSession() throws Exception {
assertStatement("SET SESSION foo = 'bar'", new SetSession(QualifiedName.of("foo"), new StringLiteral("bar")));
assertStatement("SET SESSION foo.bar = 'baz'", new SetSession(QualifiedName.of("foo", "bar"), new StringLiteral("baz")));
assertStatement("SET SESSION foo.bar.boo = 'baz'", new SetSession(QualifiedName.of("foo", "bar", "boo"), new StringLiteral("baz")));
assertStatement("SET SESSION foo.bar = 'ban' || 'ana'", new SetSession(QualifiedName.of("foo", "bar"), new FunctionCall(QualifiedName.of("concat"), ImmutableList.of(new StringLiteral("ban"), new StringLiteral("ana")))));
}
use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.
the class TestWindowNode method testSerializationRoundtrip.
@Test
public void testSerializationRoundtrip() throws Exception {
Symbol windowSymbol = symbolAllocator.newSymbol("sum", BIGINT);
Signature signature = new Signature("sum", FunctionKind.WINDOW, ImmutableList.of(), ImmutableList.of(), BIGINT.getTypeSignature(), ImmutableList.of(BIGINT.getTypeSignature()), false);
FunctionCall functionCall = new FunctionCall(QualifiedName.of("sum"), ImmutableList.of(columnC.toSymbolReference()));
WindowNode.Frame frame = new WindowNode.Frame(WindowFrame.Type.RANGE, FrameBound.Type.UNBOUNDED_PRECEDING, Optional.empty(), FrameBound.Type.UNBOUNDED_FOLLOWING, Optional.empty());
PlanNodeId id = newId();
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(columnA), ImmutableList.of(columnB), ImmutableMap.of(columnB, SortOrder.ASC_NULLS_FIRST));
Map<Symbol, WindowNode.Function> functions = ImmutableMap.of(windowSymbol, new WindowNode.Function(functionCall, signature, frame));
Optional<Symbol> hashSymbol = Optional.of(columnB);
Set<Symbol> prePartitionedInputs = ImmutableSet.of(columnA);
WindowNode windowNode = new WindowNode(id, sourceNode, specification, functions, hashSymbol, prePartitionedInputs, 0);
String json = objectMapper.writeValueAsString(windowNode);
WindowNode actualNode = objectMapper.readValue(json, WindowNode.class);
assertEquals(actualNode.getId(), windowNode.getId());
assertEquals(actualNode.getSpecification(), windowNode.getSpecification());
assertEquals(actualNode.getWindowFunctions(), windowNode.getWindowFunctions());
assertEquals(actualNode.getFrames(), windowNode.getFrames());
assertEquals(actualNode.getHashSymbol(), windowNode.getHashSymbol());
assertEquals(actualNode.getPrePartitionedInputs(), windowNode.getPrePartitionedInputs());
assertEquals(actualNode.getPreSortedOrderPrefix(), windowNode.getPreSortedOrderPrefix());
}
use of com.facebook.presto.sql.tree.FunctionCall in project presto by prestodb.
the class WindowFunctionMatcher method getAssignedSymbol.
@Override
public Optional<Symbol> getAssignedSymbol(PlanNode node, Session session, Metadata metadata, SymbolAliases symbolAliases) {
Optional<Symbol> result = Optional.empty();
if (!(node instanceof WindowNode)) {
return result;
}
WindowNode windowNode = (WindowNode) node;
FunctionCall expectedCall = callMaker.getExpectedValue(symbolAliases);
for (Map.Entry<Symbol, WindowNode.Function> assignment : windowNode.getWindowFunctions().entrySet()) {
if (expectedCall.equals(assignment.getValue().getFunctionCall())) {
checkState(!result.isPresent(), "Ambiguous function calls in %s", windowNode);
result = Optional.of(assignment.getKey());
}
}
return result;
}
Aggregations