Search in sources :

Example 21 with Function

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

the class SymbolFormatterTest method testFormat.

@Test
public void testFormat() throws Exception {
    Function f = new Function(Signature.scalar("foo", DataTypes.STRING.getTypeSignature(), DataTypes.UNDEFINED.getTypeSignature(), DataTypes.DOUBLE.getTypeSignature()), List.of(Literal.of("bar"), Literal.of(3.4)), DataTypes.DOUBLE);
    assertThat(Symbols.format("This Symbol is formatted %s", f), is("This Symbol is formatted foo('bar', 3.4)"));
}
Also used : Function(io.crate.expression.symbol.Function) Test(org.junit.Test)

Example 22 with Function

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

the class RandomFunctionTest method normalizeReference.

@Test
public void normalizeReference() {
    Function function = new Function(random.signature(), Collections.emptyList(), DataTypes.DOUBLE);
    Function normalized = (Function) random.normalizeSymbol(function, txnCtx, sqlExpressions.nodeCtx);
    assertThat(normalized, sameInstance(function));
}
Also used : Function(io.crate.expression.symbol.Function) Test(org.junit.Test)

Example 23 with Function

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

the class RoutingBuilderTest method testAllocateRouting.

@Test
public void testAllocateRouting() {
    RoutingBuilder routingBuilder = new RoutingBuilder(clusterService.state(), routingProvider);
    WhereClause whereClause = new WhereClause(new Function(EqOperator.SIGNATURE, List.of(tableInfo.getReference(new ColumnIdent("id")), Literal.of(2)), EqOperator.RETURN_TYPE));
    routingBuilder.newAllocations();
    routingBuilder.allocateRouting(tableInfo, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, null);
    routingBuilder.allocateRouting(tableInfo, whereClause, RoutingProvider.ShardSelection.ANY, null);
    // 2 routing allocations with different where clause must result in 2 allocated routings
    List<Routing> tableRoutings = routingBuilder.routingListByTableStack.pop().get(relationName);
    assertThat(tableRoutings.size(), is(2));
    // The routings are the same because the RoutingProvider enforces this - this test doesn't reflect that fact
    // currently because the used routing are stubbed via the TestingTableInfo
    Routing routing1 = tableRoutings.get(0);
    Routing routing2 = tableRoutings.get(1);
    assertThat(routing1, is(routing2));
}
Also used : Function(io.crate.expression.symbol.Function) ColumnIdent(io.crate.metadata.ColumnIdent) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 24 with Function

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

the class ExpressionAnalyzerTest method testColumnsCanBeCastedWhenOnBothSidesOfOperator.

@Test
public void testColumnsCanBeCastedWhenOnBothSidesOfOperator() {
    Function symbol = (Function) executor.asSymbol("doc.t5.i < doc.t5.w");
    assertThat(symbol, isFunction(LtOperator.NAME));
    assertThat(symbol.arguments().get(0), isFunction(ImplicitCastFunction.NAME, List.of(DataTypes.INTEGER, DataTypes.STRING)));
    assertThat(symbol.arguments().get(1).valueType(), is(DataTypes.LONG));
}
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 25 with Function

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

the class ExpressionAnalyzerTest method testParameterSymbolCastsAreFlattened.

@Test
public void testParameterSymbolCastsAreFlattened() {
    Function comparisonFunction = (Function) executor.asSymbol("doc.t2.i = $1");
    assertThat(comparisonFunction.arguments().get(1), is(instanceOf(ParameterSymbol.class)));
    assertThat(comparisonFunction.arguments().get(1).valueType(), is(DataTypes.INTEGER));
}
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)

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