[GitHub] [carbondata] Indhumathi27 commented on a change in pull request #3776: [CARBONDATA-3834]Segment directory and the segment file in metadata are not created for partitioned table when 'carbon.m

2020-06-02 Thread GitBox


Indhumathi27 commented on a change in pull request #3776:
URL: https://github.com/apache/carbondata/pull/3776#discussion_r434305132



##
File path: 
hadoop/src/main/java/org/apache/carbondata/hadoop/api/CarbonOutputCommitter.java
##
@@ -302,6 +317,54 @@ private void commitJobForPartition(JobContext context, 
boolean overwriteSet,
 commitJobFinal(context, loadModel, operationContext, carbonTable, 
uniqueId);
   }
 
+  @SuppressWarnings("unchecked")
+  private void writeSegmentWithoutMergeIndex(JobContext context, 
CarbonLoadModel loadModel,
+  String segmentFileName, String partitionPath) throws IOException {
+Map IndexFileNameMap = (Map) 
ObjectSerializationUtil

Review comment:
   ```suggestion
   Map indexFileNameMap = (Map) 
ObjectSerializationUtil
   ```

##
File path: 
integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/standardpartition/StandardPartitionTableLoadingTestCase.scala
##
@@ -566,6 +567,18 @@ class StandardPartitionTableLoadingTestCase extends 
QueryTest with BeforeAndAfte
 assert(ex.getMessage().equalsIgnoreCase("Cannot use all columns for 
partition columns;"))
   }
 
+  test("test partition without merge index files for segment") {
+sql("DROP TABLE IF EXISTS new_par")
+CarbonProperties.getInstance()
+  .addProperty(CarbonCommonConstants.CARBON_MERGE_INDEX_IN_SEGMENT, 
"false")
+sql("CREATE TABLE new_par (a INT, b INT) PARTITIONED BY (country STRING) 
STORED AS carbondata")
+sql("INSERT INTO new_par PARTITION(country='India') SELECT 1,2")
+sql("INSERT INTO new_par PARTITION(country='India') SELECT 3,4")
+sql("INSERT INTO new_par PARTITION(country='China') SELECT 5,6")
+sql("INSERT INTO new_par PARTITION(country='China') SELECT 7,8")
+checkAnswer(sql("SELECT COUNT(*) FROM new_par"), Seq(Row(4)))

Review comment:
   please check for index files also

##
File path: 
hadoop/src/main/java/org/apache/carbondata/hadoop/api/CarbonOutputCommitter.java
##
@@ -302,6 +317,54 @@ private void commitJobForPartition(JobContext context, 
boolean overwriteSet,
 commitJobFinal(context, loadModel, operationContext, carbonTable, 
uniqueId);
   }
 
+  @SuppressWarnings("unchecked")
+  private void writeSegmentWithoutMergeIndex(JobContext context, 
CarbonLoadModel loadModel,

Review comment:
   Please add method description, as why this is required

##
File path: 
hadoop/src/main/java/org/apache/carbondata/hadoop/api/CarbonOutputCommitter.java
##
@@ -302,6 +317,54 @@ private void commitJobForPartition(JobContext context, 
boolean overwriteSet,
 commitJobFinal(context, loadModel, operationContext, carbonTable, 
uniqueId);
   }
 
+  @SuppressWarnings("unchecked")
+  private void writeSegmentWithoutMergeIndex(JobContext context, 
CarbonLoadModel loadModel,
+  String segmentFileName, String partitionPath) throws IOException {
+Map IndexFileNameMap = (Map) 
ObjectSerializationUtil
+
.convertStringToObject(context.getConfiguration().get("carbon.index.files.name"));
+List partitionList =
+(List) 
ObjectSerializationUtil.convertStringToObject(partitionPath);
+SegmentFileStore.SegmentFile finalSegmentFile = null;
+boolean isRelativePath;
+String path;
+for (String partition : partitionList) {
+  isRelativePath = false;
+  path = partition;
+  if (path.startsWith(loadModel.getTablePath())) {
+path = path.substring(loadModel.getTablePath().length());
+isRelativePath = true;
+  }
+  SegmentFileStore.SegmentFile segmentFile = new 
SegmentFileStore.SegmentFile();
+  SegmentFileStore.FolderDetails folderDetails = new 
SegmentFileStore.FolderDetails();
+  Set set = new HashSet();

Review comment:
   Rename `set` variable

##
File path: 
hadoop/src/main/java/org/apache/carbondata/hadoop/api/CarbonOutputCommitter.java
##
@@ -302,6 +317,54 @@ private void commitJobForPartition(JobContext context, 
boolean overwriteSet,
 commitJobFinal(context, loadModel, operationContext, carbonTable, 
uniqueId);
   }
 
+  @SuppressWarnings("unchecked")
+  private void writeSegmentWithoutMergeIndex(JobContext context, 
CarbonLoadModel loadModel,
+  String segmentFileName, String partitionPath) throws IOException {
+Map IndexFileNameMap = (Map) 
ObjectSerializationUtil
+
.convertStringToObject(context.getConfiguration().get("carbon.index.files.name"));
+List partitionList =
+(List) 
ObjectSerializationUtil.convertStringToObject(partitionPath);
+SegmentFileStore.SegmentFile finalSegmentFile = null;
+boolean isRelativePath;
+String path;
+for (String partition : partitionList) {
+  isRelativePath = false;
+  path = partition;
+  if (path.startsWith(loadModel.getTablePath())) {
+path = path.substring(loadModel.getTablePath().length());
+isRelativePath = true;
+  }
+  SegmentFileStore.SegmentFile 

[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3785: [WIP] Fix merge index issue in streaming table

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3785:
URL: https://github.com/apache/carbondata/pull/3785#issuecomment-637678524


   Build Failed  with Spark 2.4.5, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1401/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3785: [WIP] Fix merge index issue in streaming table

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3785:
URL: https://github.com/apache/carbondata/pull/3785#issuecomment-637674877


   Build Failed  with Spark 2.3.4, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3125/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3776: [CARBONDATA-3834]Segment directory and the segment file in metadata are not created for partitioned table when 'carbon.merge.index.

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3776:
URL: https://github.com/apache/carbondata/pull/3776#issuecomment-637648330


   Build Success with Spark 2.3.4, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3124/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3776: [CARBONDATA-3834]Segment directory and the segment file in metadata are not created for partitioned table when 'carbon.merge.index.

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3776:
URL: https://github.com/apache/carbondata/pull/3776#issuecomment-637646868


   Build Success with Spark 2.4.5, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1400/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-637641946


   Build Success with Spark 2.4.5, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1399/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[jira] [Created] (CARBONDATA-3842) Select with limit displays incorrect resultset after datamap creation

2020-06-02 Thread Chetan Bhat (Jira)
Chetan Bhat created CARBONDATA-3842:
---

 Summary: Select with limit displays incorrect resultset after 
datamap creation
 Key: CARBONDATA-3842
 URL: https://issues.apache.org/jira/browse/CARBONDATA-3842
 Project: CarbonData
  Issue Type: Bug
  Components: data-query
Affects Versions: 2.0.1
 Environment: Spark 2.3.2
Reporter: Chetan Bhat


*Steps :-*

create table tab1(id int, name string, dept string) STORED as carbondata;
create materialized view datamap31 as select a.id, a.name from tab1 a;
insert into tab1 select 1,'ram','cs';
insert into tab1 select 2,'shyam','it';
select a.id, a.name from tab1 a order by a.id limit 1;

*Issue :*  

Select with limit displays incorrect resultset (2 records instead of 1) after 
datamap creation.

0: jdbc:hive2://10.20.251.163:23040/default> select a.id, a.name from tab1 a 
order by a.id limit 1;
INFO : Execution ID: 558
+-++--+
| id | name |
+-++--+
| 2 | shyam |
| 1 | ram |
+-++--+
*2 rows selected (0.601 seconds)*

 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-637638738


   Build Success with Spark 2.3.4, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3123/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] ajantha-bhat opened a new pull request #3785: [WIP] Fix merge index issue in streaming table

2020-06-02 Thread GitBox


ajantha-bhat opened a new pull request #3785:
URL: https://github.com/apache/carbondata/pull/3785


### Why is this PR needed?


### What changes were proposed in this PR?
   
   
### Does this PR introduce any user interface change?
- No
- Yes. (please explain the change and update document)
   
### Is any new testcase added?
- No
- Yes
   
   
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433877801



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,296 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to

Review comment:
   done. renamed all occurrence and document.

##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,296 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;

[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433808273



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,296 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to

Review comment:
   ok, I will change. both from and to





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433807579



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,296 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to
+   * @param to must be >= from and not outside the total rows
+   * @return array of rows between from and to (inclusive)
+   * @throws Exception
+   */
+  public Object[] read(long from, long to) throws IOException, 
InterruptedException {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+if (from < 1) {
+  throw new IllegalArgumentException("from row id:" + from + " is less 
than 1");
+}
+if (from > to) {
+  throw new IllegalArgumentException(
+  "from row id:" + from + " is greater than to row id:" + to);
+}
+if (to > getTotalRows()) {

Review comment:
   In line 86, I have mentioned 'to' must be >= 'from'
   so, this has to be greater than 0.
   
   If still need to mention. I can add.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] jackylk commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


jackylk commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433801885



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,296 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to
+   * @param to must be >= from and not outside the total rows
+   * @return array of rows between from and to (inclusive)
+   * @throws Exception
+   */
+  public Object[] read(long from, long to) throws IOException, 
InterruptedException {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+if (from < 1) {
+  throw new IllegalArgumentException("from row id:" + from + " is less 
than 1");
+}
+if (from > to) {
+  throw new IllegalArgumentException(
+  "from row id:" + from + " is greater than to row id:" + to);
+}
+if (to > getTotalRows()) {

Review comment:
   Is parameter starts from 0 or 1? should mention in line 85





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] jackylk commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


jackylk commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433800964



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,296 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to

Review comment:
   should mention what is the value stands for, is it the row number?
   if yes, change the parameter name to `fromRowNumber`





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] xubo245 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


xubo245 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-637469617


   LGTM



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433798210



##
File path: python/pycarbon/sdk/PaginationCarbonReader.py
##
@@ -0,0 +1,57 @@
+# 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.
+
+
+class PaginationCarbonReader(object):
+  def __init__(self):
+from jnius import autoclass
+self.readerClass = 
autoclass('org.apache.carbondata.sdk.file.PaginationCarbonReader')
+
+  def builder(self, path, table_name):
+self.PaginationCarbonReaderBuilder = self.readerClass.builder(path, 
table_name)
+return self
+
+  def projection(self, projection_list):
+self.PaginationCarbonReaderBuilder.projection(projection_list)
+return self
+
+  def withHadoopConf(self, key, value):

Review comment:
   ok





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-637401136


   Build Success with Spark 2.3.4, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3122/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-637399742


   Build Success with Spark 2.4.5, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1398/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3776: [CARBONDATA-3834]Segment directory and the segment file in metadata are not created for partitioned table when 'carbon.merge.index.

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3776:
URL: https://github.com/apache/carbondata/pull/3776#issuecomment-637376476


   Build Success with Spark 2.4.5, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1397/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3776: [CARBONDATA-3834]Segment directory and the segment file in metadata are not created for partitioned table when 'carbon.merge.index.

2020-06-02 Thread GitBox


CarbonDataQA1 commented on pull request #3776:
URL: https://github.com/apache/carbondata/pull/3776#issuecomment-637376228


   Build Success with Spark 2.3.4, Please check CI 
http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3121/
   



This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433650411



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,276 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to
+   * @param to must be >= from and not outside the total rows
+   * @return array of rows between from and to (inclusive)
+   * @throws Exception
+   */
+  public Object[] read(long from, long to) throws IOException, 
InterruptedException {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+if (from < 1) {
+  throw new IllegalArgumentException("from row id:" + from + " is less 
than 1");
+}
+if (from > to) {
+  throw new IllegalArgumentException(
+  "from row id:" + from + " is greater than to row id:" + to);
+}
+if (to > getTotalRows()) {
+  throw new IllegalArgumentException(
+  "to row id:" + to + " is greater than total rows:" + getTotalRows());
+}
+return getRows(from, to);
+  }
+
+  /**
+   * Get total rows in the folder.
+   * It is based on the snapshot of files taken while building the reader.
+   *
+   * @return total rows from all the files in the reader.
+   */
+  public long getTotalRows() {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+return rowCountInSplits.get(rowCountInSplits.size() - 1);
+  }
+
+  /**
+   * This 

[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433650373



##
File path: python/pycarbon/tests/sdk/test_read_write_carbon.py
##
@@ -25,7 +26,8 @@
 import os
 import jnius_config
 
-jnius_config.set_classpath("../../../sdk/sdk/target/carbondata-sdk.jar")
+jnius_config.set_classpath("../../../../sdk/sdk/target/carbondata-sdk.jar")
+# 
jnius_config.add_options('-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=')

Review comment:
   done





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433644354



##
File path: python/pycarbon/sdk/PaginationCarbonReader.py
##
@@ -0,0 +1,57 @@
+# 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.
+
+
+class PaginationCarbonReader(object):
+  def __init__(self):
+from jnius import autoclass
+self.readerClass = 
autoclass('org.apache.carbondata.sdk.file.PaginationCarbonReader')
+
+  def builder(self, path, table_name):
+self.PaginationCarbonReaderBuilder = self.readerClass.builder(path, 
table_name)
+return self
+
+  def projection(self, projection_list):
+self.PaginationCarbonReaderBuilder.projection(projection_list)
+return self
+
+  def withHadoopConf(self, key, value):

Review comment:
   That temporary AK SK is a separate requirement. Once PR raised for that, 
can python code in the same PR.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433644058



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,276 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to
+   * @param to must be >= from and not outside the total rows
+   * @return array of rows between from and to (inclusive)
+   * @throws Exception
+   */
+  public Object[] read(long from, long to) throws IOException, 
InterruptedException {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+if (from < 1) {
+  throw new IllegalArgumentException("from row id:" + from + " is less 
than 1");
+}
+if (from > to) {
+  throw new IllegalArgumentException(
+  "from row id:" + from + " is greater than to row id:" + to);
+}
+if (to > getTotalRows()) {
+  throw new IllegalArgumentException(
+  "to row id:" + to + " is greater than total rows:" + getTotalRows());
+}
+return getRows(from, to);
+  }
+
+  /**
+   * Get total rows in the folder.
+   * It is based on the snapshot of files taken while building the reader.
+   *
+   * @return total rows from all the files in the reader.
+   */
+  public long getTotalRows() {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+return rowCountInSplits.get(rowCountInSplits.size() - 1);
+  }
+
+  /**
+   * This 

[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader

2020-06-02 Thread GitBox


ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r433643240



##
File path: 
sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##
@@ -0,0 +1,276 @@
+/*
+ * 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.sdk.file;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.carbondata.common.annotations.InterfaceAudience;
+import org.apache.carbondata.common.annotations.InterfaceStability;
+import org.apache.carbondata.core.cache.CarbonLRUCache;
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.indexstore.BlockletDetailInfo;
+import org.apache.carbondata.hadoop.CarbonInputSplit;
+import org.apache.carbondata.sdk.file.cache.BlockletRows;
+
+import org.apache.hadoop.mapreduce.InputSplit;
+
+/**
+ * CarbonData SDK reader with pagination support
+ */
+@InterfaceAudience.User
+@InterfaceStability.Evolving
+public class PaginationCarbonReader extends CarbonReader {
+  // Splits based the file present in the reader path when the reader is built.
+  private List allBlockletSplits;
+
+  // Rows till the current splits stored as list.
+  private List rowCountInSplits;
+
+  // Reader builder used to create the pagination reader, used for building 
split level readers.
+  private CarbonReaderBuilder readerBuilder;
+
+  private boolean isClosed;
+
+  // to store the rows of each blocklet in memory based LRU cache.
+  // key: unique blocklet id
+  // value: BlockletRows
+  private CarbonLRUCache cache =
+  new 
CarbonLRUCache(CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB,
+  
CarbonCommonConstants.CARBON_MAX_PAGINATION_LRU_CACHE_SIZE_IN_MB_DEFAULT);
+
+  /**
+   * Call {@link #builder(String)} to construct an instance
+   */
+
+  PaginationCarbonReader(List splits, CarbonReaderBuilder 
readerBuilder) {
+// Initialize super class with no readers.
+// Based on the splits identified for pagination query, readers will be 
built for the query.
+super(null);
+this.allBlockletSplits = splits;
+this.readerBuilder = readerBuilder;
+// prepare the mapping.
+rowCountInSplits = new ArrayList<>(splits.size());
+long sum = ((CarbonInputSplit) 
splits.get(0)).getDetailInfo().getRowCount();
+rowCountInSplits.add(sum);
+for (int i = 1; i < splits.size(); i++) {
+  // prepare a summation array of row counts in each blocklet,
+  // this is used for pruning with pagination vales.
+  // At current index, it contains sum of rows of all the blocklet from 
previous + current.
+  sum += ((CarbonInputSplit) splits.get(i)).getDetailInfo().getRowCount();
+  rowCountInSplits.add(sum);
+}
+  }
+
+  /**
+   * Pagination query with from and to range.
+   *
+   * @param from must be greater than 0 and <= to
+   * @param to must be >= from and not outside the total rows
+   * @return array of rows between from and to (inclusive)
+   * @throws Exception
+   */
+  public Object[] read(long from, long to) throws IOException, 
InterruptedException {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+if (from < 1) {
+  throw new IllegalArgumentException("from row id:" + from + " is less 
than 1");
+}
+if (from > to) {
+  throw new IllegalArgumentException(
+  "from row id:" + from + " is greater than to row id:" + to);
+}
+if (to > getTotalRows()) {
+  throw new IllegalArgumentException(
+  "to row id:" + to + " is greater than total rows:" + getTotalRows());
+}
+return getRows(from, to);
+  }
+
+  /**
+   * Get total rows in the folder.
+   * It is based on the snapshot of files taken while building the reader.
+   *
+   * @return total rows from all the files in the reader.
+   */
+  public long getTotalRows() {
+if (isClosed) {
+  throw new RuntimeException("Pagination Reader is closed. please build 
again");
+}
+return rowCountInSplits.get(rowCountInSplits.size() - 1);
+  }
+
+  /**
+   * This