Search in sources :

Example 1 with ElasticsearchAggregate

use of org.apache.calcite.adapter.elasticsearch.ElasticsearchAggregate in project drill by apache.

the class ElasticPlanTransformer method visit.

@Override
public RelNode visit(RelNode other) {
    // with actual table fields
    if (other instanceof ElasticsearchProject) {
        ElasticsearchProject project = (ElasticsearchProject) other;
        RelNode input = project.getInput().accept(this);
        List<RexNode> convertedExpressions = project.getProjects();
        // project closest to the scan should be rewritten only
        if (!this.hasProject) {
            ElasticExpressionMapper expressionMapper = new ElasticExpressionMapper(project.getCluster().getRexBuilder(), project.getInput().getRowType(), mapField);
            convertedExpressions = convertedExpressions.stream().map(expression -> expression.accept(expressionMapper)).collect(Collectors.toList());
            RelRecordType relDataType = getRelRecordType(other.getRowType());
            this.hasProject = true;
            return CalciteUtils.createProject(project.getTraitSet(), input, convertedExpressions, relDataType);
        } else {
            return input;
        }
    } else if (other instanceof ElasticsearchFilter) {
        ElasticsearchFilter filter = (ElasticsearchFilter) other;
        RexNode convertedCondition = filter.getCondition().accept(new ElasticExpressionMapper(other.getCluster().getRexBuilder(), filter.getInput().getRowType(), mapField));
        return filter.copy(other.getTraitSet(), filter.getInput().accept(this), convertedCondition);
    } else if (other instanceof ElasticsearchSort) {
        ElasticsearchSort sort = (ElasticsearchSort) other;
        RelNode input = getMappedInput(sort.getInput());
        return sort.copy(other.getTraitSet(), input, sort.getCollation(), sort.offset, sort.fetch);
    } else if (other instanceof ElasticsearchAggregate) {
        ElasticsearchAggregate aggregate = (ElasticsearchAggregate) other;
        RelNode input = getMappedInput(aggregate.getInput());
        return aggregate.copy(other.getTraitSet(), input, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList());
    }
    return super.visit(other);
}
Also used : ElasticsearchSort(org.apache.calcite.adapter.elasticsearch.ElasticsearchSort) RelNode(org.apache.calcite.rel.RelNode) ElasticsearchProject(org.apache.calcite.adapter.elasticsearch.ElasticsearchProject) ElasticsearchAggregate(org.apache.calcite.adapter.elasticsearch.ElasticsearchAggregate) RelRecordType(org.apache.calcite.rel.type.RelRecordType) RexNode(org.apache.calcite.rex.RexNode) ElasticsearchFilter(org.apache.calcite.adapter.elasticsearch.ElasticsearchFilter)

Aggregations

ElasticsearchAggregate (org.apache.calcite.adapter.elasticsearch.ElasticsearchAggregate)1 ElasticsearchFilter (org.apache.calcite.adapter.elasticsearch.ElasticsearchFilter)1 ElasticsearchProject (org.apache.calcite.adapter.elasticsearch.ElasticsearchProject)1 ElasticsearchSort (org.apache.calcite.adapter.elasticsearch.ElasticsearchSort)1 RelNode (org.apache.calcite.rel.RelNode)1 RelRecordType (org.apache.calcite.rel.type.RelRecordType)1 RexNode (org.apache.calcite.rex.RexNode)1