Github user ankitsinghal commented on a diff in the pull request:

    https://github.com/apache/phoenix/pull/192#discussion_r77612514
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/util/CursorUtil.java ---
    @@ -62,24 +64,44 @@
             private boolean selectHasPKCol = false;
     
             private CursorWrapper(String cursorName, String selectSQL, 
List<OrderByNode> orderBy){
    +            this(cursorName, selectSQL, orderBy, false);
    +        }
    +
    +        private CursorWrapper(String cursorName, String selectSQL, 
List<OrderByNode> orderBy, boolean isCursorStatic){
                 this.cursorName = cursorName;
                 this.orderBy = orderBy;
                 this.selectSQL = selectSQL;
                 this.listSelectColNames = new 
ArrayList<String>(java.util.Arrays.asList(selectSQL
                         .substring(selectSQL.indexOf("SELECT") + 7, 
selectSQL.indexOf("FROM")).trim()
                         .replaceAll("[()]", "").toUpperCase().split(",")));
    +            this.isCursorStatic = isCursorStatic;
             }
     
             private synchronized void openCursor(Connection conn) throws 
SQLException {
                 if(isOpen){
                     return;
                 }
    -            QueryPlan plan = 
conn.prepareStatement(selectSQL).unwrap(PhoenixPreparedStatement.class).compileQuery();
    -            List<String> listPKColNames = new 
ArrayList<String>(Arrays.asList(plan.getTableRef().getTable()
    -                    .getPKColumns().toString().replaceAll("[\\[ \\]]", 
"").toUpperCase().split(",")));
                 StringBuilder whereBuilder = new StringBuilder(" WHERE (");
                 StringBuilder orderByBuilder = new StringBuilder(" ORDER BY ");
                 StringBuilder selectBuilder = new 
StringBuilder(listSelectColNames.toString().replaceAll("[\\[ \\]]", ""));
    +
    +            QueryPlan plan = 
conn.prepareStatement(selectSQL).unwrap(PhoenixPreparedStatement.class).compileQuery();
    +            PTable table = plan.getTableRef().getTable();
    +            //Process static cursor option
    +            if(isCursorStatic){
    +                int columnIndex = table.getRowTimestampColPos();
    +                if(columnIndex == -1) throw new SQLException("Cursor " + 
cursorName + " declared as STATIC, " +
    +                        "but target table does not contain a ROW_TIMESTAMP 
column!");
    +
    +                String columnName = 
table.getColumns().get(columnIndex).getName().getString();
    +                whereBuilder.append(columnName).append(") <= (");
    +                String timestampFilter = 
"TO_DATE('"+DateUtil.getDateFormatter(DateUtil.DEFAULT_DATE_FORMAT).format(new 
java.sql.Date(System.currentTimeMillis()))+"')";
    +                whereBuilder.append(timestampFilter).append(") AND (");
    +            }
    +
    +            List<String> listPKColNames = new 
ArrayList<String>(Arrays.asList(table.getPKColumns().toString().replaceAll("[\\[
 \\]]", "").toUpperCase().split(",")));
    +
    +            //Process ORDER BY expressions in the internal select statement
    --- End diff --
    
    By static cursor you mean that subsequent fetches on the cursor should see 
the new data upserted after the cursor is open? 
    If that so then we don't need to have timestamp filter for it, we can use 
scan.setTimeRange(0, CURRENT_SCN!=null ?  CURRENT_SCN, 
compileTimeORCursorOpenTime));


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to