You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by aertoria <gi...@git.apache.org> on 2017/06/16 20:25:11 UTC

[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

GitHub user aertoria opened a pull request:

    https://github.com/apache/phoenix/pull/262

    PHOENIX 153 implement TABLESAMPLE clause

    table sampling on each Table basis (at the 'FROM' part of the query). Sample size decided by the input sampling rate applies on Primary Key's frequency.
    
    Syntax: 
    `select name from person SAMPLE(0.10) where name='ethan'`
    
    
    ++
    ++Belows are SUPPORTED
    ++
    ===BASE CASE====
    select * from Person;
    select * from PERSON TABLESAMPLE 0.45;
    
    ===WHERE CLAUSE====
    select * from PERSON where ADDRESS = 'CA' OR name>'tina3';
    select * from PERSON TABLESAMPLE 0.49 where ADDRESS = 'CA' OR name>'tina3';
    select * from PERSON TABLESAMPLE 0.49 where ADDRESS = 'CA' OR name>'tina3' LIMIT 1;
    
    ===Wired Table===
    select * from LOCAL_ADDRESS TABLESAMPLE 0.79;
    select * from SYSTEM.STATS TABLESAMPLE 0.41;
    
    ===CORNER CASE===
    select * from PERSON TABLESAMPLE 0;
    select * from PERSON TABLESAMPLE 1.45;
    select * from PERSON TABLESAMPLE kko;
    
    ===AGGREGATION===
    select count(*) from PERSON TABLESAMPLE 0.5 LIMIT 2
    select count(*) from (select NAME from PERSON limit 20)
    
    ===SUB QUERY===
    select * from (select /*+NO_INDEX*/ * from PERSON tablesample 0.1 where Name > 'tina10') where ADDRESS = 'CA'
    
    ===JOINS===
    select * from PERSON1, PERSON2 tablesample 0.7 where PERSON1.Name = PERSON2.NAME
    
    ===QUERY being OPTMIZED===
    select * from PERSON tablesample 0.8 (goes to IDX_ADDRESS_PERSON index table, table sample carry on)
    
    ===INSERT SELECT====
    upsert into personbig(ID, ADDRESS) select id, address from personbig tablesample 0.01;


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

    $ git pull https://github.com/aertoria/phoenix master

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

    https://github.com/apache/phoenix/pull/262.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 #262
    
----
commit c872defc5cc3ef7f4d264b207d831ceb3a71ef2d
Author: aertoria <ca...@gmail.com>
Date:   2017-06-16T20:21:34Z

    PHOENIX 153 implement TABLESAMPLE clause

----


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    >  See ExplainTable and let's figure out the best place to add this.
    
    Purposing adding this logic at `BaseResultIterators`.`explain()` method. Which is between **Line1080** and **Line1081**  of `BaseResultIterators.java` (link below)
    
    https://github.com/apache/phoenix/blob/b9bb918610c04e21b27df8d3fe1c42df508a96f0/phoenix-core/src/main/java/org/apache/phoenix/iterate/BaseResultIterators.java
    
    
    Reason for this location:
    Currently, `BaseResultIterators` inherits abstract class `ExplainTable`.  The explaining string for the table part is essentially finished by these two classes, one following another. Now, the information of tablesampling is stored in `QueryPlan.Statement.fromtable` object, it resides in `BaseResultIterators`. Its parent, the abstract class `ExplainTable` will not have this info (unless we want to modify `PTable` interface and get it from `tableref`).  
    
    In addition, table sampling main logic resides in `BaseResultIterators` when it does `getParallelScans()`. Now we are just making it to also explain the plan when it overrides `explain()`. All thing considered I think `BaseResultIterators` should be the best place to put it.  Please let me know your feedback!
    
    After implemented, it looks like this on single select
    ```
    CLIENT 3-CHUNK 30 ROWS 2370 BYTES PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER PERSON
    TABLESAMPING BY 0.19
    ```
    
    On join select
    ```
    CLIENT 9-CHUNK 30 ROWS 2370 BYTES PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER PERSON
    TABLESAMPING BY 0.65
        PARALLEL INNER-JOIN TABLE 0
            CLIENT 2-CHUNK 1 ROWS 32 BYTES PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER US_POPULATION
            TABLESAMPING BY 0.9504
        AFTER-JOIN SERVER FILTER BY PERSON.ADDRESS > US_POPULATION.STATE
    ```


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126823141
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java ---
    @@ -267,6 +267,12 @@ public LimitNode getLimit() {
         }
         
         @Override
    +    public Double getTableSamplingRate(){
    +    	if(fromTable==null || !(fromTable instanceof ConcreteTableNode)) return null;
    +    	return ((ConcreteTableNode)fromTable).getTableSamplingRate();
    --- End diff --
    
    This is a valid concern and I also have thought about it during developing. Below is my thought process. Please correct me @JamesRTaylor 
    
    So for a join statment, when there are two concrete tables, during the early stage of the plan preparation phase, they will exist inside `select-statement` object as one `JoinTableNode` object. During this time, `getTableSamplingRate` method is not called. Even if in the future some one calls it, it will return null because type safety check inside method.
    
    Later on, during the plan compiling phase, this `select-statement` is going through JoinCompiler, where two new `select-statment` objects will be created with each one has a brand new `fromTable` object. `FromTable` object is populated from `joinTable` object which essentially is the end product when `JoinTable.Compile()` spliting the original `JoinTableNode` into two. For this code please check Line 136 of `JoinCompiler.java` (Link below)
    
    https://github.com/apache/phoenix/blob/ecd287f618470d1e34082c20feb9939cbb0ea65b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
    
    
    So by the time `getTableSamplingRate` method is called, which is during the "getting iterator phase", each select statments will have exactly one `ConcreteTableNode` with its corresponding sampling rate associate with it.


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126779550
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java ---
    @@ -267,6 +267,12 @@ public LimitNode getLimit() {
         }
         
         @Override
    +    public Double getTableSamplingRate(){
    +    	if(fromTable==null || !(fromTable instanceof ConcreteTableNode)) return null;
    +    	return ((ConcreteTableNode)fromTable).getTableSamplingRate();
    --- End diff --
    
    Do we need this method? What happens in the case of a join, where there are multiple concrete tables? 


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126774166
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java ---
    @@ -539,6 +539,7 @@ protected QueryPlan compileSingleFlatQuery(StatementContext context, SelectState
             if (table.getViewStatement() != null) {
                 viewWhere = new SQLParser(table.getViewStatement()).parseQuery().getWhere();
             }
    +        
    --- End diff --
    
    Please revert changes to this file as there are only whitespace changes.


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    The last changes (if we are referring to explain plan change etc) has already been done and went with the last commits.
    
    I'm now rebase with the latest phoenix master and squash all commits into one.
    
    Thanks! @JamesRTaylor 


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    Sounds good. I will start prepare another patch. 


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126779607
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryWithTableSampleIT.java ---
    @@ -0,0 +1,261 @@
    +/*
    + * 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.end2end;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +
    +import java.sql.Connection;
    +import java.sql.DriverManager;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.util.Properties;
    +
    +import org.apache.phoenix.exception.PhoenixParserException;
    +import org.apache.phoenix.util.PropertiesUtil;
    +import org.apache.phoenix.util.TestUtil;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +
    +public class QueryWithTableSampleIT extends ParallelStatsEnabledIT {
    +    private String tableName;
    +    private String joinedTableName;
    +    
    +    @Before
    +    public void generateTableNames() {
    +        tableName = "T_" + generateUniqueName();
    +        joinedTableName = "T_" + generateUniqueName();
    +    }
    +        
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSyntax() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample 15 ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (175) ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryZeroSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (0) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);                        
    +            assertFalse(rs.next());
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (45) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(2, rs.getInt(1));
    +            assertEquals(200, rs.getInt(2));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(6, rs.getInt(1));
    +            assertEquals(600, rs.getInt(2));
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithWhereClause() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (22) where i2>=300 and i1<14 LIMIT 4 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(8, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(10, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(12, rs.getInt(1));          
    +            
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithAggregator() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(i1) FROM " + tableName +" tablesample (22) where i2>=3000 or i1<2 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(14, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithUnion() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT * FROM " + tableName +" tablesample (100) where i1<2 union all SELECT * FROM " + tableName +" tablesample (2) where i2<6000";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(0, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(1, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(30, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(44, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithSubQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(*) FROM (SELECT * FROM " + tableName +" tablesample (50))";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(50, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithJoins() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(*) FROM " + tableName +" as A tablesample (45), "+joinedTableName+" as B tablesample (75) where A.i1=B.i1";
    +            System.out.println(query);
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +
    +            assertTrue(rs.next());
    +            assertEquals(31, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    final private static void inspect(final ResultSet rs) throws SQLException{
    +    	while(rs.next()){
    +    		System.out.println(rs.getInt(1)+","+rs.getInt(2));
    --- End diff --
    
    Correct. I forgot to remove it.


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    Commit 0507d4f change list:
    1, explain plan a new way (Thanks for the suggestion)
    2, squash previous four commit into one
    3, revise all commit message to start with PHOENIX-153+space 
    
    
    preview on a Single select
    `CLIENT 3-CHUNK 30 ROWS 2370 BYTES PARALLEL 1-WAY 0.2-SAMPLED ROUND ROBIN FULL SCAN OVER PERSON`
    
    on a Join select
    ```
    CLIENT 1-CHUNK 0 ROWS 0 BYTES PARALLEL 1-WAY 0.65-SAMPLED ROUND ROBIN FULL SCAN OVER INX_ADDRESS_PERSON
        SERVER FILTER BY FIRST KEY ONLY
        PARALLEL INNER-JOIN TABLE 0
            CLIENT 1-CHUNK 1 ROWS 32 BYTES PARALLEL 1-WAY 0.15-SAMPLED ROUND ROBIN FULL SCAN OVER US_POPULATION
        DYNAMIC SERVER FILTER BY TO_CHAR("INX_ADDRESS_PERSON.0:ADDRESS") IN (US_POPULATION.STATE)
    ```
    



---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126833276
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryWithTableSampleIT.java ---
    @@ -0,0 +1,261 @@
    +/*
    + * 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.end2end;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +
    +import java.sql.Connection;
    +import java.sql.DriverManager;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.util.Properties;
    +
    +import org.apache.phoenix.exception.PhoenixParserException;
    +import org.apache.phoenix.util.PropertiesUtil;
    +import org.apache.phoenix.util.TestUtil;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +
    +public class QueryWithTableSampleIT extends ParallelStatsEnabledIT {
    +    private String tableName;
    +    private String joinedTableName;
    +    
    +    @Before
    +    public void generateTableNames() {
    +        tableName = "T_" + generateUniqueName();
    +        joinedTableName = "T_" + generateUniqueName();
    +    }
    +        
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSyntax() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample 15 ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (175) ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryZeroSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (0) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);                        
    +            assertFalse(rs.next());
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (45) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(2, rs.getInt(1));
    +            assertEquals(200, rs.getInt(2));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(6, rs.getInt(1));
    +            assertEquals(600, rs.getInt(2));
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithWhereClause() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (22) where i2>=300 and i1<14 LIMIT 4 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(8, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(10, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(12, rs.getInt(1));          
    +            
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithAggregator() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(i1) FROM " + tableName +" tablesample (22) where i2>=3000 or i1<2 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(14, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithUnion() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT * FROM " + tableName +" tablesample (100) where i1<2 union all SELECT * FROM " + tableName +" tablesample (2) where i2<6000";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(0, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(1, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(30, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(44, rs.getInt(1));
    --- End diff --
    
    This test is good, but once you incorporate the table sample in the explain plan, you can also have an assert for the query plan.


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria closed the pull request at:

    https://github.com/apache/phoenix/pull/262


---

[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126782179
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/compile/QueryCompiler.java ---
    @@ -539,6 +539,7 @@ protected QueryPlan compileSingleFlatQuery(StatementContext context, SelectState
             if (table.getViewStatement() != null) {
                 viewWhere = new SQLParser(table.getViewStatement()).parseQuery().getWhere();
             }
    +        
    --- End diff --
    
    +1


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    Your idea for updating the explain plan is good. One minor nit. How about "SAMPLED AT 0.9504" instead of TABLESAMPING?


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126833346
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryWithTableSampleIT.java ---
    @@ -0,0 +1,261 @@
    +/*
    + * 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.end2end;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +
    +import java.sql.Connection;
    +import java.sql.DriverManager;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.util.Properties;
    +
    +import org.apache.phoenix.exception.PhoenixParserException;
    +import org.apache.phoenix.util.PropertiesUtil;
    +import org.apache.phoenix.util.TestUtil;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +
    +public class QueryWithTableSampleIT extends ParallelStatsEnabledIT {
    +    private String tableName;
    +    private String joinedTableName;
    +    
    +    @Before
    +    public void generateTableNames() {
    +        tableName = "T_" + generateUniqueName();
    +        joinedTableName = "T_" + generateUniqueName();
    +    }
    +        
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSyntax() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample 15 ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (175) ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryZeroSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (0) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);                        
    +            assertFalse(rs.next());
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (45) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(2, rs.getInt(1));
    +            assertEquals(200, rs.getInt(2));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(6, rs.getInt(1));
    +            assertEquals(600, rs.getInt(2));
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithWhereClause() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (22) where i2>=300 and i1<14 LIMIT 4 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(8, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(10, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(12, rs.getInt(1));          
    +            
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithAggregator() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(i1) FROM " + tableName +" tablesample (22) where i2>=3000 or i1<2 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(14, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithUnion() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT * FROM " + tableName +" tablesample (100) where i1<2 union all SELECT * FROM " + tableName +" tablesample (2) where i2<6000";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(0, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(1, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(30, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(44, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithSubQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(*) FROM (SELECT * FROM " + tableName +" tablesample (50))";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(50, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithJoins() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(*) FROM " + tableName +" as A tablesample (45), "+joinedTableName+" as B tablesample (75) where A.i1=B.i1";
    +            System.out.println(query);
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +
    +            assertTrue(rs.next());
    +            assertEquals(31, rs.getInt(1));
    --- End diff --
    
    Same here - this would be good to assert that the explain plan looks as expected once those changes are made.


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    Closing this P.R. as it has been merged.


---

[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126833016
  
    --- Diff: phoenix-core/src/main/java/org/apache/phoenix/parse/SelectStatement.java ---
    @@ -267,6 +267,12 @@ public LimitNode getLimit() {
         }
         
         @Override
    +    public Double getTableSamplingRate(){
    +    	if(fromTable==null || !(fromTable instanceof ConcreteTableNode)) return null;
    +    	return ((ConcreteTableNode)fromTable).getTableSamplingRate();
    --- End diff --
    
    Sounds reasonable. Please add a comment explaining as you've done here.


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    New patch summary:
    1, Rebased.
    2, Adding in plan explain for table sample, as well as corresponding test cases.
    example:
    ```
    CLIENT 3-CHUNK 30 ROWS 2370 BYTES PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER PERSON
    TABLESAMPING BY 19.0
    ```
    
    Other minor changes:
    reverse unnecessary empty new line change on one file
    revised comments for one method.
    remove unnecessary system print on test cases.


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    +1 after these couple minor tweaks. Nice job, @aertoria!


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    Ping @aertoria - would you have a few spare cycles to make that last change? Also, please squash all commits into one and amend your commit message to be prefixed with PHOENIX-153 (i.e. include the dash). Otherwise, we the pull request isn't tied to the JIRA.


---
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] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause

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

    https://github.com/apache/phoenix/pull/262#discussion_r126773527
  
    --- Diff: phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryWithTableSampleIT.java ---
    @@ -0,0 +1,261 @@
    +/*
    + * 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.end2end;
    +
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertFalse;
    +import static org.junit.Assert.assertTrue;
    +
    +import java.sql.Connection;
    +import java.sql.DriverManager;
    +import java.sql.PreparedStatement;
    +import java.sql.ResultSet;
    +import java.sql.SQLException;
    +import java.util.Properties;
    +
    +import org.apache.phoenix.exception.PhoenixParserException;
    +import org.apache.phoenix.util.PropertiesUtil;
    +import org.apache.phoenix.util.TestUtil;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +
    +public class QueryWithTableSampleIT extends ParallelStatsEnabledIT {
    +    private String tableName;
    +    private String joinedTableName;
    +    
    +    @Before
    +    public void generateTableNames() {
    +        tableName = "T_" + generateUniqueName();
    +        joinedTableName = "T_" + generateUniqueName();
    +    }
    +        
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSyntax() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample 15 ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test(expected=PhoenixParserException.class)
    +    public void testSingleQueryWrongSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (175) ";
    +
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            inspect(rs);
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryZeroSamplingRate() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (0) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);                        
    +            assertFalse(rs.next());
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (45) ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(2, rs.getInt(1));
    +            assertEquals(200, rs.getInt(2));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(6, rs.getInt(1));
    +            assertEquals(600, rs.getInt(2));
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithWhereClause() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT i1, i2 FROM " + tableName +" tablesample (22) where i2>=300 and i1<14 LIMIT 4 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(8, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(10, rs.getInt(1));
    +            
    +            assertTrue(rs.next());
    +            assertEquals(12, rs.getInt(1));          
    +            
    +
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithAggregator() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(i1) FROM " + tableName +" tablesample (22) where i2>=3000 or i1<2 ";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(14, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithUnion() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT * FROM " + tableName +" tablesample (100) where i1<2 union all SELECT * FROM " + tableName +" tablesample (2) where i2<6000";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(0, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(1, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(30, rs.getInt(1));
    +            assertTrue(rs.next());
    +            assertEquals(44, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithSubQuery() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(*) FROM (SELECT * FROM " + tableName +" tablesample (50))";
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +            
    +            assertTrue(rs.next());
    +            assertEquals(50, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    @Test
    +    public void testSingleQueryWithJoins() throws Exception {
    +        Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
    +        Connection conn = DriverManager.getConnection(getUrl(), props);
    +        try {
    +            prepareTableWithValues(conn, 100);
    +            String query = "SELECT count(*) FROM " + tableName +" as A tablesample (45), "+joinedTableName+" as B tablesample (75) where A.i1=B.i1";
    +            System.out.println(query);
    +            ResultSet rs = conn.createStatement().executeQuery(query);
    +
    +            assertTrue(rs.next());
    +            assertEquals(31, rs.getInt(1));
    +        } finally {
    +            conn.close();
    +        }
    +    }
    +    
    +    final private static void inspect(final ResultSet rs) throws SQLException{
    +    	while(rs.next()){
    +    		System.out.println(rs.getInt(1)+","+rs.getInt(2));
    --- End diff --
    
    Minor nit: we don't write to system.out for testing (though I understand the value while debugging). Perhaps simplest to just switch to logging instead.


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by aertoria <gi...@git.apache.org>.
Github user aertoria commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    @JamesRTaylor @gjacoby126  @samarthjain  


---
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] phoenix issue #262: PHOENIX 153 implement TABLESAMPLE clause

Posted by JamesRTaylor <gi...@git.apache.org>.
Github user JamesRTaylor commented on the issue:

    https://github.com/apache/phoenix/pull/262
  
    This looks very good. Couple of minor comments. One addition that I think is worth making would be to include the sampling rate to the explain plan. See ExplainTable and let's figure out the best place to add this.


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