[
https://issues.apache.org/jira/browse/PHOENIX-3572?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15863300#comment-15863300
]
ASF GitHub Bot commented on PHOENIX-3572:
-----------------------------------------
Github user ankitsinghal commented on a diff in the pull request:
https://github.com/apache/phoenix/pull/229#discussion_r100738871
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/util/CursorUtil.java ---
@@ -0,0 +1,203 @@
+/*
+ * 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.phoenix.util;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.phoenix.compile.QueryPlan;
+import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.execute.CursorFetchPlan;
+import org.apache.phoenix.iterate.CursorResultIterator;
+import org.apache.phoenix.parse.CloseStatement;
+import org.apache.phoenix.parse.DeclareCursorStatement;
+import org.apache.phoenix.parse.OpenStatement;
+import org.apache.phoenix.schema.tuple.Tuple;
+
+public final class CursorUtil {
+
+ private static class CursorWrapper {
+ private final String cursorName;
+ private final String selectSQL;
+ private boolean isOpen = false;
+ QueryPlan queryPlan;
+ ImmutableBytesWritable row;
+ ImmutableBytesWritable previousRow;
+ private Scan scan;
+ private boolean moreValues=true;
+ private boolean isReversed;
+ private boolean islastCallNext;
+ private CursorFetchPlan fetchPlan;
+ private int offset = -1;
+
+ private CursorWrapper(String cursorName, String selectSQL,
QueryPlan queryPlan){
+ this.cursorName = cursorName;
+ this.selectSQL = selectSQL;
+ this.queryPlan = queryPlan;
+ this.islastCallNext = true;
+ this.fetchPlan = new CursorFetchPlan(queryPlan);
+ }
+
+ private synchronized void openCursor(Connection conn) throws
SQLException {
+ if(isOpen){
+ return;
+ }
+ this.scan = this.queryPlan.getContext().getScan();
+
isReversed=OrderBy.REV_ROW_KEY_ORDER_BY.equals(this.queryPlan.getOrderBy());
+ isOpen = true;
+ }
+
+ private void closeCursor() throws SQLException {
+ isOpen = false;
+ ((CursorResultIterator) fetchPlan.iterator()).closeCursor();
+ //TODO: Determine if the cursor should be removed from the
HashMap at this point.
+ //Semantically it makes sense that something which is 'Closed'
one should be able to 'Open' again.
+ mapCursorIDQuery.remove(this.cursorName);
+ }
+
+ private QueryPlan getFetchPlan(boolean isNext, int fetchSize)
throws SQLException {
+ if (!isOpen)
+ throw new SQLException("Fetch call on closed cursor '" +
this.cursorName + "'!");
+
((CursorResultIterator)fetchPlan.iterator()).setFetchSize(fetchSize);
+ if (!queryPlan.getStatement().isAggregate() ||
!queryPlan.getStatement().isDistinct()) {
+ if (islastCallNext != isNext) {
+ if (islastCallNext && !isReversed){
+ ScanUtil.setReversed(scan);
+ } else {
+ ScanUtil.unsetReversed(scan);
+ }
--- End diff --
this code seems to be for reverse/prior and belongs to another JIRA. can we
remove this if it can affect the functionality?
> Support FETCH NEXT| n ROWS from Cursor
> --------------------------------------
>
> Key: PHOENIX-3572
> URL: https://issues.apache.org/jira/browse/PHOENIX-3572
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: Biju Nair
> Assignee: Biju Nair
>
> Implement required changes to support
> - {{DECLARE}} and {{OPEN}} a cursor
> - query {{FETCH NEXT | n ROWS}} from the cursor
> - {{CLOSE}} the cursor
> Based on the feedback in [PR
> #192|https://github.com/apache/phoenix/pull/192], implement the changes using
> {{ResultSet}}.
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)