You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@carbondata.apache.org by GitBox <gi...@apache.org> on 2020/05/21 04:39:17 UTC
[GitHub] [carbondata] ajantha-bhat opened a new pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
ajantha-bhat opened a new pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770
### Why is this PR needed?
Please refer the design document attached in the JIRA.
Carbondata SDK now currently doesn't support pagination.
### What changes were proposed in this PR?
a) Support pagination from java SDK with LRU cache support.
b) Support pagination in python SDK by calling JAVA SDK.
### Does this PR introduce any user interface change?
- No [Added new interfaces]
### Is any new testcase added?
- 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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-658681740
Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3393/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432606525
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ int[] blockletIndexRange = getBlockletIndexRange(from, to);
+ for (int i = blockletIndexRange[0]; i <= blockletIndexRange[1]; i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
Review comment:
How about the performance for pagination?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-631920232
Build Failed with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1329/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432611327
##########
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:
Please support temporary ak, sk and security token in python too.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
VenuReddy2103 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435183240
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
+ rowsInBlocklet[count++] = carbonReader.readNextRow();
+ }
+ carbonReader.close();
Review comment:
hasNext() seem to throw IOException, InterruptedException exceptions. Enclose this while loop in try/catch/finally block is better ?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-658797923
Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3399/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434414946
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
Review comment:
argument itslef is fromRowNumber, error message is enough
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-648760696
@akashrn5 , @xubo245 , @jack86596 : reminder !
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434411308
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,41 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* Pagination query with from and to range.
+*
+* @param fromRowNumber must be greater 0 (as row id starts from 1)
+* and less than equal to toRowNumber
+* @param toRowNumber must be greater than 0 (as row id starts from 1)
+* and greater than equals to fromRowNumber and not outside the total rows
+* @return array of rows between fromRowNumber and toRowNumber (inclusive)
+* @throws Exception
+*/
+public Object[] read(long fromRowNumber, long toRowNumber) throws IOException, InterruptedException;
+```
+
+```
+/**
+* Get total rows in the folder or a list of CarbonData files.
+* 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();
+```
+
+```
+/**
+* Closes the pagination reader, drops the cache and snapshot.
+* Need to build reader again if the files need to be read again.
+* Suggest to call this when new files are added in the folder.
Review comment:
* call this when the all pagination queries are finished and can the drop cache.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-645308529
Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3161/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432580839
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,39 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* 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;
+```
+
+```
+/**
+* Get total rows in the folder.
Review comment:
Suggestion: Get total rows in the folder or a list of CarbonData files
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-638155466
retest this please
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434412721
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435944901
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
Review comment:
should not continue, throw exception to user immediately
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435945737
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
+ rowsInBlocklet[count++] = carbonReader.readNextRow();
+ }
+ carbonReader.close();
Review comment:
It is a standard interface used for all the reader.
If we need to do something when the exception occurred it make sense to enclose it. Now we don't have anything to do.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-658610305
retest this please
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434412447
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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();
Review comment:
sum is understandable.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-639612033
Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3141/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] jackylk commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
jackylk commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-662189893
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:
users@infra.apache.org
[GitHub] [carbondata] jackylk commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432601619
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
Review comment:
Why add 2 for summationArray2?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-648835883
Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3210/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434412447
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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();
Review comment:
sum is understandable. There are 2 people reviewed before !
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ int[] blockletIndexRange = getBlockletIndexRange(from, to);
+ for (int i = blockletIndexRange[0]; i <= blockletIndexRange[1]; i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
Review comment:
Tested with local file system. With cache reading few rows (out of million rows) after cache is loaded is very fast (within 1 second)
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] akashrn5 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
akashrn5 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434515260
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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();
Review comment:
`summationOfRowsInEachBlocklet` would be more meaningful i guess,
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-645244871
please merge @akashrn5 , @xubo245 @jackylk
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] akashrn5 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
akashrn5 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434515638
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
Review comment:
just from row id in error, doesn't make much sense right
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-631921958
Build Failed with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3049/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-638234676
Build Success with Spark 2.3.4, Please check CI http://121.244.95.60:12545/job/ApacheCarbonPRBuilder2.3/3130/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] asfgit closed pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432611327
##########
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:
Please support temporary ak, sk and security token in python.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-663044289
Thanks for your contribution!
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432603190
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
Review comment:
suggestion: create new class and return a object of this class
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
VenuReddy2103 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435146300
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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);
Review comment:
Any reason for first split rows count handling seperately instead of doing in below for loop itself with loop starting with i = 0; If it was unintentional, suggest to remove outside & start loop from 0.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434414895
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
Review comment:
argument itslef is fromRowNumber, error message is enough
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434407280
##########
File path: docs/configuration-parameters.md
##########
@@ -141,6 +141,7 @@ This section provides the details of all the configurations required for the Car
| carbon.load.all.segment.indexes.to.cache | true | Setting this configuration to false, will prune and load only matched segment indexes to cache using segment metadata information such as columnid and it's minmax values, which decreases the usage of driver memory. |
| carbon.secondary.index.creation.threads | 1 | Specifies the number of threads to concurrently process segments during secondary index creation. This property helps fine tuning the system when there are a lot of segments in a table. The value range is 1 to 50. |
| carbon.si.lookup.partialstring | true | When true, it includes starts with, ends with and contains. When false, it includes only starts with secondary indexes. |
+| carbon.max.pagination.lru.cache.size.in.mb | -1 | Maximum memory **(in MB)** upto which the SDK pagination reader can cache the blocklet rows. Suggest to configure as multiple of blocklet size. Default value of -1 means there is no memory limit for caching. Only integer values greater than 0 are accepted. |
Review comment:
multiple of blocklet means,
N * blocklet size in mb. No need to give example
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] akashrn5 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
akashrn5 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434515732
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
Review comment:
same as above
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432603190
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
Review comment:
suggestion: create new class and return a object instance of this class
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434414148
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
Review comment:
user should know what to pass, getTotalRows() provided for this reason. If by mistake he passes wrong value. we should not assume and give till end of rows.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432611960
##########
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=6666')
Review comment:
Please remove it
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434413651
##########
File path: sdk/sdk/src/test/java/org/apache/carbondata/sdk/file/PaginationCarbonReaderTest.java
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.File;
+import java.io.IOException;
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.metadata.datatype.DataTypes;
+import org.apache.carbondata.core.metadata.datatype.Field;
+import org.apache.carbondata.core.util.CarbonProperties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.RandomStringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test suite for {@link CSVCarbonWriter}
+ */
+public class PaginationCarbonReaderTest {
Review comment:
already there. please check
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] akashrn5 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
akashrn5 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434379315
##########
File path: sdk/sdk/src/test/java/org/apache/carbondata/sdk/file/PaginationCarbonReaderTest.java
##########
@@ -0,0 +1,221 @@
+/*
+ * 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.File;
+import java.io.IOException;
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants;
+import org.apache.carbondata.core.metadata.datatype.DataTypes;
+import org.apache.carbondata.core.metadata.datatype.Field;
+import org.apache.carbondata.core.util.CarbonProperties;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.RandomStringUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test suite for {@link CSVCarbonWriter}
+ */
+public class PaginationCarbonReaderTest {
Review comment:
can you add test cases for negative scenarios also, which throws exceptions?
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
Review comment:
here why do we need to throw an exception, if the limit is crossed, cant we give till the last row?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-645244714
retest this please
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-658725720
retest this please
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435944365
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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);
Review comment:
yeah, it was initial code. modified.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435945737
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
+ rowsInBlocklet[count++] = carbonReader.readNextRow();
+ }
+ carbonReader.close();
Review comment:
If we need to do something when the exception occurred it make sense to enclose it. Now we don't have anything to do.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-639610764
Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1417/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434408720
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,41 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* Pagination query with from and to range.
+*
+* @param fromRowNumber must be greater 0 (as row id starts from 1)
+* and less than equal to toRowNumber
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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;
+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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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:
added
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432604711
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
Review comment:
So the rows result number should not more than Integer.MAX_VALUE: to - from + 1 <= Integer.MAX_VALUE?
Suggestion: limit the size of to - from + 1
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432605600
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ int[] blockletIndexRange = getBlockletIndexRange(from, to);
+ for (int i = blockletIndexRange[0]; i <= blockletIndexRange[1]; i++) {
Review comment:
suggestion: blockletIndexRange[0] => blockletIndexRange.getFrom()
blockletIndexRange[1] => blockletIndexRange.getTo()
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-645308981
Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1437/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435946982
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
+ rowsInBlocklet[count++] = carbonReader.readNextRow();
+ }
+ carbonReader.close();
+ long fromRowId;
+ if (i == 0) {
+ fromRowId = 1;
+ } else {
+ // previous index will contain the sum of rows till previous blocklet.
+ fromRowId = rowCountInSplits.get(i - 1) + 1;
+ }
+ blockletRows = new BlockletRows(fromRowId, detailInfo.getBlockSize(), rowsInBlocklet);
+ // add entry to cache with no expiry time
+ // key: unique blocklet id
+ // value: BlockletRows
+ cache.put(String.valueOf(i), blockletRows, blockletRows.getMemorySize(), Integer.MAX_VALUE);
+ }
+ long fromBlockletRow = blockletRows.getRowIdStartIndex();
+ long toBlockletRow = fromBlockletRow + blockletRows.getRowsCount();
+ Object[] rowsInBlocklet = blockletRows.getRows();
+ if (toRowNumber > toBlockletRow) {
+ if (fromRowNumber >= fromBlockletRow) {
+ // only fromRowNumber lies in this blocklet,
+ // read from fromRowNumber to end of the blocklet.
+ // -1 because row id starts form 0
+ int start = (int) (fromRowNumber - blockletRows.getRowIdStartIndex());
+ int end = blockletRows.getRowsCount();
+ while (start < end) {
Review comment:
it will be hard to read. I feel current changes is 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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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=6666')
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:
users@infra.apache.org
[GitHub] [carbondata] jackylk commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-638130343
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-631874964
@jackylk , @xubo245 : please check
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
VenuReddy2103 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435258695
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
+ rowsInBlocklet[count++] = carbonReader.readNextRow();
+ }
+ carbonReader.close();
+ long fromRowId;
+ if (i == 0) {
+ fromRowId = 1;
+ } else {
+ // previous index will contain the sum of rows till previous blocklet.
+ fromRowId = rowCountInSplits.get(i - 1) + 1;
+ }
+ blockletRows = new BlockletRows(fromRowId, detailInfo.getBlockSize(), rowsInBlocklet);
+ // add entry to cache with no expiry time
+ // key: unique blocklet id
+ // value: BlockletRows
+ cache.put(String.valueOf(i), blockletRows, blockletRows.getMemorySize(), Integer.MAX_VALUE);
+ }
+ long fromBlockletRow = blockletRows.getRowIdStartIndex();
+ long toBlockletRow = fromBlockletRow + blockletRows.getRowsCount();
+ Object[] rowsInBlocklet = blockletRows.getRows();
+ if (toRowNumber > toBlockletRow) {
+ if (fromRowNumber >= fromBlockletRow) {
+ // only fromRowNumber lies in this blocklet,
+ // read from fromRowNumber to end of the blocklet.
+ // -1 because row id starts form 0
+ int start = (int) (fromRowNumber - blockletRows.getRowIdStartIndex());
+ int end = blockletRows.getRowsCount();
+ while (start < end) {
Review comment:
All 3 partial overlap cases we copy selectively. so start and end changes. but the while loop copy is same. How about refactor such that copy is moved out to common ? Just a suggestion if it doesn't make code difficult to understand.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-661711709
need one more 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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-658797618
Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1657/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432604711
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
Review comment:
So the rows result number should not more than Integer.MAX_VALUE: to - from + 1 <= Integer.MAX_VALUE?
Suggestion: limit the scope: to - from + 1
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-648830470
Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1483/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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:
users@infra.apache.org
[GitHub] [carbondata] akashrn5 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
akashrn5 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434325061
##########
File path: docs/configuration-parameters.md
##########
@@ -141,6 +141,7 @@ This section provides the details of all the configurations required for the Car
| carbon.load.all.segment.indexes.to.cache | true | Setting this configuration to false, will prune and load only matched segment indexes to cache using segment metadata information such as columnid and it's minmax values, which decreases the usage of driver memory. |
| carbon.secondary.index.creation.threads | 1 | Specifies the number of threads to concurrently process segments during secondary index creation. This property helps fine tuning the system when there are a lot of segments in a table. The value range is 1 to 50. |
| carbon.si.lookup.partialstring | true | When true, it includes starts with, ends with and contains. When false, it includes only starts with secondary indexes. |
+| carbon.max.pagination.lru.cache.size.in.mb | -1 | Maximum memory **(in MB)** upto which the SDK pagination reader can cache the blocklet rows. Suggest to configure as multiple of blocklet size. Default value of -1 means there is no memory limit for caching. Only integer values greater than 0 are accepted. |
Review comment:
`configure as multiple of blocklet size` for this in the bracket can you mention an example?
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,41 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* Pagination query with from and to range.
+*
+* @param fromRowNumber must be greater 0 (as row id starts from 1)
+* and less than equal to toRowNumber
Review comment:
`less than or equal to`
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,41 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* Pagination query with from and to range.
+*
+* @param fromRowNumber must be greater 0 (as row id starts from 1)
+* and less than equal to toRowNumber
+* @param toRowNumber must be greater than 0 (as row id starts from 1)
+* and greater than equals to fromRowNumber and not outside the total rows
Review comment:
change `greater than equals to fromRowNumber and not outside the total rows` to `greater than or equal to fromRowNumber and should not cross the total rows count value`
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,41 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* Pagination query with from and to range.
+*
+* @param fromRowNumber must be greater 0 (as row id starts from 1)
+* and less than equal to toRowNumber
+* @param toRowNumber must be greater than 0 (as row id starts from 1)
+* and greater than equals to fromRowNumber and not outside the total rows
+* @return array of rows between fromRowNumber and toRowNumber (inclusive)
+* @throws Exception
+*/
+public Object[] read(long fromRowNumber, long toRowNumber) throws IOException, InterruptedException;
+```
+
+```
+/**
+* Get total rows in the folder or a list of CarbonData files.
+* 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();
+```
+
+```
+/**
+* Closes the pagination reader, drops the cache and snapshot.
+* Need to build reader again if the files need to be read again.
+* Suggest to call this when new files are added in the folder.
Review comment:
```suggestion
* Do not call this unless new files are added in the folder of you want to drop the cache.
```
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
Review comment:
please change the method java doc similar with comments above for md files
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
Review comment:
same as above for all error messages, please change to a meaningful message like the above suggestion
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
Review comment:
```suggestion
throw new IllegalArgumentException("Starting row number :" + fromRowNumber + " of pagination read is less than 1");
```
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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();
Review comment:
rename `sum` to `summationOfRowsInEachBlocklet`, this would be meaningful
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432606525
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ int[] blockletIndexRange = getBlockletIndexRange(from, to);
+ for (int i = blockletIndexRange[0]; i <= blockletIndexRange[1]; i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
Review comment:
How about the performance for pagination now ?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-648760782
retest this please
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
Review comment:
yes, pagination query is ideally used for getting few rows (per page).
Total rows can be more than Integer.MAX_VALUE (hence using long for from and to), but per query should not be more than Integer.MAX_VALUE.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434414895
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
Review comment:
argument itslef if fromRowNumber, error message is enough
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater 0 (as row id starts from 1)
+ * and less than equal to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than equals to fromRowNumber and not outside the total rows
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
Review comment:
argument itslef if fromRowNumber, error message is enough
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
ajantha-bhat commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r434409645
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,41 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* Pagination query with from and to range.
+*
+* @param fromRowNumber must be greater 0 (as row id starts from 1)
+* and less than equal to toRowNumber
+* @param toRowNumber must be greater than 0 (as row id starts from 1)
+* and greater than equals to fromRowNumber and not outside the total rows
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:
users@infra.apache.org
[GitHub] [carbondata] ajantha-bhat commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
+ }
+
+ private Object[] getRows(long from, long to)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(to - from + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ int[] blockletIndexRange = getBlockletIndexRange(from, to);
+ for (int i = blockletIndexRange[0]; i <= blockletIndexRange[1]; i++) {
Review comment:
done
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
+ }
+ return index;
+ }
+
+ private int[] getBlockletIndexRange(long from, long to) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, to);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), from);
+ return new int[] {lowerBound, upperBound};
Review comment:
done
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
Review comment:
done
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
Review comment:
fixed
##########
File path: docs/sdk-guide.md
##########
@@ -766,6 +771,39 @@ public VectorSchemaRoot getArrowVectors() throws IOException;
public static ArrowRecordBatch byteArrayToArrowBatch(byte[] batchBytes, BufferAllocator bufferAllocator) throws IOException;
```
+### Class org.apache.carbondata.sdk.file.PaginationCarbonReader
+```
+/**
+* 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;
+```
+
+```
+/**
+* Get total rows in the folder.
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-658685529
Build Failed with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1653/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-638235543
Build Success with Spark 2.4.5, Please check CI http://121.244.95.60:12545/job/ApacheCarbon_PR_Builder_2.4.5/1406/
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] CarbonDataQA1 commented on pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
CarbonDataQA1 commented on pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#issuecomment-633897508
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] VenuReddy2103 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
VenuReddy2103 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r435181761
##########
File path: sdk/sdk/src/main/java/org/apache/carbondata/sdk/file/PaginationCarbonReader.java
##########
@@ -0,0 +1,303 @@
+/*
+ * 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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 fromRowNumber must be greater than 0 (as row id starts from 1)
+ * and less than or equals to toRowNumber
+ * @param toRowNumber must be greater than 0 (as row id starts from 1)
+ * and greater than or equals to fromRowNumber
+ * and should not cross the total rows count
+ * @return array of rows between fromRowNumber and toRowNumber (inclusive)
+ * @throws Exception
+ */
+ public Object[] read(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ if (fromRowNumber < 1) {
+ throw new IllegalArgumentException("from row id:" + fromRowNumber + " is less than 1");
+ }
+ if (fromRowNumber > toRowNumber) {
+ throw new IllegalArgumentException(
+ "from row id:" + fromRowNumber + " is greater than to row id:" + toRowNumber);
+ }
+ if (toRowNumber > getTotalRows()) {
+ throw new IllegalArgumentException(
+ "to row id:" + toRowNumber + " is greater than total rows:" + getTotalRows());
+ }
+ return getRows(fromRowNumber, toRowNumber);
+ }
+
+ /**
+ * Get total rows in the folder or a list of CarbonData files.
+ * 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * Get total rows in the folder or a list of CarbonData files.
+ * It is based on the snapshot of files taken while building the reader.
+ *
+ *
+ * @return total rows from all the files in the reader.
+ */
+ public String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ // offset the one index shifted and get absolute value of it.
+ index = Math.abs(index + 1);
+ }
+ return index;
+ }
+
+ private Range getBlockletIndexRange(long fromRowNumber, long toRowNumber) {
+ // find the matching blocklet index range by checking with from and to.
+ int upperBound = findBlockletIndex(rowCountInSplits, toRowNumber);
+ // lower bound cannot be more than upper bound, so work on sub list.
+ int lowerBound = findBlockletIndex(rowCountInSplits.subList(0, upperBound), fromRowNumber);
+ return new Range(lowerBound, upperBound);
+ }
+
+ private Object[] getRows(long fromRowNumber, long toRowNumber)
+ throws IOException, InterruptedException {
+ int rowCount = 0;
+ Object[] rows = new Object[(int)(toRowNumber - fromRowNumber + 1)];
+ // get the matching split index (blocklets) range for the input range.
+ Range blockletIndexRange = getBlockletIndexRange(fromRowNumber, toRowNumber);
+ for (int i = blockletIndexRange.getFrom(); i <= blockletIndexRange.getTo(); i++) {
+ String blockletUniqueId = String.valueOf(i);
+ BlockletRows blockletRows;
+ if (cache.get(blockletUniqueId) != null) {
+ blockletRows = (BlockletRows)cache.get(blockletUniqueId);
+ } else {
+ BlockletDetailInfo detailInfo =
+ ((CarbonInputSplit) allBlockletSplits.get(i)).getDetailInfo();
+ int rowCountInBlocklet = detailInfo.getRowCount();
+ Object[] rowsInBlocklet = new Object[rowCountInBlocklet];
+ // read the rows from the blocklet
+ // TODO: read blocklets in multi-thread if there is a performance requirement.
+ readerBuilder.setInputSplit(allBlockletSplits.get(i));
+ CarbonReader<Object> carbonReader = readerBuilder.build();
+ int count = 0;
+ while (carbonReader.hasNext()) {
Review comment:
we don't continue with next splits if current split read fails ?
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [carbondata] xubo245 commented on a change in pull request #3770: [CARBONDATA-3829] Support pagination in SDK reader
Posted by GitBox <gi...@apache.org>.
xubo245 commented on a change in pull request #3770:
URL: https://github.com/apache/carbondata/pull/3770#discussion_r432602296
##########
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<T> extends CarbonReader<T> {
+ // Splits based the file present in the reader path when the reader is built.
+ private List<InputSplit> allBlockletSplits;
+
+ // Rows till the current splits stored as list.
+ private List<Long> 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<InputSplit> 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 interface is for python to call java.
+ * Because python cannot understand java Long object. so send string object.
+ *
+ * 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 String getTotalRowsAsString() {
+ if (isClosed) {
+ throw new RuntimeException("Pagination Reader is closed. please build again");
+ }
+ return (rowCountInSplits.get(rowCountInSplits.size() - 1)).toString();
+ }
+
+ private static int findBlockletIndex(List<Long> summationArray2, Long key) {
+ // summation array is in sorted order, so can use the binary search.
+ int index = Collections.binarySearch(summationArray2, key);
+ if (index < 0) {
+ // when key not found, binary search returns negative index [-1 to -N].
+ // which is the possible place where key can be inserted.
+ // with one shifted position. As 0 is also a valid index.
+ index = index + 1; // offset the one index shifted.
+ index = Math.abs(index);
Review comment:
please merge line 145 and 146
----------------------------------------------------------------
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:
users@infra.apache.org