You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by mravi <gi...@git.apache.org> on 2014/05/19 19:09:37 UTC

[GitHub] incubator-phoenix pull request: PHOENIX#939

GitHub user mravi opened a pull request:

    https://github.com/apache/incubator-phoenix/pull/34

    PHOENIX#939

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mravi/incubator-phoenix 3.0

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-phoenix/pull/34.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #34
    
----
commit 7000f6447f1814e618d6dbbb1cf99d102119e50b
Author: Ravi Magham <ma...@gmail.com>
Date:   2014-05-19T16:35:58Z

    PHOENIX#939

----


---
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.
---

[GitHub] incubator-phoenix pull request: PHOENIX#939

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on a diff in the pull request:

    https://github.com/apache/incubator-phoenix/pull/34#discussion_r13060084
  
    --- Diff: phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java ---
    @@ -423,6 +423,91 @@ public void testLoadAndStore() throws Exception {
             assertEquals(270, rs.getInt("MAX_SAL"));
         }
         
    +    /**
    +     * Test for sequences.
    +     * @throws Exception
    +     */
    +    @Test
    +    public void testDataForSQLQueryWithSequences() throws Exception {
    +        
    +         //create the table
    +         String ddl = "CREATE TABLE  " + TABLE_FULL_NAME 
    +                + "  (ID  INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, AGE INTEGER) ";
    +                
    +        conn.createStatement().execute(ddl);
    +        
    +        String sequenceDdl = "CREATE SEQUENCE my_sequence";
    +                
    +        conn.createStatement().execute(sequenceDdl);
    +           
    +        //prepare data with 10 rows having age 25 and the other 30.
    +        final String dml = "UPSERT INTO " + TABLE_FULL_NAME + " VALUES(?,?,?)";
    +        PreparedStatement stmt = conn.prepareStatement(dml);
    +        int rows = 20;
    +        for(int i = 0 ; i < rows; i++) {
    +            stmt.setInt(1, i);
    +            stmt.setString(2, "a"+i);
    +            stmt.setInt(3, (i % 2 == 0) ? 25 : 30);
    +            stmt.execute();    
    +        }
    +        conn.commit();
    +        
    +        //sql query
    +        final String sqlQuery = " SELECT NEXT VALUE FOR my_sequence AS my_seq,ID,NAME,AGE FROM " + TABLE_FULL_NAME + " WHERE AGE > 25";
    --- End diff --
    
    Nice! Does this pass now? I see your code below seems to be doing the right thing wrt creating a SequeunceResultIterator when necessary.


---
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.
---

[GitHub] incubator-phoenix pull request: PHOENIX#939

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on a diff in the pull request:

    https://github.com/apache/incubator-phoenix/pull/34#discussion_r13060097
  
    --- Diff: phoenix-pig/src/it/java/org/apache/phoenix/pig/PhoenixHBaseLoaderIT.java ---
    @@ -423,6 +423,91 @@ public void testLoadAndStore() throws Exception {
             assertEquals(270, rs.getInt("MAX_SAL"));
         }
         
    +    /**
    +     * Test for sequences.
    +     * @throws Exception
    +     */
    +    @Test
    +    public void testDataForSQLQueryWithSequences() throws Exception {
    +        
    +         //create the table
    +         String ddl = "CREATE TABLE  " + TABLE_FULL_NAME 
    +                + "  (ID  INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, AGE INTEGER) ";
    +                
    +        conn.createStatement().execute(ddl);
    +        
    +        String sequenceDdl = "CREATE SEQUENCE my_sequence";
    +                
    +        conn.createStatement().execute(sequenceDdl);
    +           
    +        //prepare data with 10 rows having age 25 and the other 30.
    +        final String dml = "UPSERT INTO " + TABLE_FULL_NAME + " VALUES(?,?,?)";
    +        PreparedStatement stmt = conn.prepareStatement(dml);
    +        int rows = 20;
    +        for(int i = 0 ; i < rows; i++) {
    +            stmt.setInt(1, i);
    +            stmt.setString(2, "a"+i);
    +            stmt.setInt(3, (i % 2 == 0) ? 25 : 30);
    +            stmt.execute();    
    +        }
    +        conn.commit();
    +        
    +        //sql query
    +        final String sqlQuery = " SELECT NEXT VALUE FOR my_sequence AS my_seq,ID,NAME,AGE FROM " + TABLE_FULL_NAME + " WHERE AGE > 25";
    +        //load data and filter rows whose age is > 25
    +        pigServer.registerQuery(String.format(
    +                "A = load 'hbase://query/%s' using org.apache.phoenix.pig.PhoenixHBaseLoader('%s');", sqlQuery,
    +                zkQuorum));
    +        
    +        
    +        Iterator<Tuple> iterator  = pigServer.openIterator("A");
    +        int recordsRead = 0;
    +        while (iterator.hasNext()) {
    +            Tuple tuple = iterator.next();
    +            System.out.println(" the field value is "+tuple.get(1));
    +            recordsRead++;
    +        }
    +        assertEquals(rows/2, recordsRead);
    +    }
    +    
    +    @Test
    +    public void testDataForSQLQueryWithFunctions() throws Exception {
    +        
    +         //create the table
    +         String ddl = "CREATE TABLE  " + TABLE_FULL_NAME 
    +                + "  (ID  INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR) ";
    +                
    +        conn.createStatement().execute(ddl);
    +        
    +        final String dml = "UPSERT INTO " + TABLE_FULL_NAME + " VALUES(?,?)";
    +        PreparedStatement stmt = conn.prepareStatement(dml);
    +        int rows = 20;
    +        for(int i = 0 ; i < rows; i++) {
    +            stmt.setInt(1, i);
    +            stmt.setString(2, "a"+i);
    +            stmt.execute();    
    +        }
    +        conn.commit();
    +        
    +        //sql query
    +        final String sqlQuery = " SELECT UPPER(NAME) AS n FROM " + TABLE_FULL_NAME + " ORDER BY ID" ;
    --- End diff --
    
    Just to confirm, this will work fine for arbitrary expressions, right? Like this: SELECT UPPER(NAME || 'foo') as n ...


---
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.
---

[GitHub] incubator-phoenix pull request: PHOENIX#939

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on a diff in the pull request:

    https://github.com/apache/incubator-phoenix/pull/34#discussion_r13060129
  
    --- Diff: phoenix-pig/src/main/java/org/apache/phoenix/pig/hadoop/PhoenixRecordReader.java ---
    @@ -100,7 +99,13 @@ public void initialize(InputSplit split, TaskAttemptContext context) throws IOEx
             scan.setStartRow(keyRange.getLowerRange());
             scan.setStopRow(keyRange.getUpperRange());
              try {
    -            this.resultIterator = new TableResultIterator(queryPlan.getContext(), queryPlan.getTableRef(),scan);
    +            //this.resultIterator = queryPlan.iterator();
    +             TableResultIterator tableResultIterator = new TableResultIterator(queryPlan.getContext(), queryPlan.getTableRef(),scan);
    +            if(queryPlan.getContext().getSequenceManager().getSequenceCount() > 0) {
    --- End diff --
    
    Good - this looks right. Does it work for sequences now?


---
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.
---