If the SQL-MapReduce function is a partition function, multiple operateOnPartition calls get a handle to the same IMDC. The finalization code uses the method Drainable::drainOutputRows(). If any input partition is empty, operateOnSomeRows and operateOnPartition are never invoked; therefore, Teradata recommends creating an empty IMDC in drainOutputRows, as in the following code.
public void drainOutputRows(RowEmitter outputEmitter) { InMemoryDataCollection IMDC_name = InMemoryDataCollectionRepository.getInMemoryDataCollection(imdcName_); if(IMDC_name == null) { myIMDC = InMemoryDataCollectionRepository.createInMemoryDataCollection( imdcName_, imdcCols_, imdcInMemSizeInMB_); } IMDC_name.finalizeCollection(); int taskIdx = TaskInfo.getTaskIndex(); long numRows = IMDC_name.numRows(); outputEmitter.addInt(taskIdx); outputEmitter.addLong(numRows); outputEmitter.emitRow(); }