use of io.crate.analyze.symbol.Function in project crate by crate.
the class ExpressionAnalyzerTest method testAnalyzeSubscriptFunctionCall.
@Test
public void testAnalyzeSubscriptFunctionCall() throws Exception {
// Test when use subscript function is used explicitly then it's handled (and validated)
// the same way it's handled when the subscript operator `[]` is used
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, new SessionContext(0, EnumSet.of(Option.ALLOW_QUOTED_SUBSCRIPT), null), paramTypeHints, new FullQualifedNameFieldProvider(dummySources), null);
ExpressionAnalysisContext expressionAnalysisContext = new ExpressionAnalysisContext();
FunctionCall subscriptFunctionCall = new FunctionCall(new QualifiedName("subscript"), ImmutableList.of(new ArrayLiteral(ImmutableList.of(new StringLiteral("obj"))), new LongLiteral("1")));
Function function = (Function) expressionAnalyzer.convert(subscriptFunctionCall, expressionAnalysisContext);
assertEquals("subscript(_array(Literal{obj, type=string}),Literal{1, type=integer})", function.toString());
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class ExpressionAnalyzerTest method testNonDeterministicFunctionsAlwaysNew.
@Test
public void testNonDeterministicFunctionsAlwaysNew() throws Exception {
ExpressionAnalysisContext localContext = new ExpressionAnalysisContext();
FunctionInfo info1 = new FunctionInfo(new FunctionIdent("inc", Collections.singletonList(DataTypes.BOOLEAN)), DataTypes.INTEGER, FunctionInfo.Type.SCALAR, FunctionInfo.NO_FEATURES);
Function fn1 = localContext.allocateFunction(info1, Collections.singletonList(Literal.BOOLEAN_FALSE));
Function fn2 = localContext.allocateFunction(info1, Collections.singletonList(Literal.BOOLEAN_FALSE));
Function fn3 = localContext.allocateFunction(info1, Collections.singletonList(Literal.BOOLEAN_TRUE));
// different instances
assertThat(fn1, allOf(not(sameInstance(fn2)), not(sameInstance(fn3))));
// but equal
assertThat(fn1, is(equalTo(fn2)));
assertThat(fn1, is(not(equalTo(fn3))));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class UpdateAnalyzerTest method testUsingFQColumnNameShouldBePossibleInWhereClause.
@Test
public void testUsingFQColumnNameShouldBePossibleInWhereClause() throws Exception {
UpdateAnalyzedStatement statement = analyze("update users set name = 'foo' where users.name != 'foo'");
Function eqFunction = (Function) ((Function) statement.nestedStatements().get(0).whereClause().query()).arguments().get(0);
assertThat(eqFunction.arguments().get(0), isReference("name"));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class InputCreatingVisitorTest method testNonDeterministicFunctionsReplacement.
@Test
public void testNonDeterministicFunctionsReplacement() throws Exception {
SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
Function fn1 = (Function) sqlExpressions.asSymbol("random()");
Function fn2 = (Function) sqlExpressions.asSymbol("random()");
List<Symbol> inputSymbols = Arrays.<Symbol>asList(Literal.BOOLEAN_FALSE, sqlExpressions.asSymbol("upper(a)"), fn1, fn2);
Function newSameFn = (Function) sqlExpressions.asSymbol("random()");
Function newDifferentFn = (Function) sqlExpressions.asSymbol("random()");
InputCreatingVisitor.Context context = new InputCreatingVisitor.Context(inputSymbols);
Symbol replaced1 = InputCreatingVisitor.INSTANCE.process(fn1, context);
assertThat(replaced1, is(instanceOf(InputColumn.class)));
assertThat(((InputColumn) replaced1).index(), is(2));
Symbol replaced2 = InputCreatingVisitor.INSTANCE.process(fn2, context);
assertThat(replaced2, is(instanceOf(InputColumn.class)));
assertThat(((InputColumn) replaced2).index(), is(3));
Symbol replaced3 = InputCreatingVisitor.INSTANCE.process(newSameFn, context);
// not replaced
assertThat(replaced3, is(equalTo((Symbol) newSameFn)));
Symbol replaced4 = InputCreatingVisitor.INSTANCE.process(newDifferentFn, context);
// not replaced
assertThat(replaced4, is(equalTo((Symbol) newDifferentFn)));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class QueriedDocTableFetchPushDownTest method testPushDownOrderRefUsedInFunction.
@Test
public void testPushDownOrderRefUsedInFunction() throws Exception {
QuerySpec qs = new QuerySpec();
Function funcOfI = abs(REF_I);
qs.outputs(Lists.newArrayList(REF_A, REF_I, funcOfI));
qs.orderBy(new OrderBy(Lists.newArrayList(REF_I), new boolean[] { true }, new Boolean[] { false }));
QueriedDocTableFetchPushDown pd = new QueriedDocTableFetchPushDown(new QueriedDocTable(TABLE_REL, qs));
QueriedDocTable sub = pd.pushDown();
assertThat(qs, isSQL("SELECT FETCH(INPUT(0), s.t._doc['a']), INPUT(1), abs(INPUT(1)) ORDER BY INPUT(1) DESC NULLS LAST"));
assertThat(sub.querySpec(), isSQL("SELECT s.t._fetchid, s.t.i ORDER BY s.t.i DESC NULLS LAST"));
}
Aggregations