private Mapping extractProjectsAndMapping(
		Aggregate aggregate,
		RelNode input,
		RelBuilder relBuilder) {

		// Compute which input fields are used.
		final ImmutableBitSet.Builder inputFieldsUsed = getInputFieldUsed(aggregate, input);

		final List<RexNode> projects = new ArrayList<>();
		final Mapping mapping =
			Mappings.create(MappingType.INVERSE_SURJECTION,
				aggregate.getInput().getRowType().getFieldCount(),
				inputFieldsUsed.cardinality());
		int j = 0;
		for (int i : inputFieldsUsed.build()) {
			projects.add(relBuilder.field(i));
			mapping.set(i, j++);
		}

		if (input instanceof Project) {
			// this will not create trivial projects
			relBuilder.project(projects);
		} else {
			relBuilder.project(projects, Collections.emptyList(), true);
		}

		return mapping;
	}
private Mapping extractProjectsAndMapping ( Aggregate aggregate , RelNode input , RelBuilder relBuilder ) { final ImmutableBitSet . Builder inputFieldsUsed = getInputFieldUsed ( aggregate , input ) ; final List < RexNode > projects = new ArrayList < > ( ) ; final Mapping mapping = Mappings . create ( MappingType . INVERSE_SURJECTION , aggregate . getInput ( ) . getRowType ( ) . getFieldCount ( ) , inputFieldsUsed . cardinality ( ) ) ; int j = 0 ; for ( int i : inputFieldsUsed . build ( ) ) { projects . add ( relBuilder . field ( i ) ) ; mapping . set ( i , j ++ ) ; } if ( input instanceof Project ) { relBuilder . project ( projects ) ; } else { relBuilder . project ( projects , Collections . emptyList ( ) , true ) ; } return mapping ; }
Extract projects from the Aggregate and return the index mapping between the new projects
and it's input.