use of io.crate.metadata.FunctionIdent in project crate by crate.
the class CoordinateFunction method register.
private static void register(ScalarFunctionModule module, String name, Function<Object, Double> func) {
for (DataType inputType : SUPPORTED_INPUT_TYPES) {
FunctionIdent ident = new FunctionIdent(name, Collections.singletonList(inputType));
module.register(new UnaryScalar<>(new FunctionInfo(ident, DataTypes.DOUBLE), func));
}
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class GeoHashFunction method register.
private static void register(ScalarFunctionModule module, String name, Function<Object, BytesRef> func) {
for (DataType inputType : SUPPORTED_INPUT_TYPES) {
FunctionIdent ident = new FunctionIdent(name, Collections.singletonList(inputType));
module.register(new UnaryScalar<>(new FunctionInfo(ident, DataTypes.STRING), func));
}
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class GroupProjectionTest method testStreaming2.
@Test
public void testStreaming2() throws Exception {
Reference nameRef = createReference("name", DataTypes.STRING);
List<Symbol> keys = Collections.singletonList(nameRef);
List<Aggregation> aggregations = Collections.singletonList(Aggregation.finalAggregation(new FunctionInfo(new FunctionIdent(CountAggregation.NAME, ImmutableList.of()), DataTypes.LONG), ImmutableList.of(), Aggregation.Step.PARTIAL));
GroupProjection groupProjection = new GroupProjection(keys, aggregations, RowGranularity.CLUSTER);
BytesStreamOutput out = new BytesStreamOutput();
Projection.toStream(groupProjection, out);
StreamInput in = StreamInput.wrap(out.bytes());
GroupProjection p2 = (GroupProjection) Projection.fromStream(in);
assertThat(p2.keys().size(), is(1));
assertThat(p2.values().size(), is(1));
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class MergeNodeTest method testSerialization.
@Test
public void testSerialization() throws Exception {
Reference nameRef = TestingHelpers.createReference("name", DataTypes.STRING);
List<Symbol> keys = Collections.singletonList(nameRef);
List<Aggregation> aggregations = Collections.singletonList(Aggregation.finalAggregation(new FunctionInfo(new FunctionIdent(CountAggregation.NAME, ImmutableList.of()), DataTypes.LONG), ImmutableList.of(), Aggregation.Step.PARTIAL));
GroupProjection groupProjection = new GroupProjection(keys, aggregations, RowGranularity.CLUSTER);
TopNProjection topNProjection = new TopNProjection(10, 0, InputColumn.numInputs(keys.size() + aggregations.size()));
List<Projection> projections = Arrays.asList(groupProjection, topNProjection);
MergePhase node = new MergePhase(UUID.randomUUID(), 0, "merge", 2, Collections.emptyList(), Arrays.<DataType>asList(DataTypes.UNDEFINED, DataTypes.STRING), projections, DistributionInfo.DEFAULT_BROADCAST, null);
node.executionNodes(Sets.newHashSet("node1", "node2"));
BytesStreamOutput output = new BytesStreamOutput();
node.writeTo(output);
StreamInput input = StreamInput.wrap(output.bytes());
MergePhase node2 = MergePhase.FACTORY.create();
node2.readFrom(input);
assertThat(node.numUpstreams(), is(node2.numUpstreams()));
assertThat(node.nodeIds(), is(node2.nodeIds()));
assertThat(node.jobId(), is(node2.jobId()));
assertEquals(node.inputTypes(), node2.inputTypes());
assertThat(node.phaseId(), is(node2.phaseId()));
assertThat(node.distributionInfo(), is(node2.distributionInfo()));
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class ExpressionAnalyzer method convertFunctionCall.
protected Symbol convertFunctionCall(FunctionCall node, ExpressionAnalysisContext context) {
List<Symbol> arguments = new ArrayList<>(node.getArguments().size());
List<DataType> argumentTypes = new ArrayList<>(node.getArguments().size());
for (Expression expression : node.getArguments()) {
Symbol argSymbol = expression.accept(innerAnalyzer, context);
argumentTypes.add(argSymbol.valueType());
arguments.add(argSymbol);
}
FunctionInfo functionInfo;
if (node.isDistinct()) {
if (argumentTypes.size() > 1) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "%s(DISTINCT x) does not accept more than one argument", node.getName()));
}
// define the inner function. use the arguments/argumentTypes from above
FunctionIdent innerIdent = new FunctionIdent(CollectSetAggregation.NAME, argumentTypes);
FunctionInfo innerInfo = getFunctionInfo(innerIdent);
Symbol innerFunction = context.allocateFunction(innerInfo, arguments);
// define the outer function which contains the inner function as argument.
String nodeName = "collection_" + node.getName().toString();
List<Symbol> outerArguments = Arrays.<Symbol>asList(innerFunction);
ImmutableList<DataType> outerArgumentTypes = ImmutableList.<DataType>of(new SetType(argumentTypes.get(0)));
FunctionIdent ident = new FunctionIdent(nodeName, outerArgumentTypes);
try {
functionInfo = getFunctionInfo(ident);
} catch (UnsupportedOperationException ex) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "unknown function %s(DISTINCT %s)", node.getName(), argumentTypes.get(0)), ex);
}
arguments = outerArguments;
} else {
FunctionIdent ident = new FunctionIdent(node.getName().toString(), argumentTypes);
functionInfo = getFunctionInfo(ident);
}
return context.allocateFunction(functionInfo, arguments);
}
Aggregations