use of org.apache.calcite.adapter.elasticsearch.ElasticsearchSort 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);
}
Aggregations