Search in sources :

Example 6 with FunctionImplementation

use of io.crate.metadata.FunctionImplementation in project crate by crate.

the class HyperLogLogDistinctAggregationTest method testReturnTypeIsAlwaysLong.

@Test
public void testReturnTypeIsAlwaysLong() {
    // Return type is fixed to Long
    FunctionImplementation func = nodeCtx.functions().get(null, HyperLogLogDistinctAggregation.NAME, List.of(Literal.of(1)), SearchPath.pathWithPGCatalogAndDoc());
    assertEquals(DataTypes.LONG, func.info().returnType());
    func = nodeCtx.functions().get(null, HyperLogLogDistinctAggregation.NAME, List.of(Literal.of(1), Literal.of(2)), SearchPath.pathWithPGCatalogAndDoc());
    assertEquals(DataTypes.LONG, func.info().returnType());
}
Also used : FunctionImplementation(io.crate.metadata.FunctionImplementation) Test(org.junit.Test)

Example 7 with FunctionImplementation

use of io.crate.metadata.FunctionImplementation in project crate by crate.

the class WindowAggProjectionSerialisationTest method test_window_agg_projection_serialization_with_filter_before_4_1_0.

@Test
public void test_window_agg_projection_serialization_with_filter_before_4_1_0() throws IOException {
    FunctionImplementation sumFunctionImpl = getSumFunction();
    WindowDefinition partitionByOneWindowDef = new WindowDefinition(singletonList(Literal.of(1L)), null, null);
    WindowFunction windowFunction = new WindowFunction(sumFunctionImpl.signature(), singletonList(Literal.of(2L)), sumFunctionImpl.boundSignature().getReturnType().createType(), null, partitionByOneWindowDef, null);
    Symbol standaloneInput = Literal.of(42L);
    var windowAggProjection = new WindowAggProjection(partitionByOneWindowDef, List.of(windowFunction), List.of(standaloneInput));
    var output = new BytesStreamOutput();
    output.setVersion(Version.V_4_0_0);
    windowAggProjection.writeTo(output);
    var input = output.bytes().streamInput();
    input.setVersion(Version.V_4_0_0);
    var actualWindowAggProjection = new WindowAggProjection(input);
    assertThat(actualWindowAggProjection.outputs(), contains(standaloneInput, windowFunction));
    assertThat(actualWindowAggProjection.windowFunctions().get(0).filter(), Matchers.nullValue());
}
Also used : WindowFunction(io.crate.expression.symbol.WindowFunction) Symbol(io.crate.expression.symbol.Symbol) FunctionImplementation(io.crate.metadata.FunctionImplementation) WindowDefinition(io.crate.analyze.WindowDefinition) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Example 8 with FunctionImplementation

use of io.crate.metadata.FunctionImplementation in project crate by crate.

the class InputFactoryTest method testCompiled.

@Test
public void testCompiled() throws Exception {
    Function function = (Function) expressions.normalize(expressions.asSymbol("a like 'f%'"));
    InputFactory.Context<Input<?>> ctx = factory.ctxForRefs(txnCtx, i -> Literal.of("foo"));
    Input<?> input = ctx.add(function);
    FunctionExpression expression = (FunctionExpression) input;
    java.lang.reflect.Field f = FunctionExpression.class.getDeclaredField("scalar");
    f.setAccessible(true);
    FunctionImplementation impl = (FunctionImplementation) f.get(expression);
    assertThat(impl.signature(), is(function.signature()));
    FunctionImplementation uncompiled = expressions.nodeCtx.functions().getQualified(function, txnCtx.sessionSettings().searchPath());
    assertThat(uncompiled, not(sameInstance(impl)));
}
Also used : Function(io.crate.expression.symbol.Function) Input(io.crate.data.Input) FunctionImplementation(io.crate.metadata.FunctionImplementation) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 9 with FunctionImplementation

use of io.crate.metadata.FunctionImplementation in project crate by crate.

the class HandlerSideLevelCollectTest method testInformationSchemaTables.

@Test
public void testInformationSchemaTables() throws Exception {
    InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
    TableInfo tablesTableInfo = schemaInfo.getTableInfo("tables");
    Routing routing = tablesTableInfo.getRouting(clusterService().state(), routingProvider, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
    List<Symbol> toCollect = new ArrayList<>();
    for (Reference reference : tablesTableInfo.columns()) {
        toCollect.add(reference);
    }
    Symbol tableNameRef = toCollect.get(12);
    List<Symbol> arguments = Arrays.asList(tableNameRef, Literal.of("shards"));
    FunctionImplementation eqImpl = functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
    Function whereClause = new Function(eqImpl.signature(), arguments, EqOperator.RETURN_TYPE);
    RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC, new WhereClause(whereClause));
    Bucket result = collect(collectNode);
    assertThat(TestingHelpers.printedTable(result), is("NULL| NULL| NULL| strict| NULL| NULL| NULL| SYSTEM GENERATED| NULL| NULL| NULL| sys| shards| sys| BASE TABLE| NULL\n"));
}
Also used : Function(io.crate.expression.symbol.Function) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) Symbol(io.crate.expression.symbol.Symbol) Reference(io.crate.metadata.Reference) ArrayList(java.util.ArrayList) WhereClause(io.crate.analyze.WhereClause) Routing(io.crate.metadata.Routing) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) FunctionImplementation(io.crate.metadata.FunctionImplementation) RoutedCollectPhase(io.crate.execution.dsl.phases.RoutedCollectPhase) Test(org.junit.Test)

Example 10 with FunctionImplementation

use of io.crate.metadata.FunctionImplementation in project crate by crate.

the class GeometricMeanAggregationtest method test_functions_return_type_is_always_double_for_any_argument_type.

@Test
public void test_functions_return_type_is_always_double_for_any_argument_type() {
    for (DataType<?> type : Stream.concat(DataTypes.NUMERIC_PRIMITIVE_TYPES.stream(), Stream.of(DataTypes.TIMESTAMPZ)).collect(Collectors.toList())) {
        FunctionImplementation stddev = nodeCtx.functions().get(null, GeometricMeanAggregation.NAME, List.of(Literal.of(type, null)), SearchPath.pathWithPGCatalogAndDoc());
        assertThat(stddev.boundSignature().getReturnType().createType(), is(DataTypes.DOUBLE));
    }
}
Also used : FunctionImplementation(io.crate.metadata.FunctionImplementation) Test(org.junit.Test)

Aggregations

FunctionImplementation (io.crate.metadata.FunctionImplementation)21 Symbol (io.crate.expression.symbol.Symbol)11 Test (org.junit.Test)11 Input (io.crate.data.Input)9 Function (io.crate.expression.symbol.Function)6 Literal (io.crate.expression.symbol.Literal)5 List (java.util.List)5 TransactionContext (io.crate.metadata.TransactionContext)4 Map (java.util.Map)4 Lists2 (io.crate.common.collections.Lists2)3 ArrayFunction (io.crate.expression.scalar.arithmetic.ArrayFunction)3 ArrayList (java.util.ArrayList)3 OrderBy (io.crate.analyze.OrderBy)2 ParamTypeHints (io.crate.analyze.ParamTypeHints)2 WindowDefinition (io.crate.analyze.WindowDefinition)2 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)2 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)2 Function (io.crate.analyze.symbol.Function)2 Literal (io.crate.analyze.symbol.Literal)2 RamAccounting (io.crate.breaker.RamAccounting)2