[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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
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(); +} +} + +
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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(); +} +} + +
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---
[GitHub] phoenix pull request #262: PHOENIX 153 implement TABLESAMPLE clause
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(); +} +} + +
[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: aertoriaDate: 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---