Search in sources :

Example 71 with Function

use of io.crate.expression.symbol.Function in project crate by crate.

the class ExpressionAnalyzerTest method testSwapFunctionLeftSide.

@Test
public void testSwapFunctionLeftSide() throws Exception {
    Function cmp = (Function) expressions.normalize(executor.asSymbol("8 + 5 > t1.x"));
    // the comparison was swapped so the field is on the left side
    assertThat(cmp.name(), is("op_<"));
    assertThat(cmp.arguments().get(0), isReference("x"));
}
Also used : CoalesceFunction(io.crate.expression.scalar.conditional.CoalesceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) ArraySliceFunction(io.crate.expression.scalar.ArraySliceFunction) ImplicitCastFunction(io.crate.expression.scalar.cast.ImplicitCastFunction) Function(io.crate.expression.symbol.Function) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 72 with Function

use of io.crate.expression.symbol.Function in project crate by crate.

the class ExpressionAnalyzerTest method testColumnsAreCastedToLiteralType.

@Test
public void testColumnsAreCastedToLiteralType() {
    Function symbol = (Function) executor.asSymbol("doc.t2.i = 1.1");
    assertThat(symbol, isSQL("(_cast(doc.t2.i, 'double precision') = 1.1)"));
}
Also used : CoalesceFunction(io.crate.expression.scalar.conditional.CoalesceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) ArraySliceFunction(io.crate.expression.scalar.ArraySliceFunction) ImplicitCastFunction(io.crate.expression.scalar.cast.ImplicitCastFunction) Function(io.crate.expression.symbol.Function) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 73 with Function

use of io.crate.expression.symbol.Function in project crate by crate.

the class CommonQueryBuilderTest method test_eq_on_alias_uses_termquery.

@Test
public void test_eq_on_alias_uses_termquery() throws Exception {
    // Testing expression: col as alias = 'foo'
    AliasSymbol alias = new AliasSymbol("aliased", createReference("name", DataTypes.STRING));
    var literal = Literal.of("foo");
    var func = new Function(EqOperator.SIGNATURE, List.of(alias, literal), DataTypes.BOOLEAN);
    Query query = queryTester.toQuery(func);
    assertThat(query, instanceOf(TermQuery.class));
}
Also used : Function(io.crate.expression.symbol.Function) TermQuery(org.apache.lucene.search.TermQuery) AliasSymbol(io.crate.expression.symbol.AliasSymbol) CrateRegexQuery(io.crate.lucene.match.CrateRegexQuery) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) RegexpQuery(org.apache.lucene.search.RegexpQuery) PointInSetQuery(org.apache.lucene.search.PointInSetQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) IntersectsPrefixTreeQuery(org.apache.lucene.spatial.prefix.IntersectsPrefixTreeQuery) PointRangeQuery(org.apache.lucene.search.PointRangeQuery) TermInSetQuery(org.apache.lucene.search.TermInSetQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DocValuesFieldExistsQuery(org.apache.lucene.search.DocValuesFieldExistsQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) Test(org.junit.Test)

Example 74 with Function

use of io.crate.expression.symbol.Function in project crate by crate.

the class SimplifyEqualsOperationOnIdenticalReferencesTest method testSimplifyRefEqRefWhenRefIsNullableWithParent.

@Test
public void testSimplifyRefEqRefWhenRefIsNullableWithParent() {
    Function functionToOptimize = new Function(EqOperator.SIGNATURE, List.of(NULLABLE_REF, NULLABLE_REF), DataTypes.BOOLEAN);
    Function dummyParent = new Function(NotPredicate.SIGNATURE, List.of(functionToOptimize), DataTypes.BOOLEAN);
    Match<Function> match = RULE.pattern().accept(functionToOptimize, Captures.empty());
    assertTrue(match.isPresent());
    Symbol optimizedFunction = RULE.apply(match.value(), match.captures(), NODE_CONTEXT, dummyParent);
    assertThat(optimizedFunction, is(nullValue()));
}
Also used : Function(io.crate.expression.symbol.Function) Ignore3vlFunction(io.crate.expression.scalar.Ignore3vlFunction) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test)

Example 75 with Function

use of io.crate.expression.symbol.Function in project crate by crate.

the class SimplifyEqualsOperationOnIdenticalReferencesTest method testSimplifyRefEqRefWhenRefIsNullableWithNoParent.

@Test
public void testSimplifyRefEqRefWhenRefIsNullableWithNoParent() {
    Function functionToOptimize = new Function(EqOperator.SIGNATURE, List.of(NULLABLE_REF, NULLABLE_REF), DataTypes.BOOLEAN);
    Match<Function> match = RULE.pattern().accept(functionToOptimize, Captures.empty());
    assertTrue(match.isPresent());
    Symbol optimizedFunction = RULE.apply(match.value(), match.captures(), NODE_CONTEXT, null);
    Symbol expected = new Function(NotPredicate.SIGNATURE, List.of(new Function(IsNullPredicate.SIGNATURE, List.of(NULLABLE_REF), DataTypes.BOOLEAN)), DataTypes.BOOLEAN);
    assertThat(optimizedFunction, is(expected));
}
Also used : Function(io.crate.expression.symbol.Function) Ignore3vlFunction(io.crate.expression.scalar.Ignore3vlFunction) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test)

Aggregations

Function (io.crate.expression.symbol.Function)80 Test (org.junit.Test)56 Symbol (io.crate.expression.symbol.Symbol)43 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)43 SymbolMatchers.isFunction (io.crate.testing.SymbolMatchers.isFunction)35 SubscriptFunction (io.crate.expression.scalar.SubscriptFunction)25 TryCastFunction (io.crate.expression.scalar.cast.TryCastFunction)24 ExplicitCastFunction (io.crate.expression.scalar.cast.ExplicitCastFunction)23 DistanceFunction (io.crate.expression.scalar.geo.DistanceFunction)23 AliasSymbol (io.crate.expression.symbol.AliasSymbol)13 ParameterSymbol (io.crate.expression.symbol.ParameterSymbol)13 SelectSymbol (io.crate.expression.symbol.SelectSymbol)13 InputColumn (io.crate.expression.symbol.InputColumn)10 ArrayList (java.util.ArrayList)10 Literal (io.crate.expression.symbol.Literal)9 ArraySliceFunction (io.crate.expression.scalar.ArraySliceFunction)8 FunctionImplementation (io.crate.metadata.FunctionImplementation)8 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)7 ScopedSymbol (io.crate.expression.symbol.ScopedSymbol)6 Reference (io.crate.metadata.Reference)6