processing/src/main/java/org/apache/carbondata/processing/sort/sortdata/IntermediateFileMerger.java
/**
   * Below method will be used to write data to file
   *
   * @throws CarbonSortKeyAndGroupByException problem while writing
   */
Below method will be used to write data to file
@throws CarbonSortKeyAndGroupByException problem while writing
Below method will be used to write data to file @throws CarbonSortKeyAndGroupByException problem while writing
private void writeDataToFile(Object[] row) throws CarbonSortKeyAndGroupByException {
    try {
      int[] mdkArray = (int[]) row[0];
      byte[][] nonDictArray = (byte[][]) row[1];
      int mdkIndex = 0;
      int nonDictKeyIndex = 0;
      for (boolean nodictinary : isNoDictionaryDimensionColumn) {
        if (nodictinary) {
          byte[] col = nonDictArray[nonDictKeyIndex++];
          stream.writeShort(col.length);
          stream.write(col);
        } else {
          stream.writeInt(mdkArray[mdkIndex++]);
        }
      }
      for (; nonDictKeyIndex < noDictDimCnt + complexCnt; nonDictKeyIndex++) {
        byte[] col = nonDictArray[nonDictKeyIndex++];
        stream.writeShort(col.length);
        stream.write(col);
      }
      int fieldIndex = 0;
      for (int counter = 0; counter < measureCnt; counter++) {
        if (null != NonDictionaryUtil.getMeasure(fieldIndex, row)) {
          stream.write((byte) 1);
          DataType dataType = measureDataTypes[counter];
          if (dataType == DataTypes.BOOLEAN) {
            stream.writeBoolean((boolean)NonDictionaryUtil.getMeasure(fieldIndex, row));
          } else if (dataType == DataTypes.SHORT) {
            stream.writeShort((short) NonDictionaryUtil.getMeasure(fieldIndex, row));
          } else if (dataType == DataTypes.INT) {
            stream.writeInt((int) NonDictionaryUtil.getMeasure(fieldIndex, row));
          } else if (dataType == DataTypes.LONG) {
            stream.writeLong((long) NonDictionaryUtil.getMeasure(fieldIndex, row));
          } else if (dataType == DataTypes.DOUBLE) {
            stream.writeDouble((Double) NonDictionaryUtil.getMeasure(fieldIndex, row));
          } else if (DataTypes.isDecimal(dataType)) {
            byte[] bigDecimalInBytes = DataTypeUtil
                .bigDecimalToByte((BigDecimal) NonDictionaryUtil.getMeasure(fieldIndex, row));
            stream.writeInt(bigDecimalInBytes.length);
            stream.write(bigDecimalInBytes);
          } else {
            throw new IllegalArgumentException("unsupported data type:" + dataType);
          }
        } else {
          stream.write((byte) 0);
        }
        fieldIndex++;
      }
    } catch (IOException e) {
      throw new CarbonSortKeyAndGroupByException("Problem while writing the file", e);
    }
  }
private void writeDataToFile ( Object [ ] row ) throws CarbonSortKeyAndGroupByException { try { int [ ] mdkArray = ( int [ ] ) row [ 0 ] ; byte [ ] [ ] nonDictArray = ( byte [ ] [ ] ) row [ 1 ] ; int mdkIndex = 0 ; int nonDictKeyIndex = 0 ; for ( boolean nodictinary : isNoDictionaryDimensionColumn ) { if ( nodictinary ) { byte [ ] col = nonDictArray [ nonDictKeyIndex ++ ] ; stream . writeShort ( col . length ) ; stream . write ( col ) ; } else { stream . writeInt ( mdkArray [ mdkIndex ++ ] ) ; } } for ( ; nonDictKeyIndex < noDictDimCnt + complexCnt ; nonDictKeyIndex ++ ) { byte [ ] col = nonDictArray [ nonDictKeyIndex ++ ] ; stream . writeShort ( col . length ) ; stream . write ( col ) ; } int fieldIndex = 0 ; for ( int counter = 0 ; counter < measureCnt ; counter ++ ) { if ( null != NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) { stream . write ( ( byte ) 1 ) ; DataType dataType = measureDataTypes [ counter ] ; if ( dataType == DataTypes . BOOLEAN ) { stream . writeBoolean ( ( boolean ) NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) ; } else if ( dataType == DataTypes . SHORT ) { stream . writeShort ( ( short ) NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) ; } else if ( dataType == DataTypes . INT ) { stream . writeInt ( ( int ) NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) ; } else if ( dataType == DataTypes . LONG ) { stream . writeLong ( ( long ) NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) ; } else if ( dataType == DataTypes . DOUBLE ) { stream . writeDouble ( ( Double ) NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) ; } else if ( DataTypes . isDecimal ( dataType ) ) { byte [ ] bigDecimalInBytes = DataTypeUtil . bigDecimalToByte ( ( BigDecimal ) NonDictionaryUtil . getMeasure ( fieldIndex , row ) ) ; stream . writeInt ( bigDecimalInBytes . length ) ; stream . write ( bigDecimalInBytes ) ; } else { throw new IllegalArgumentException ( "unsupported data type:" + dataType ) ; } } else { stream . write ( ( byte ) 0 ) ; } fieldIndex ++ ; } } catch ( IOException e ) { throw new CarbonSortKeyAndGroupByException ( "Problem while writing the file" , e ) ; } }
Below method will be used to write data to file
 @throws CarbonSortKeyAndGroupByException problem while writing
Below method will be used to write data to file @throws CarbonSortKeyAndGroupByException problem while writing
// write dictionary and non dictionary dimensions here. // write complex // write measure