Github user sounakr commented on a diff in the pull request: https://github.com/apache/carbondata/pull/2417#discussion_r201221334 --- Diff: core/src/main/java/org/apache/carbondata/core/datastore/chunk/store/ColumnPageWrapper.java --- @@ -53,11 +60,75 @@ public int fillVector(int[] filteredRowId, ColumnVectorInfo[] vectorInfo, int ch throw new UnsupportedOperationException("internal error"); } - @Override - public byte[] getChunkData(int rowId) { - return columnPage.getBytes(rowId); + @Override public byte[] getChunkData(int rowId) { + ColumnType columnType = columnPage.getColumnSpec().getColumnType(); + DataType srcDataType = columnPage.getColumnSpec().getSchemaDataType(); + DataType targetDataType = columnPage.getDataType(); + if (columnPage.getNullBits().get(rowId)) { + // if this row is null, return default null represent in byte array + return CarbonCommonConstants.MEMBER_DEFAULT_VAL_ARRAY; + } + if ((columnType == ColumnType.COMPLEX_PRIMITIVE) && this.isAdaptiveComplexPrimitive()) { + if (srcDataType == DataTypes.DOUBLE || srcDataType == DataTypes.FLOAT) { + double doubleData = columnPage.getDouble(rowId); + if (srcDataType == DataTypes.FLOAT) { + float out = (float) doubleData; + return ByteUtil.toBytes(out); + } else { + return ByteUtil.toBytes(doubleData); + } + } else if (DataTypes.isDecimal(srcDataType)) { + throw new RuntimeException("unsupported type: " + srcDataType); + } else if ((srcDataType == DataTypes.BYTE) || + (srcDataType == DataTypes.BOOLEAN) || + (srcDataType == DataTypes.SHORT) || + (srcDataType == DataTypes.SHORT_INT) || + (srcDataType == DataTypes.INT) || + (srcDataType == DataTypes.LONG) || + (srcDataType == DataTypes.TIMESTAMP)) { + long longData = columnPage.getLong(rowId); + if ((srcDataType == DataTypes.BYTE)) { + byte out = (byte) longData; + return ByteUtil.toBytes(out); + } else if (srcDataType == DataTypes.BOOLEAN) { + byte out = (byte) longData; + return ByteUtil.toBytes(ByteUtil.toBoolean(out)); + } else if (srcDataType == DataTypes.SHORT) { + short out = (short) longData; + return ByteUtil.toBytes(out); + } else if (srcDataType == DataTypes.SHORT_INT) { + int out = (int) longData; + return ByteUtil.toBytes(out); + } else if (srcDataType == DataTypes.INT) { + int out = (int) longData; + return ByteUtil.toBytes(out); + } else { + // timestamp and long + return ByteUtil.toBytes(longData); + } + } else if ((targetDataType == DataTypes.STRING) || + (targetDataType == DataTypes.VARCHAR) || + (targetDataType == DataTypes.BYTE_ARRAY)) { + return columnPage.getBytes(rowId); + } else { + throw new RuntimeException("unsupported type: " + targetDataType); + } + } else if ((columnType == ColumnType.COMPLEX_PRIMITIVE) && !this.isAdaptiveComplexPrimitive()) { + if ((srcDataType == DataTypes.BYTE) || (srcDataType == DataTypes.BOOLEAN)) { + byte[] out = new byte[1]; + out[0] = (columnPage.getByte(rowId)); + return out; + } else if (srcDataType == DataTypes.BYTE_ARRAY) { + return columnPage.getBytes(rowId); + } else { + throw new RuntimeException("unsupported type: " + targetDataType); + } + } else { + return columnPage.getBytes(rowId); --- End diff -- This getBytes is only for Complex STRUCT and ARRAY type which are in Byte Array Format. Later when CARBONDATA-2713 turns STRUCT and ARRAY to V-format then this check will throw exception
---