{
sortFields = new Fields[ size ];
sortBuilder = new TupleBuilder[ size ];
}
Scope outgoingScope = outgoingScopes.get( 0 );
int numScopes = Math.min( size, incomingScopes.size() );
for( int i = 0; i < numScopes; i++ )
{
Scope incomingScope = incomingScopes.get( i );
// for GroupBy, incoming may have same name, but guaranteed to have same key/value/sort fields for merge
// arrays may be size 1, then ordinal should always be zero.
int ordinal = size == 1 ? 0 : incomingScope.getOrdinal();
keyFields[ ordinal ] = outgoingScope.getKeySelectors().get( incomingScope.getName() );
valuesFields[ ordinal ] = incomingScope.getIncomingSpliceFields();
keyBuilder[ ordinal ] = createNarrowBuilder( incomingScope.getIncomingSpliceFields(), keyFields[ ordinal ] );
valuesBuilder[ ordinal ] = createNulledBuilder( incomingScope.getIncomingSpliceFields(), keyFields[ ordinal ] );
if( sortFields != null )
{
sortFields[ ordinal ] = outgoingScope.getSortingSelectors().get( incomingScope.getName() );
sortBuilder[ ordinal ] = createNarrowBuilder( incomingScope.getIncomingSpliceFields(), sortFields[ ordinal ] );
}
if( LOG.isDebugEnabled() )
{
LOG.debug( "incomingScope: {}, in pos: {}", incomingScope.getName(), ordinal );
LOG.debug( "keyFields: {}", printSafe( keyFields[ ordinal ] ) );
LOG.debug( "valueFields: {}", printSafe( valuesFields[ ordinal ] ) );
if( sortFields != null )
LOG.debug( "sortFields: {}", printSafe( sortFields[ ordinal ] ) );