Search in sources :

Example 16 with FunctionInfo

use of io.crate.metadata.FunctionInfo 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));
}
Also used : CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) FunctionIdent(io.crate.metadata.FunctionIdent) TestingHelpers.createReference(io.crate.testing.TestingHelpers.createReference) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) 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 17 with FunctionInfo

use of io.crate.metadata.FunctionInfo 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()));
}
Also used : Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) FunctionInfo(io.crate.metadata.FunctionInfo) TopNProjection(io.crate.planner.projection.TopNProjection) GroupProjection(io.crate.planner.projection.GroupProjection) Projection(io.crate.planner.projection.Projection) TopNProjection(io.crate.planner.projection.TopNProjection) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CountAggregation(io.crate.operation.aggregation.impl.CountAggregation) Aggregation(io.crate.analyze.symbol.Aggregation) FunctionIdent(io.crate.metadata.FunctionIdent) MergePhase(io.crate.planner.node.dql.MergePhase) StreamInput(org.elasticsearch.common.io.stream.StreamInput) GroupProjection(io.crate.planner.projection.GroupProjection) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with FunctionInfo

use of io.crate.metadata.FunctionInfo 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);
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo)

Aggregations

FunctionInfo (io.crate.metadata.FunctionInfo)18 FunctionIdent (io.crate.metadata.FunctionIdent)15 CrateUnitTest (io.crate.test.integration.CrateUnitTest)7 DataType (io.crate.types.DataType)7 Test (org.junit.Test)7 Aggregation (io.crate.analyze.symbol.Aggregation)4 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)3 StreamInput (org.elasticsearch.common.io.stream.StreamInput)3 InputColumn (io.crate.analyze.symbol.InputColumn)2 Symbol (io.crate.analyze.symbol.Symbol)2 Reference (io.crate.metadata.Reference)2 AggregationFunction (io.crate.operation.aggregation.AggregationFunction)2 Aggregator (io.crate.operation.aggregation.Aggregator)2 CountAggregation (io.crate.operation.aggregation.impl.CountAggregation)2 CollectExpression (io.crate.operation.collect.CollectExpression)2 InputCollectExpression (io.crate.operation.collect.InputCollectExpression)2 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)2 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)2 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)2 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)2