phoenix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ankitsinghal <...@git.apache.org>
Subject [GitHub] phoenix pull request #229: PHOENIX-3572 Support FETCH NEXT|n ROWS query on c...
Date Mon, 13 Feb 2017 07:54:34 GMT
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?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message