Github user kumarvishal09 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2402#discussion_r197630599
--- Diff:
core/src/main/java/org/apache/carbondata/core/datastore/page/LocalDictColumnPage.java
---
@@ -0,0 +1,319 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.carbondata.core.datastore.page;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+
+import org.apache.carbondata.common.logging.LogService;
+import org.apache.carbondata.common.logging.LogServiceFactory;
+import org.apache.carbondata.core.localdictionary.PageLevelDictionary;
+import
org.apache.carbondata.core.localdictionary.exception.DictionaryThresholdReachedException;
+import
org.apache.carbondata.core.localdictionary.generator.LocalDictionaryGenerator;
+import org.apache.carbondata.core.util.ByteUtil;
+
+/**
+ * Column page implementation for Local dictionary generated columns
+ * Its a decorator over two column page
+ * 1. Which will hold the actual data
+ * 2. Which will hold the dictionary encoded data
+ */
+public class LocalDictColumnPage extends ColumnPage {
+
+ /**
+ * LOGGER
+ */
+ private static final LogService LOGGER =
+ LogServiceFactory.getLogService(LocalDictColumnPage.class.getName());
+
+ /**
+ * to maintain page level dictionary for column page
+ */
+ private PageLevelDictionary pageLevelDictionary;
+
+ /**
+ * to hold the actual data of the column
+ */
+ private ColumnPage actualDataColumnPage;
+
+ /**
+ * to hold the dictionary encoded column page
+ */
+ private ColumnPage encodedDataColumnPage;
+
+ /**
+ * to check if actual column page memory is already clear
+ */
+ private boolean isActualPageMemoryFreed;
+
+ /**
+ * Create a new column page with input data type and page size.
+ */
+ protected LocalDictColumnPage(ColumnPage actualDataColumnPage,
ColumnPage encodedColumnpage,
+ LocalDictionaryGenerator localDictionaryGenerator) {
+ super(actualDataColumnPage.getColumnSpec(),
actualDataColumnPage.getDataType(),
+ actualDataColumnPage.getPageSize());
+ if (!localDictionaryGenerator.isThresholdReached()) {
+ pageLevelDictionary = new
PageLevelDictionary(localDictionaryGenerator,
+ actualDataColumnPage.getColumnSpec().getFieldName());
+ this.encodedDataColumnPage = encodedColumnpage;
+ }
+ this.actualDataColumnPage = actualDataColumnPage;
+ }
+
+ @Override public byte[][] getByteArrayPage() {
+ if (null != pageLevelDictionary) {
+ return encodedDataColumnPage.getByteArrayPage();
+ } else {
+ return actualDataColumnPage.getByteArrayPage();
+ }
+ }
+
+ /**
+ * Below method will be used to check whether page is local dictionary
+ * generated or not. This will be used for while enoding the the page
+ *
+ * @return
+ */
+ public boolean isLocalDictGeneratedPage() {
+ return null != pageLevelDictionary;
+ }
+
+ /**
+ * Below method will be used to add column data to page
+ *
+ * @param rowId row number
+ * @param bytes actual data
+ */
+ @Override public void putBytes(int rowId, byte[] bytes) {
+ if (null != pageLevelDictionary) {
+ try {
+ actualDataColumnPage.putBytes(rowId, bytes);
+ int dictionaryValue =
pageLevelDictionary.getDictionaryValue(bytes);
+ encodedDataColumnPage.putBytes(rowId,
ByteUtil.toBytes(dictionaryValue));
+ } catch (DictionaryThresholdReachedException e) {
+ LOGGER.error(e, "Local Dictionary threshold reached for the
column: " + actualDataColumnPage
+ .getColumnSpec().getFieldName());
+ pageLevelDictionary = null;
+ encodedDataColumnPage.freeMemory();
+ encodedDataColumnPage = null;
+ }
+ } else {
+ actualDataColumnPage.putBytes(rowId, bytes);
+ }
+ }
+
+ public PageLevelDictionary getPageDictionary() {
+ return pageLevelDictionary;
+ }
+
+ @Override public void disableLocalDictEncoding() {
+ pageLevelDictionary = null;
+ freeEncodedColumnPage();
+ }
+
+ @Override public PageLevelDictionary getColumnPageDictionary() {
--- End diff --
remove above method
---