GitHub user anubhav100 opened a pull request: https://github.com/apache/carbondata/pull/1934
[CARBONDATA-2133] Fixed Exception displays after performing select query on newly added Boolean Type **Problem** : In Restructure util and RestructureBasedVectorResultCollector to get the default value of a measure type the case for boolean data type was missing,and in DataTypeUtil to store default value in bytes case of boolean data type was missing **Solution**:Add the Required Cases **Complete Description**: **Classes changed**: 1.**RestructureBasedVectorResultCollector**: **in the below method case for boolean data type was missing** private void fillDataForNonExistingMeasures() { for (int i = 0; i < tableBlockExecutionInfos.getActualQueryMeasures().length; i++) { if (!measureInfo.getMeasureExists()[i]) { int queryOrder = tableBlockExecutionInfos.getActualQueryMeasures()[i].getQueryOrder(); CarbonMeasure measure = tableBlockExecutionInfos.getActualQueryMeasures()[i].getMeasure(); ColumnVectorInfo columnVectorInfo = allColumnInfo[queryOrder]; CarbonColumnVector vector = columnVectorInfo.vector; Object defaultValue = measureDefaultValues[i]; if (null == defaultValue) { vector.putNulls(columnVectorInfo.vectorOffset, columnVectorInfo.size); } else { DataType dataType = measureInfo.getMeasureDataTypes()[i]; if (dataType == DataTypes.SHORT) { vector.putShorts(columnVectorInfo.vectorOffset, columnVectorInfo.size, (short) defaultValue); } else if (dataType == DataTypes.INT) { vector .putInts(columnVectorInfo.vectorOffset, columnVectorInfo.size, (int) defaultValue); } else if (dataType == DataTypes.LONG) { vector.putLongs(columnVectorInfo.vectorOffset, columnVectorInfo.size, (long) defaultValue); } else if (DataTypes.isDecimal(dataType)) { vector.putDecimals(columnVectorInfo.vectorOffset, columnVectorInfo.size, ((Decimal) defaultValue).toJavaBigDecimal(), measure.getPrecision()); } else { vector.putDoubles(columnVectorInfo.vectorOffset, columnVectorInfo.size, (double) defaultValue); } } } } } 2.**RestructureUtil**: **in below methods getMeasureDefaultValue,getMeasureDefaultValueByType the if statement for boolean data type was missing** public static Object getMeasureDefaultValue(ColumnSchema columnSchema, byte[] defaultValue) { Object measureDefaultValue = null; if (!isDefaultValueNull(defaultValue)) { String value; DataType dataType = columnSchema.getDataType(); if (dataType == DataTypes.SHORT) { value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); measureDefaultValue = Short.valueOf(value); } else if (dataType == DataTypes.LONG) { value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); measureDefaultValue = Long.parseLong(value); } else if (dataType == DataTypes.INT) { value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); measureDefaultValue = Integer.parseInt(value); } else if (DataTypes.isDecimal(dataType)) { BigDecimal decimal = DataTypeUtil.byteToBigDecimal(defaultValue); if (columnSchema.getScale() > decimal.scale()) { decimal = decimal.setScale(columnSchema.getScale(), RoundingMode.HALF_UP); } measureDefaultValue = decimal; } else { value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); Double parsedValue = Double.valueOf(value); if (!Double.isInfinite(parsedValue) && !Double.isNaN(parsedValue)) { measureDefaultValue = parsedValue; } } } return measureDefaultValue; } 3.**DatatypeUtil**: To store default value on bytes case of boolean data type was missing public static byte[] convertDataToBytesBasedOnDataType(String data, ColumnSchema columnSchema) { if (null == data) { return null; } else if (CarbonCommonConstants.MEMBER_DEFAULT_VAL.equals(data)) { LOGGER.error("Default value should not be carbon specific null value : " + data); return null; } try { long parsedIntVal = 0; DataType dataType = columnSchema.getDataType(); if (dataType == DataTypes.INT) { parsedIntVal = (long) Integer.parseInt(data); return String.valueOf(parsedIntVal) .getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); } else if (dataType == DataTypes.SHORT) { parsedIntVal = (long) Short.parseShort(data); return String.valueOf(parsedIntVal) .getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); } else if (dataType == DataTypes.DOUBLE) { return String.valueOf(Double.parseDouble(data)) .getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); } else if (dataType == DataTypes.LONG) { return String.valueOf(Long.parseLong(data)) .getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); } else if (dataType == DataTypes.DATE) { DirectDictionaryGenerator directDictionaryGenerator = DirectDictionaryKeyGeneratorFactory .getDirectDictionaryGenerator(columnSchema.getDataType()); int value = directDictionaryGenerator.generateDirectSurrogateKey(data); return String.valueOf(value) .getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); } else if (dataType == DataTypes.TIMESTAMP) { if (columnSchema.hasEncoding(Encoding.DIRECT_DICTIONARY)) { DirectDictionaryGenerator directDictionaryGenerator1 = DirectDictionaryKeyGeneratorFactory .getDirectDictionaryGenerator(columnSchema.getDataType()); int value1 = directDictionaryGenerator1.generateDirectSurrogateKey(data); return String.valueOf(value1) .getBytes(Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); } else { try { Date dateToStr = timeStampformatter.get().parse(data); return ByteUtil.toBytes(dateToStr.getTime()); } catch (ParseException e) { LOGGER.error( "Cannot convert value to Time/Long type value. Value is considered as null" + e .getMessage()); return null; } } } else if (DataTypes.isDecimal(dataType)) { String parsedValue = parseStringToBigDecimal(data, columnSchema); if (null == parsedValue) { return null; } java.math.BigDecimal javaDecVal = new java.math.BigDecimal(parsedValue); return bigDecimalToByte(javaDecVal); } else { return getDataTypeConverter().convertFromStringToByte(data); } } catch (NumberFormatException ex) { LOGGER.error("Problem while converting data type" + data); return null; } } You can merge this pull request into a Git repository by running: $ git pull https://github.com/anubhav100/incubator-carbondata CARBONDATA-2133 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/carbondata/pull/1934.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #1934 ---- commit fcd812a9d09302c1d10b2897883fa3c31a86e156 Author: anubhav100 <anubhav.tarar@...> Date: 2018-02-06T08:03:39Z Fixed Exception displays after performing select query on newly added Boolean data type ---- ---