processing/src/main/java/org/apache/carbondata/processing/sort/sortdata/SortDataRows.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[][] recordHolderList, int entryCountLocal, File file)
      throws CarbonSortKeyAndGroupByException {
    DataOutputStream stream = null;
    try {
      stream = FileFactory.getDataOutputStream(file.getPath(), FileFactory.FileType.LOCAL,
          parameters.getFileWriteBufferSize(), parameters.getSortTempCompressorName());
      stream.writeInt(entryCountLocal);
      int complexDimColCount = parameters.getComplexDimColCount();
      int dimColCount = parameters.getDimColCount() + complexDimColCount;
      DataType[] type = parameters.getMeasureDataType();
      boolean[] noDictionaryDimnesionMapping = parameters.getNoDictionaryDimnesionColumn();
      Object[] row = null;
      for (int i = 0; i < entryCountLocal; i++) {
        row = recordHolderList[i];
        int dimCount = 0;
        for (; dimCount < noDictionaryDimnesionMapping.length; dimCount++) {
          if (noDictionaryDimnesionMapping[dimCount]) {
            byte[] col = (byte[]) row[dimCount];
            stream.writeShort(col.length);
            stream.write(col);
          } else {
            stream.writeInt((int)row[dimCount]);
          }
        }
        for (; dimCount < dimColCount; dimCount++) {
          byte[] value = (byte[])row[dimCount];
          stream.writeShort(value.length);
          stream.write(value);
        }
        for (int mesCount = 0;
             mesCount < parameters.getMeasureColCount(); mesCount++) {
          Object value = row[mesCount + dimColCount];
          if (null != value) {
            stream.write((byte) 1);
            DataType dataType = type[mesCount];
            if (dataType == DataTypes.BOOLEAN) {
              stream.writeBoolean((boolean) value);
            } else if (dataType == DataTypes.SHORT) {
              stream.writeShort((Short) value);
            } else if (dataType == DataTypes.INT) {
              stream.writeInt((Integer) value);
            } else if (dataType == DataTypes.LONG) {
              stream.writeLong((Long) value);
            } else if (dataType == DataTypes.DOUBLE) {
              stream.writeDouble((Double) value);
            } else if (DataTypes.isDecimal(dataType)) {
              BigDecimal val = (BigDecimal) value;
              byte[] bigDecimalInBytes = DataTypeUtil.bigDecimalToByte(val);
              stream.writeInt(bigDecimalInBytes.length);
              stream.write(bigDecimalInBytes);
            } else {
              throw new IllegalArgumentException("unsupported data type:" + type[mesCount]);
            }
          } else {
            stream.write((byte) 0);
          }
        }
      }
    } catch (IOException e) {
      throw new CarbonSortKeyAndGroupByException("Problem while writing the file", e);
    } finally {
      CarbonUtil.closeStreams(stream);
    }
  }
private void writeDataToFile ( Object [ ] [ ] recordHolderList , int entryCountLocal , File file ) throws CarbonSortKeyAndGroupByException { DataOutputStream stream = null ; try { stream = FileFactory . getDataOutputStream ( file . getPath ( ) , FileFactory . FileType . LOCAL , parameters . getFileWriteBufferSize ( ) , parameters . getSortTempCompressorName ( ) ) ; stream . writeInt ( entryCountLocal ) ; int complexDimColCount = parameters . getComplexDimColCount ( ) ; int dimColCount = parameters . getDimColCount ( ) + complexDimColCount ; DataType [ ] type = parameters . getMeasureDataType ( ) ; boolean [ ] noDictionaryDimnesionMapping = parameters . getNoDictionaryDimnesionColumn ( ) ; Object [ ] row = null ; for ( int i = 0 ; i < entryCountLocal ; i ++ ) { row = recordHolderList [ i ] ; int dimCount = 0 ; for ( ; dimCount < noDictionaryDimnesionMapping . length ; dimCount ++ ) { if ( noDictionaryDimnesionMapping [ dimCount ] ) { byte [ ] col = ( byte [ ] ) row [ dimCount ] ; stream . writeShort ( col . length ) ; stream . write ( col ) ; } else { stream . writeInt ( ( int ) row [ dimCount ] ) ; } } for ( ; dimCount < dimColCount ; dimCount ++ ) { byte [ ] value = ( byte [ ] ) row [ dimCount ] ; stream . writeShort ( value . length ) ; stream . write ( value ) ; } for ( int mesCount = 0 ; mesCount < parameters . getMeasureColCount ( ) ; mesCount ++ ) { Object value = row [ mesCount + dimColCount ] ; if ( null != value ) { stream . write ( ( byte ) 1 ) ; DataType dataType = type [ mesCount ] ; if ( dataType == DataTypes . BOOLEAN ) { stream . writeBoolean ( ( boolean ) value ) ; } else if ( dataType == DataTypes . SHORT ) { stream . writeShort ( ( Short ) value ) ; } else if ( dataType == DataTypes . INT ) { stream . writeInt ( ( Integer ) value ) ; } else if ( dataType == DataTypes . LONG ) { stream . writeLong ( ( Long ) value ) ; } else if ( dataType == DataTypes . DOUBLE ) { stream . writeDouble ( ( Double ) value ) ; } else if ( DataTypes . isDecimal ( dataType ) ) { BigDecimal val = ( BigDecimal ) value ; byte [ ] bigDecimalInBytes = DataTypeUtil . bigDecimalToByte ( val ) ; stream . writeInt ( bigDecimalInBytes . length ) ; stream . write ( bigDecimalInBytes ) ; } else { throw new IllegalArgumentException ( "unsupported data type:" + type [ mesCount ] ) ; } } else { stream . write ( ( byte ) 0 ) ; } } } } catch ( IOException e ) { throw new CarbonSortKeyAndGroupByException ( "Problem while writing the file" , e ) ; } finally { CarbonUtil . closeStreams ( stream ) ; } }
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
// open stream // write number of entries to the file // get row from record holder list // write dictionary and non dictionary dimensions here. // write complex dimensions here. // as measures are stored in separate array. // close streams