Search in sources :

Example 11 with FunctionIdent

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

the class StdDevAggregationTest method testReturnType.

@Test
public void testReturnType() throws Exception {
    for (DataType<?> type : Iterables.concat(DataTypes.NUMERIC_PRIMITIVE_TYPES, Arrays.asList(DataTypes.TIMESTAMP))) {
        FunctionIdent fi = new FunctionIdent("stddev", ImmutableList.<DataType>of(type));
        // Return type is fixed to Double
        assertEquals(DataTypes.DOUBLE, functions.get(fi).info().returnType());
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) AggregationTest(io.crate.operation.aggregation.AggregationTest) Test(org.junit.Test)

Example 12 with FunctionIdent

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

the class PercentileAggregation method register.

public static void register(AggregationImplModule mod) {
    for (DataType<?> t : DataTypes.NUMERIC_PRIMITIVE_TYPES) {
        mod.register(new PercentileAggregation(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.<DataType>of(t, DataTypes.DOUBLE)), DataTypes.DOUBLE, FunctionInfo.Type.AGGREGATE)));
        mod.register(new PercentileAggregation(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(t, DataTypes.DOUBLE_ARRAY)), DataTypes.DOUBLE_ARRAY, FunctionInfo.Type.AGGREGATE)));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo) DataType(io.crate.types.DataType)

Example 13 with FunctionIdent

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

the class GroupingBytesRefCollectorBenchmark method createGroupByMinBytesRefCollector.

private GroupingCollector createGroupByMinBytesRefCollector(Functions functions) {
    InputCollectExpression keyInput = new InputCollectExpression(0);
    List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
    CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
    FunctionIdent minBytesRefFuncIdent = new FunctionIdent(MinimumAggregation.NAME, Arrays.asList(DataTypes.STRING));
    FunctionInfo minBytesRefFuncInfo = new FunctionInfo(minBytesRefFuncIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
    AggregationFunction minAgg = (AggregationFunction) functions.get(minBytesRefFuncIdent);
    Aggregation aggregation = Aggregation.finalAggregation(minBytesRefFuncInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
    Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, minAgg, new Input[] { keyInput }) };
    return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.STRING);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) Aggregation(io.crate.analyze.symbol.Aggregation) MinimumAggregation(io.crate.operation.aggregation.impl.MinimumAggregation) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) InputColumn(io.crate.analyze.symbol.InputColumn) FunctionInfo(io.crate.metadata.FunctionInfo) Aggregator(io.crate.operation.aggregation.Aggregator) CollectExpression(io.crate.operation.collect.CollectExpression) InputCollectExpression(io.crate.operation.collect.InputCollectExpression)

Example 14 with FunctionIdent

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

the class FunctionTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    Function fn = new Function(new FunctionInfo(new FunctionIdent(randomAsciiOfLength(10), ImmutableList.of(DataTypes.BOOLEAN)), TestingHelpers.randomPrimitiveType(), FunctionInfo.Type.SCALAR, randomFeatures()), Collections.singletonList(TestingHelpers.createReference(randomAsciiOfLength(2), DataTypes.BOOLEAN)));
    BytesStreamOutput output = new BytesStreamOutput();
    Symbols.toStream(fn, output);
    StreamInput input = StreamInput.wrap(output.bytes());
    Function fn2 = (Function) Symbols.fromStream(input);
    assertThat(fn, is(equalTo(fn2)));
    assertThat(fn.hashCode(), is(fn2.hashCode()));
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) StreamInput(org.elasticsearch.common.io.stream.StreamInput) FunctionInfo(io.crate.metadata.FunctionInfo) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 15 with FunctionIdent

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

the class SimpleTopNProjectorTest method testFunctionExpression.

@Test
public void testFunctionExpression() throws Throwable {
    Scalar floor = (Scalar) TestingHelpers.getFunctions().get(new FunctionIdent("floor", Collections.<DataType>singletonList(DataTypes.DOUBLE)));
    FunctionExpression<Number, ?> funcExpr = new FunctionExpression<>(floor, new Input[] { input });
    Projector projector = new SimpleTopNProjector(ImmutableList.<Input<?>>of(funcExpr), COLLECT_EXPRESSIONS, 10, TopN.NO_OFFSET);
    Iterable<Row> rows = RowGenerator.fromSingleColValues(() -> IntStream.range(0, 12).mapToDouble(i -> 42.3d).iterator());
    BatchIterator batchIterator = projector.apply(RowsBatchIterator.newInstance(rows, 1));
    consumer.accept(batchIterator, null);
    Bucket result = consumer.getBucket();
    assertThat(result.size(), is(10));
    assertThat(result.iterator().next(), isRow(42L));
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) FunctionExpression(io.crate.operation.aggregation.FunctionExpression) TestingHelpers.isRow(io.crate.testing.TestingHelpers.isRow) Scalar(io.crate.metadata.Scalar) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

FunctionIdent (io.crate.metadata.FunctionIdent)32 Test (org.junit.Test)19 FunctionInfo (io.crate.metadata.FunctionInfo)15 AggregationTest (io.crate.operation.aggregation.AggregationTest)12 DataType (io.crate.types.DataType)8 CrateUnitTest (io.crate.test.integration.CrateUnitTest)6 Aggregation (io.crate.analyze.symbol.Aggregation)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)3 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 Function (io.crate.analyze.symbol.Function)2 InputColumn (io.crate.analyze.symbol.InputColumn)2 Symbol (io.crate.analyze.symbol.Symbol)2 Reference (io.crate.metadata.Reference)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 SetType (io.crate.types.SetType)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1