Search in sources :

Example 1 with FunctionIdent

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

the class GroupingIntegerCollectorBenchmark method createGroupBySumCollector.

private GroupingCollector createGroupBySumCollector(Functions functions) {
    InputCollectExpression keyInput = new InputCollectExpression(0);
    List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
    CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
    FunctionIdent functionIdent = new FunctionIdent(SumAggregation.NAME, Arrays.asList(DataTypes.INTEGER));
    FunctionInfo functionInfo = new FunctionInfo(functionIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
    AggregationFunction sumAgg = (AggregationFunction) functions.get(functionIdent);
    Aggregation aggregation = Aggregation.finalAggregation(functionInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
    Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, sumAgg, new Input[] { keyInput }) };
    return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.INTEGER);
}
Also used : AggregationFunction(io.crate.operation.aggregation.AggregationFunction) Aggregation(io.crate.analyze.symbol.Aggregation) SumAggregation(io.crate.operation.aggregation.impl.SumAggregation) 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 2 with FunctionIdent

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

the class SymbolFormatterTest method testFormat.

@Test
public void testFormat() throws Exception {
    Function f = new Function(new FunctionInfo(new FunctionIdent("foo", Arrays.<DataType>asList(DataTypes.STRING, DataTypes.UNDEFINED)), DataTypes.DOUBLE), Arrays.<Symbol>asList(Literal.of("bar"), Literal.of(3.4)));
    assertThat(SymbolFormatter.format("This Symbol is formatted %s", f), is("This Symbol is formatted foo('bar', 3.4)"));
}
Also used : Function(io.crate.analyze.symbol.Function) FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with FunctionIdent

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

the class FunctionTest method testCloning.

@Test
public void testCloning() 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)));
    Function fn2 = fn.clone();
    assertThat(fn, is(equalTo(fn2)));
    assertThat(fn.hashCode(), is(fn2.hashCode()));
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 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 5 with FunctionIdent

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

the class AggregationTest method executeAggregation.

public Object[][] executeAggregation(String name, DataType dataType, Object[][] data, List<DataType> argumentTypes) throws Exception {
    FunctionIdent fi;
    InputCollectExpression[] inputs;
    if (dataType != null) {
        fi = new FunctionIdent(name, argumentTypes);
        inputs = new InputCollectExpression[argumentTypes.size()];
        for (int i = 0; i < argumentTypes.size(); i++) {
            inputs[i] = new InputCollectExpression(i);
        }
    } else {
        fi = new FunctionIdent(name, ImmutableList.<DataType>of());
        inputs = new InputCollectExpression[0];
    }
    AggregationFunction impl = (AggregationFunction) functions.get(fi);
    Object state = impl.newState(ramAccountingContext);
    ArrayBucket bucket = new ArrayBucket(data);
    for (Row row : bucket) {
        for (InputCollectExpression i : inputs) {
            i.setNextRow(row);
        }
        state = impl.iterate(ramAccountingContext, state, inputs);
    }
    state = impl.terminatePartial(ramAccountingContext, state);
    return new Object[][] { { state } };
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) DataType(io.crate.types.DataType) Row(io.crate.data.Row)

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