Search in sources :

Example 6 with DesiredField

use of org.apache.drill.exec.planner.logical.FieldsReWriterUtil.DesiredField in project drill by apache.

the class DrillFilterItemStarReWriterRule method createFieldMapper.

/**
 * Creates node mapper to replace item star calls with new input field references.
 * Starting index should be calculated from the last used input expression (i.e. scan expression).
 * NB: field reference index starts from 0 thus original field count can be taken as starting index
 *
 * @param desiredFields list of desired fields
 * @param startingIndex starting index
 * @return field mapper
 */
private static Map<RexNode, Integer> createFieldMapper(Collection<DesiredField> desiredFields, int startingIndex) {
    Map<RexNode, Integer> fieldMapper = new HashMap<>();
    int index = startingIndex;
    for (DesiredField desiredField : desiredFields) {
        for (RexNode node : desiredField.getNodes()) {
            // if field is referenced in more then one call, add each call to field mapper
            fieldMapper.put(node, index);
        }
        // increment index for the next node reference
        index++;
    }
    return fieldMapper;
}
Also used : HashMap(java.util.HashMap) DesiredField(org.apache.drill.exec.planner.logical.FieldsReWriterUtil.DesiredField) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

DesiredField (org.apache.drill.exec.planner.logical.FieldsReWriterUtil.DesiredField)6 ArrayList (java.util.ArrayList)4 RelDataType (org.apache.calcite.rel.type.RelDataType)4 RexNode (org.apache.calcite.rex.RexNode)4 HashMap (java.util.HashMap)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 RexInputRef (org.apache.calcite.rex.RexInputRef)2 PathSegment (org.apache.drill.common.expression.PathSegment)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 FieldsReWriter (org.apache.drill.exec.planner.logical.FieldsReWriterUtil.FieldsReWriter)2