[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