Github user sounakr commented on a diff in the pull request: https://github.com/apache/carbondata/pull/2209#discussion_r185213084 --- Diff: processing/src/main/java/org/apache/carbondata/processing/datatypes/PrimitiveDataType.java --- @@ -211,29 +241,66 @@ public int getSurrogateIndex() { /* * set surrogate index */ - @Override - public void setSurrogateIndex(int surrIndex) { - index = surrIndex; + @Override public void setSurrogateIndex(int surrIndex) { + if (this.carbonDimension != null && !this.carbonDimension.hasEncoding(Encoding.DICTIONARY)) { + index = 0; + } else if (this.carbonDimension == null && isDictionary == false) { + index = 0; + } else { + index = surrIndex; + } + } + + @Override public Boolean getIsColumnDictionary() { + return isDictionary; } @Override public void writeByteArray(Object input, DataOutputStream dataOutputStream) throws IOException, DictionaryGenerationException { String parsedValue = input == null ? null : DataTypeUtil.parseValue(input.toString(), carbonDimension); - Integer surrogateKey; - if (null == parsedValue) { - surrogateKey = CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY; - } else { - surrogateKey = dictionaryGenerator.getOrGenerateKey(parsedValue); - if (surrogateKey == CarbonCommonConstants.INVALID_SURROGATE_KEY) { + if (this.isDictionary) { + Integer surrogateKey; + if (null == parsedValue) { surrogateKey = CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY; + } else { + surrogateKey = dictionaryGenerator.getOrGenerateKey(parsedValue); + if (surrogateKey == CarbonCommonConstants.INVALID_SURROGATE_KEY) { + surrogateKey = CarbonCommonConstants.MEMBER_DEFAULT_VAL_SURROGATE_KEY; + } + } + dataOutputStream.writeInt(surrogateKey); + } else { + // Transform into ByteArray for No Dictionary. + // TODO have to refactor and place all the cases present in NonDictionaryFieldConverterImpl + if (null == parsedValue && this.carbonDimension.getDataType() != DataTypes.STRING) { --- End diff -- The check has to be similar to NonDictionaryFieldConverterImpl
---