Repository: phoenix Updated Branches: refs/heads/master 02f159165 -> e9593529f
PHOENIX-4258 Breakup ScanQueryIT into several integration tests so as not to create too many tables in one test Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/e9593529 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e9593529 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e9593529 Branch: refs/heads/master Commit: e9593529fac63d24629044c6e221f7369b08cf0e Parents: 02f1591 Author: James Taylor <[email protected]> Authored: Fri Sep 29 12:14:21 2017 -0700 Committer: James Taylor <[email protected]> Committed: Fri Sep 29 12:14:21 2017 -0700 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/InQueryIT.java | 247 +++++++++++ .../apache/phoenix/end2end/IntArithmeticIT.java | 18 +- .../phoenix/end2end/NumericArithmeticIT.java | 145 ++++++ .../org/apache/phoenix/end2end/QueryIT.java | 230 +--------- .../org/apache/phoenix/end2end/RangeScanIT.java | 281 ++++++++++++ .../org/apache/phoenix/end2end/ScanQueryIT.java | 443 ------------------- .../org/apache/phoenix/end2end/StringIT.java | 33 ++ 7 files changed, 729 insertions(+), 668 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/InQueryIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InQueryIT.java new file mode 100644 index 0000000..c5e6e63 --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InQueryIT.java @@ -0,0 +1,247 @@ +/* + * 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.apache.phoenix.util.TestUtil.B_VALUE; +import static org.apache.phoenix.util.TestUtil.C_VALUE; +import static org.apache.phoenix.util.TestUtil.E_VALUE; +import static org.apache.phoenix.util.TestUtil.ROW1; +import static org.apache.phoenix.util.TestUtil.ROW2; +import static org.apache.phoenix.util.TestUtil.ROW3; +import static org.apache.phoenix.util.TestUtil.ROW4; +import static org.apache.phoenix.util.TestUtil.ROW5; +import static org.apache.phoenix.util.TestUtil.ROW6; +import static org.apache.phoenix.util.TestUtil.ROW7; +import static org.apache.phoenix.util.TestUtil.ROW8; +import static org.apache.phoenix.util.TestUtil.ROW9; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +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.Date; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import org.apache.phoenix.util.PropertiesUtil; +import org.junit.Test; +import org.junit.runners.Parameterized.Parameters; + +public class InQueryIT extends BaseQueryIT { + + public InQueryIT(String idxDdl, boolean mutable, boolean columnEncoded, boolean keepDeletedCells) throws Exception { + super(idxDdl, mutable, columnEncoded, false); + } + + @Parameters(name="InQueryIT_{index}") // name is used by failsafe as file name in reports + public static Collection<Object> data() { + return QueryIT.data(); + } + + @Test + public void testInListSkipScan() throws Exception { + String query = "SELECT entity_id, b_string FROM " + tableName + " WHERE organization_id=? and entity_id IN (?,?)"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + statement.setString(2, ROW2); + statement.setString(3, ROW4); + ResultSet rs = statement.executeQuery(); + Set<String> expectedvals = new HashSet<String>(); + expectedvals.add(ROW2+"_"+C_VALUE); + expectedvals.add(ROW4+"_"+B_VALUE); + Set<String> vals = new HashSet<String>(); + assertTrue (rs.next()); + vals.add(rs.getString(1) + "_" + rs.getString(2)); + assertTrue (rs.next()); + vals.add(rs.getString(1) + "_" + rs.getString(2)); + assertFalse(rs.next()); + assertEquals(expectedvals, vals); + } finally { + conn.close(); + } + } + + @Test + public void testDateInList() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE a_date IN (?,?) AND a_integer < 4"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setDate(1, new Date(0)); + statement.setDate(2, date); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + assertEquals(ROW1, rs.getString(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testSimpleInListStatement() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND a_integer IN (2,4)"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW2, ROW4)); + } finally { + conn.close(); + } + } + + @Test + public void testPartiallyQualifiedRVCInList() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE (a_integer,a_string) IN ((2,'a'),(5,'b'))"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW2, ROW5)); + } finally { + conn.close(); + } + } + + @Test + public void testFullyQualifiedRVCInList() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE (a_integer,a_string, organization_id,entity_id) IN ((2,'a',:1,:2),(5,'b',:1,:3))"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + statement.setString(2, ROW2); + statement.setString(3, ROW5); + ResultSet rs = statement.executeQuery(); + assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW2, ROW5)); + } finally { + conn.close(); + } + } + + @Test + public void testOneInListStatement() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND b_string IN (?)"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + statement.setString(2, E_VALUE); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + assertEquals(ROW3, rs.getString(1)); + assertTrue(rs.next()); + assertEquals(ROW6, rs.getString(1)); + assertTrue(rs.next()); + assertEquals(ROW9, rs.getString(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + + @Test + public void testMixedTypeInListStatement() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND x_long IN (5, ?)"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + long l = Integer.MAX_VALUE + 1L; + statement.setLong(2, l); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + assertEquals(ROW7, rs.getString(1)); + assertTrue(rs.next()); + assertEquals(ROW9, rs.getString(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testRowKeySingleIn() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and entity_id IN (?,?,?)"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + statement.setString(2, ROW2); + statement.setString(3, ROW6); + statement.setString(4, ROW8); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW2); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW6); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW8); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + + @Test + public void testRowKeyMultiIn() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and entity_id IN (?,?,?) and a_string IN (?,?)"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + statement.setString(2, ROW2); + statement.setString(3, ROW6); + statement.setString(4, ROW9); + statement.setString(5, B_VALUE); + statement.setString(6, C_VALUE); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW6); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW9); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/IntArithmeticIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IntArithmeticIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IntArithmeticIT.java index 0dd5f57..d21cde8 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IntArithmeticIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IntArithmeticIT.java @@ -51,7 +51,7 @@ public class IntArithmeticIT extends BaseQueryIT { super(indexDDL, mutable, columnEncoded, false); } - @Parameters(name="ClientTimeArithmeticQueryIT_{index}") // name is used by failsafe as file name in reports + @Parameters(name="IntArithmeticIT_{index}") // name is used by failsafe as file name in reports public static Collection<Object> data() { return QueryIT.data(); } @@ -165,22 +165,6 @@ public class IntArithmeticIT extends BaseQueryIT { } @Test - public void testNegateExpression() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " where A_INTEGER - 4 = -1"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(ROW3, rs.getString(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test public void testIntMultiplyExpression() throws Exception { String query = "SELECT entity_id FROM " + tableName + " where A_INTEGER * 2 = 16"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/NumericArithmeticIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NumericArithmeticIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NumericArithmeticIT.java index b1d613d..605cb5b 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NumericArithmeticIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NumericArithmeticIT.java @@ -17,6 +17,8 @@ */ package org.apache.phoenix.end2end; +import static org.apache.phoenix.util.TestUtil.A_VALUE; +import static org.apache.phoenix.util.TestUtil.B_VALUE; import static org.apache.phoenix.util.TestUtil.ROW1; import static org.apache.phoenix.util.TestUtil.ROW2; import static org.apache.phoenix.util.TestUtil.ROW3; @@ -40,6 +42,9 @@ import org.apache.phoenix.util.PropertiesUtil; import org.junit.Before; import org.junit.Test; +import com.google.common.primitives.Doubles; +import com.google.common.primitives.Floats; + public class NumericArithmeticIT extends ParallelStatsDisabledIT { private String tableName; @@ -278,4 +283,144 @@ public class NumericArithmeticIT extends ParallelStatsDisabledIT { conn.close(); } } + @Test + public void testScanByByteValue() throws Exception { + String query = "SELECT a_string, b_string, a_byte FROM " + tableName + " WHERE ?=organization_id and 1=a_byte"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, getOrganizationId()); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), A_VALUE); + assertEquals(rs.getString("B_string"), B_VALUE); + assertEquals(rs.getByte(3), 1); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testScanByShortValue() throws Exception { + String query = "SELECT a_string, b_string, a_short FROM " + tableName + " WHERE ?=organization_id and 128=a_short"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, getOrganizationId()); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), A_VALUE); + assertEquals(rs.getString("B_string"), B_VALUE); + assertEquals(rs.getShort("a_short"), 128); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testScanByFloatValue() throws Exception { + String query = "SELECT a_string, b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_float"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, getOrganizationId()); + statement.setFloat(2, 0.01f); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), A_VALUE); + assertEquals(rs.getString("B_string"), B_VALUE); + assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testScanByUnsignedFloatValue() throws Exception { + String query = "SELECT a_string, b_string, a_unsigned_float FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_float"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, getOrganizationId()); + statement.setFloat(2, 0.01f); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), A_VALUE); + assertEquals(rs.getString("B_string"), B_VALUE); + assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testScanByDoubleValue() throws Exception { + String query = "SELECT a_string, b_string, a_double FROM " + tableName + " WHERE ?=organization_id and ?=a_double"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, getOrganizationId()); + statement.setDouble(2, 0.0001); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), A_VALUE); + assertEquals(rs.getString("B_string"), B_VALUE); + assertTrue(Doubles.compare(rs.getDouble(3), 0.0001) == 0); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testScanByUnsignedDoubleValue() throws Exception { + String query = "SELECT a_string, b_string, a_unsigned_double FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_double"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, getOrganizationId()); + statement.setDouble(2, 0.0001); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), A_VALUE); + assertEquals(rs.getString("B_string"), B_VALUE); + assertTrue(Doubles.compare(rs.getDouble(3), 0.0001) == 0); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testScanWithNoWhereClause() throws Exception { + String query = "SELECT y_integer FROM " + tableName; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + for (int i =0; i < 8; i++) { + assertTrue (rs.next()); + assertEquals(0, rs.getInt(1)); + assertTrue(rs.wasNull()); + } + assertTrue (rs.next()); + assertEquals(300, rs.getInt(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + } http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java index a6d8a21..8cd153c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java @@ -17,18 +17,10 @@ */ package org.apache.phoenix.end2end; +import static org.apache.phoenix.util.TestUtil.A_VALUE; import static org.apache.phoenix.util.TestUtil.B_VALUE; import static org.apache.phoenix.util.TestUtil.C_VALUE; -import static org.apache.phoenix.util.TestUtil.E_VALUE; -import static org.apache.phoenix.util.TestUtil.ROW1; -import static org.apache.phoenix.util.TestUtil.ROW2; -import static org.apache.phoenix.util.TestUtil.ROW3; -import static org.apache.phoenix.util.TestUtil.ROW4; -import static org.apache.phoenix.util.TestUtil.ROW5; -import static org.apache.phoenix.util.TestUtil.ROW6; import static org.apache.phoenix.util.TestUtil.ROW7; -import static org.apache.phoenix.util.TestUtil.ROW8; -import static org.apache.phoenix.util.TestUtil.ROW9; import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -36,12 +28,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.sql.Connection; -import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Arrays; import java.util.Properties; import org.apache.phoenix.exception.SQLExceptionCode; @@ -61,54 +51,6 @@ public class QueryIT extends BaseQueryIT { } @Test - public void testIntFilter() throws Exception { - String updateStmt = - "upsert into " + tableName + - " (" + - " ORGANIZATION_ID, " + - " ENTITY_ID, " + - " A_INTEGER) " + - "VALUES (?, ?, ?)"; - // Override value that was set at creation time - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); - PreparedStatement stmt = conn.prepareStatement(updateStmt); - stmt.setString(1, tenantId); - stmt.setString(2, ROW4); - stmt.setInt(3, -10); - stmt.execute(); - conn.commit(); - - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer >= ?"; - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setInt(2, 7); - ResultSet rs = statement.executeQuery(); - assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW7, ROW8, ROW9)); - - query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer < 2"; - statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - rs = statement.executeQuery(); - assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW1, ROW4)); - - query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer <= 2"; - statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - rs = statement.executeQuery(); - assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW1, ROW2, ROW4)); - - query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer >=9"; - statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW9); - assertFalse(rs.next()); - conn.close(); - } - - @Test public void testToDateOnString() throws Exception { // TODO: test more conversion combinations String query = "SELECT a_string FROM " + tableName + " WHERE organization_id=? and a_integer = 5"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); @@ -145,107 +87,17 @@ public class QueryIT extends BaseQueryIT { } @Test - public void testDateInList() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE a_date IN (?,?) AND a_integer < 4"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setDate(1, new Date(0)); - statement.setDate(2, date); - ResultSet rs = statement.executeQuery(); - assertTrue(rs.next()); - assertEquals(ROW1, rs.getString(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testSimpleInListStatement() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND a_integer IN (2,4)"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW2, ROW4)); - } finally { - conn.close(); - } - } - - @Test - public void testPartiallyQualifiedRVCInList() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE (a_integer,a_string) IN ((2,'a'),(5,'b'))"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW2, ROW5)); - } finally { - conn.close(); - } - } - - @Test - public void testFullyQualifiedRVCInList() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE (a_integer,a_string, organization_id,entity_id) IN ((2,'a',:1,:2),(5,'b',:1,:3))"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setString(2, ROW2); - statement.setString(3, ROW5); - ResultSet rs = statement.executeQuery(); - assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW2, ROW5)); - } finally { - conn.close(); - } - } - - @Test - public void testOneInListStatement() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND b_string IN (?)"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setString(2, E_VALUE); - ResultSet rs = statement.executeQuery(); - assertTrue(rs.next()); - assertEquals(ROW3, rs.getString(1)); - assertTrue(rs.next()); - assertEquals(ROW6, rs.getString(1)); - assertTrue(rs.next()); - assertEquals(ROW9, rs.getString(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - - @Test - public void testMixedTypeInListStatement() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? AND x_long IN (5, ?)"; + public void testColumnAliasMapping() throws Exception { + String query = "SELECT a.a_string, " + tableName + ".b_string FROM " + tableName + " a WHERE ?=organization_id and 5=a_integer ORDER BY a_string, b_string"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(url, props); + Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); - long l = Integer.MAX_VALUE + 1L; - statement.setLong(2, l); ResultSet rs = statement.executeQuery(); - assertTrue(rs.next()); - assertEquals(ROW7, rs.getString(1)); - assertTrue(rs.next()); - assertEquals(ROW9, rs.getString(1)); + assertTrue (rs.next()); + assertEquals(rs.getString(1), B_VALUE); + assertEquals(rs.getString("B_string"), C_VALUE); assertFalse(rs.next()); } finally { conn.close(); @@ -253,85 +105,47 @@ public class QueryIT extends BaseQueryIT { } @Test - public void testValidStringConcatExpression() throws Exception {//test fails with stack overflow wee - int counter=0; - String[] answers = new String[]{"00D300000000XHP5bar","a5bar","15bar","5bar","5bar"}; - String[] queries = new String[] { - "SELECT organization_id || 5 || 'bar' FROM " + tableName + " limit 1", - "SELECT a_string || 5 || 'bar' FROM " + tableName + " order by a_string limit 1", - "SELECT a_integer||5||'bar' FROM " + tableName + " order by a_integer limit 1", - "SELECT x_decimal||5||'bar' FROM " + tableName + " limit 1", - "SELECT x_long||5||'bar' FROM " + tableName + " limit 1" - }; - - for (String query : queries) { - Properties props = new Properties(); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs=statement.executeQuery(); - assertTrue(rs.next()); - assertEquals(answers[counter++],rs.getString(1)); - assertFalse(rs.next()); - } - finally { - conn.close(); - } - } - } - - @Test - public void testRowKeySingleIn() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and entity_id IN (?,?,?)"; + public void testAllScan() throws Exception { + String query = "SELECT ALL a_string, b_string FROM " + tableName + " WHERE ?=organization_id and 5=a_integer"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); - statement.setString(2, ROW2); - statement.setString(3, ROW6); - statement.setString(4, ROW8); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW2); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW6); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW8); + assertEquals(rs.getString(1), B_VALUE); + assertEquals(rs.getString("B_string"), C_VALUE); assertFalse(rs.next()); } finally { conn.close(); } } - @Test - public void testRowKeyMultiIn() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and entity_id IN (?,?,?) and a_string IN (?,?)"; + public void testDistinctScan() throws Exception { + String query = "SELECT DISTINCT a_string FROM " + tableName + " WHERE organization_id=?"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); - statement.setString(2, ROW2); - statement.setString(3, ROW6); - statement.setString(4, ROW9); - statement.setString(5, B_VALUE); - statement.setString(6, C_VALUE); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW6); + assertEquals(rs.getString(1), A_VALUE); + assertTrue (rs.next()); + assertEquals(rs.getString(1), B_VALUE); assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW9); + assertEquals(rs.getString(1), C_VALUE); assertFalse(rs.next()); } finally { conn.close(); } } - + @Test - public void testColumnAliasMapping() throws Exception { - String query = "SELECT a.a_string, " + tableName + ".b_string FROM " + tableName + " a WHERE ?=organization_id and 5=a_integer ORDER BY a_string, b_string"; + public void testDistinctLimitScan() throws Exception { + String query = "SELECT DISTINCT a_string FROM " + tableName + " WHERE organization_id=? LIMIT 1"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -339,11 +153,11 @@ public class QueryIT extends BaseQueryIT { statement.setString(1, tenantId); ResultSet rs = statement.executeQuery(); assertTrue (rs.next()); - assertEquals(rs.getString(1), B_VALUE); - assertEquals(rs.getString("B_string"), C_VALUE); + assertEquals(rs.getString(1), A_VALUE); assertFalse(rs.next()); } finally { conn.close(); } } + } http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/RangeScanIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RangeScanIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RangeScanIT.java new file mode 100644 index 0000000..3d2e375 --- /dev/null +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RangeScanIT.java @@ -0,0 +1,281 @@ +/* + * 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 maynot 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 applicablelaw 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.apache.phoenix.util.TestUtil.B_VALUE; +import static org.apache.phoenix.util.TestUtil.C_VALUE; +import static org.apache.phoenix.util.TestUtil.ROW1; +import static org.apache.phoenix.util.TestUtil.ROW2; +import static org.apache.phoenix.util.TestUtil.ROW3; +import static org.apache.phoenix.util.TestUtil.ROW4; +import static org.apache.phoenix.util.TestUtil.ROW5; +import static org.apache.phoenix.util.TestUtil.ROW6; +import static org.apache.phoenix.util.TestUtil.ROW7; +import static org.apache.phoenix.util.TestUtil.ROW8; +import static org.apache.phoenix.util.TestUtil.ROW9; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +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.util.Arrays; +import java.util.Collection; +import java.util.Properties; + +import org.apache.phoenix.util.PropertiesUtil; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + + +@RunWith(Parameterized.class) +public class RangeScanIT extends BaseQueryIT { + + @Parameters(name="RangeScanIT_{index}") // name is used by failsafe as file name in reports + public static Collection<Object> data() { + return QueryIT.data(); + } + + public RangeScanIT(String indexDDL, boolean mutable, boolean columnEncoded) throws Exception { + super(indexDDL, mutable, columnEncoded, false); + } + + @Test + public void testNegateExpression() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " where A_INTEGER - 4 = -1"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(ROW3, rs.getString(1)); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testIntEqualityFilter() throws Exception { + String query = "SELECT a_string, /* comment ok? */ b_string FROM " + tableName + " WHERE ?=organization_id and 5=a_integer"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), B_VALUE); + assertEquals(rs.getString("B_string"), C_VALUE); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testIntRangeFilter() throws Exception { + String updateStmt = + "upsert into " + tableName + + " (" + + " ORGANIZATION_ID, " + + " ENTITY_ID, " + + " A_INTEGER) " + + "VALUES (?, ?, ?)"; + // Override value that was set at creation time + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(url, props); + PreparedStatement stmt = conn.prepareStatement(updateStmt); + stmt.setString(1, tenantId); + stmt.setString(2, ROW4); + stmt.setInt(3, -10); + stmt.execute(); + conn.commit(); + + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer >= ?"; + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + statement.setInt(2, 7); + ResultSet rs = statement.executeQuery(); + assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW7, ROW8, ROW9)); + + query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer < 2"; + statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + rs = statement.executeQuery(); + assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW1, ROW4)); + + query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer <= 2"; + statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + rs = statement.executeQuery(); + assertValueEqualsResultSet(rs, Arrays.<Object>asList(ROW1, ROW2, ROW4)); + + query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and a_integer >=9"; + statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW9); + assertFalse(rs.next()); + conn.close(); + } + + @Test + public void testUnboundRangeScan1() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id <= ?"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW1); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW2); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW3); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW4); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW5); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW6); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW7); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW8); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW9); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testUnboundRangeScan2() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id >= ?"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW1); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW2); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW3); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW4); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW5); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW6); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW7); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW8); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW9); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testUpperLowerBoundRangeScan() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and substr(entity_id,1,3) > '00A' and substr(entity_id,1,3) < '00C'"; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW5); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW6); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW7); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW8); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testUpperBoundRangeScan() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and substr(entity_id,1,3) >= '00B' "; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW5); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW6); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW7); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW8); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW9); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testLowerBoundRangeScan() throws Exception { + String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and substr(entity_id,1,3) < '00B' "; + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + statement.setString(1, tenantId); + ResultSet rs = statement.executeQuery(); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW1); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW2); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW3); + assertTrue (rs.next()); + assertEquals(rs.getString(1), ROW4); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java deleted file mode 100644 index c343e80..0000000 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ScanQueryIT.java +++ /dev/null @@ -1,443 +0,0 @@ -/* - * 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 maynot 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 applicablelaw 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.apache.phoenix.util.TestUtil.A_VALUE; -import static org.apache.phoenix.util.TestUtil.B_VALUE; -import static org.apache.phoenix.util.TestUtil.C_VALUE; -import static org.apache.phoenix.util.TestUtil.ROW1; -import static org.apache.phoenix.util.TestUtil.ROW2; -import static org.apache.phoenix.util.TestUtil.ROW3; -import static org.apache.phoenix.util.TestUtil.ROW4; -import static org.apache.phoenix.util.TestUtil.ROW5; -import static org.apache.phoenix.util.TestUtil.ROW6; -import static org.apache.phoenix.util.TestUtil.ROW7; -import static org.apache.phoenix.util.TestUtil.ROW8; -import static org.apache.phoenix.util.TestUtil.ROW9; -import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; -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.util.Collection; -import java.util.HashSet; -import java.util.Properties; -import java.util.Set; - -import org.apache.phoenix.util.PropertiesUtil; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - -import com.google.common.primitives.Doubles; -import com.google.common.primitives.Floats; - - -@RunWith(Parameterized.class) -public class ScanQueryIT extends BaseQueryIT { - - @Parameters(name="ScanQueryIT_{index}") // name is used by failsafe as file name in reports - public static Collection<Object> data() { - return QueryIT.data(); - } - - public ScanQueryIT(String indexDDL, boolean mutable, boolean columnEncoded) throws Exception { - super(indexDDL, mutable, columnEncoded, false); - } - - @Test - public void testScan() throws Exception { - String query = "SELECT a_string, /* comment ok? */ b_string FROM " + tableName + " WHERE ?=organization_id and 5=a_integer"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), B_VALUE); - assertEquals(rs.getString("B_string"), C_VALUE); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testNoWhereScan() throws Exception { - String query = "SELECT y_integer FROM " + tableName; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - for (int i =0; i < 8; i++) { - assertTrue (rs.next()); - assertEquals(0, rs.getInt(1)); - assertTrue(rs.wasNull()); - } - assertTrue (rs.next()); - assertEquals(300, rs.getInt(1)); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testScanByByteValue() throws Exception { - String query = "SELECT a_string, b_string, a_byte FROM " + tableName + " WHERE ?=organization_id and 1=a_byte"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertEquals(rs.getString("B_string"), B_VALUE); - assertEquals(rs.getByte(3), 1); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testScanByShortValue() throws Exception { - String query = "SELECT a_string, b_string, a_short FROM " + tableName + " WHERE ?=organization_id and 128=a_short"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertEquals(rs.getString("B_string"), B_VALUE); - assertEquals(rs.getShort("a_short"), 128); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testScanByFloatValue() throws Exception { - String query = "SELECT a_string, b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_float"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setFloat(2, 0.01f); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertEquals(rs.getString("B_string"), B_VALUE); - assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testScanByUnsignedFloatValue() throws Exception { - String query = "SELECT a_string, b_string, a_unsigned_float FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_float"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setFloat(2, 0.01f); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertEquals(rs.getString("B_string"), B_VALUE); - assertTrue(Floats.compare(rs.getFloat(3), 0.01f) == 0); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testScanByDoubleValue() throws Exception { - String query = "SELECT a_string, b_string, a_double FROM " + tableName + " WHERE ?=organization_id and ?=a_double"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setDouble(2, 0.0001); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertEquals(rs.getString("B_string"), B_VALUE); - assertTrue(Doubles.compare(rs.getDouble(3), 0.0001) == 0); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testScanByUnsigned_DoubleValue() throws Exception { - String query = "SELECT a_string, b_string, a_unsigned_double FROM " + tableName + " WHERE ?=organization_id and ?=a_unsigned_double"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setDouble(2, 0.0001); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertEquals(rs.getString("B_string"), B_VALUE); - assertTrue(Doubles.compare(rs.getDouble(3), 0.0001) == 0); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testAllScan() throws Exception { - String query = "SELECT ALL a_string, b_string FROM " + tableName + " WHERE ?=organization_id and 5=a_integer"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), B_VALUE); - assertEquals(rs.getString("B_string"), C_VALUE); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testDistinctScan() throws Exception { - String query = "SELECT DISTINCT a_string FROM " + tableName + " WHERE organization_id=?"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertTrue (rs.next()); - assertEquals(rs.getString(1), B_VALUE); - assertTrue (rs.next()); - assertEquals(rs.getString(1), C_VALUE); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testDistinctLimitScan() throws Exception { - String query = "SELECT DISTINCT a_string FROM " + tableName + " WHERE organization_id=? LIMIT 1"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), A_VALUE); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testInListSkipScan() throws Exception { - String query = "SELECT entity_id, b_string FROM " + tableName + " WHERE organization_id=? and entity_id IN (?,?)"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - statement.setString(2, ROW2); - statement.setString(3, ROW4); - ResultSet rs = statement.executeQuery(); - Set<String> expectedvals = new HashSet<String>(); - expectedvals.add(ROW2+"_"+C_VALUE); - expectedvals.add(ROW4+"_"+B_VALUE); - Set<String> vals = new HashSet<String>(); - assertTrue (rs.next()); - vals.add(rs.getString(1) + "_" + rs.getString(2)); - assertTrue (rs.next()); - vals.add(rs.getString(1) + "_" + rs.getString(2)); - assertFalse(rs.next()); - assertEquals(expectedvals, vals); - } finally { - conn.close(); - } - } - - @Test - public void testUnboundRangeScan1() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id <= ?"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW1); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW2); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW3); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW4); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW5); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW6); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW7); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW8); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW9); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testUnboundRangeScan2() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id >= ?"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW1); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW2); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW3); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW4); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW5); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW6); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW7); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW8); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW9); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testUpperLowerBoundRangeScan() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and substr(entity_id,1,3) > '00A' and substr(entity_id,1,3) < '00C'"; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW5); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW6); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW7); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW8); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testUpperBoundRangeScan() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and substr(entity_id,1,3) >= '00B' "; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW5); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW6); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW7); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW8); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW9); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testLowerBoundRangeScan() throws Exception { - String query = "SELECT entity_id FROM " + tableName + " WHERE organization_id=? and substr(entity_id,1,3) < '00B' "; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - statement.setString(1, tenantId); - ResultSet rs = statement.executeQuery(); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW1); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW2); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW3); - assertTrue (rs.next()); - assertEquals(rs.getString(1), ROW4); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9593529/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java index fe2e3b4..b3ae961 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/StringIT.java @@ -16,21 +16,25 @@ */ package org.apache.phoenix.end2end; +import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; import static org.junit.Assert.assertArrayEquals; 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.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; +import java.util.Properties; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.query.QueryConstants; import org.apache.phoenix.util.ByteUtil; +import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.TestUtil; import org.junit.Test; @@ -282,4 +286,33 @@ public class StringIT extends ParallelStatsDisabledIT { assertTrue(rs.wasNull()); assertFalse(rs.next()); } + + @Test + public void testValidStringConcatExpression() throws Exception {//test fails with stack overflow wee + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Date date = new Date(System.currentTimeMillis()); + Connection conn = DriverManager.getConnection(getUrl(), props); + String tableName = + initATableValues(generateUniqueName(), getOrganizationId(), getDefaultSplits(getOrganizationId()), + date, null, getUrl(), "COLUMN_ENCODED_BYTES=0"); + int counter=0; + String[] answers = new String[]{"00D300000000XHP5bar","a5bar","15bar","5bar","5bar"}; + String[] queries = new String[] { + "SELECT organization_id || 5 || 'bar' FROM " + tableName + " limit 1", + "SELECT a_string || 5 || 'bar' FROM " + tableName + " order by a_string limit 1", + "SELECT a_integer||5||'bar' FROM " + tableName + " order by a_integer limit 1", + "SELECT x_decimal||5||'bar' FROM " + tableName + " limit 1", + "SELECT x_long||5||'bar' FROM " + tableName + " limit 1" + }; + + for (String query : queries) { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs=statement.executeQuery(); + assertTrue(rs.next()); + assertEquals(answers[counter++],rs.getString(1)); + assertFalse(rs.next()); + } + conn.close(); + } + } \ No newline at end of file
