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());
}
}
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)));
}
}
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);
}
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()));
}
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));
}
Aggregations