You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/03/12 23:40:01 UTC
[20/41] PHOENIX-130 Separate execution of slow (integration) tests
from fast unit tests (GabrielReid)
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/df23cf97/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
deleted file mode 100644
index 2e58067..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArithmeticQueryTest.java
+++ /dev/null
@@ -1,594 +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 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.PHOENIX_JDBC_URL;
-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.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.math.BigDecimal;
-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.SQLExceptionCode;
-import org.junit.Test;
-
-import com.google.common.primitives.Doubles;
-import com.google.common.primitives.Floats;
-
-
-public class ArithmeticQueryTest extends BaseHBaseManagedTimeTest {
-
- @Test
- public void testDecimalUpsertValue() throws Exception {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.setAutoCommit(false);
- try {
- String ddl = "CREATE TABLE testDecimalArithmetic" +
- " (pk VARCHAR NOT NULL PRIMARY KEY, " +
- "col1 DECIMAL(31,0), col2 DECIMAL(5), col3 DECIMAL(5,2), col4 DECIMAL)";
- createTestTable(getUrl(), ddl);
-
- // Test upsert correct values
- String query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3, col4) VALUES(?,?,?,?,?)";
- PreparedStatement stmt = conn.prepareStatement(query);
- stmt.setString(1, "valueOne");
- stmt.setBigDecimal(2, new BigDecimal("123456789123456789"));
- stmt.setBigDecimal(3, new BigDecimal("12345"));
- stmt.setBigDecimal(4, new BigDecimal("12.34"));
- stmt.setBigDecimal(5, new BigDecimal("12345.6789"));
- stmt.execute();
- conn.commit();
-
- query = "SELECT col1, col2, col3, col4 FROM testDecimalArithmetic WHERE pk = 'valueOne'";
- stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(new BigDecimal("123456789123456789"), rs.getBigDecimal(1));
- assertEquals(new BigDecimal("12345"), rs.getBigDecimal(2));
- assertEquals(new BigDecimal("12.34"), rs.getBigDecimal(3));
- assertEquals(new BigDecimal("12345.6789"), rs.getBigDecimal(4));
- assertFalse(rs.next());
-
- query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3) VALUES(?,?,?,?)";
- stmt = conn.prepareStatement(query);
- stmt.setString(1, "valueTwo");
- stmt.setBigDecimal(2, new BigDecimal("1234567890123456789012345678901.12345"));
- stmt.setBigDecimal(3, new BigDecimal("12345.6789"));
- stmt.setBigDecimal(4, new BigDecimal("123.45678"));
- stmt.execute();
- conn.commit();
-
- query = "SELECT col1, col2, col3 FROM testDecimalArithmetic WHERE pk = 'valueTwo'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(new BigDecimal("1234567890123456789012345678901"), rs.getBigDecimal(1));
- assertEquals(new BigDecimal("12345"), rs.getBigDecimal(2));
- assertEquals(new BigDecimal("123.45"), rs.getBigDecimal(3));
- assertFalse(rs.next());
-
- // Test upsert incorrect values and confirm exceptions would be thrown.
- try {
- query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3) VALUES(?,?,?,?)";
- stmt = conn.prepareStatement(query);
- stmt.setString(1, "badValues");
- // one more than max_precision
- stmt.setBigDecimal(2, new BigDecimal("12345678901234567890123456789012"));
- stmt.setBigDecimal(3, new BigDecimal("12345"));
- stmt.setBigDecimal(4, new BigDecimal("123.45"));
- stmt.execute();
- conn.commit();
- fail("Should have caught bad values.");
- } catch (SQLException e) {
- assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
- }
- try {
- query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3) VALUES(?,?,?,?)";
- stmt = conn.prepareStatement(query);
- stmt.setString(1, "badValues");
- stmt.setBigDecimal(2, new BigDecimal("123456"));
- // Exceeds specified precision by 1
- stmt.setBigDecimal(3, new BigDecimal("123456"));
- stmt.setBigDecimal(4, new BigDecimal("123.45"));
- stmt.execute();
- conn.commit();
- fail("Should have caught bad values.");
- } catch (SQLException e) {
- assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
- }
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testDecimalUpsertSelect() throws Exception {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.setAutoCommit(false);
- try {
- String ddl = "CREATE TABLE source" +
- " (pk VARCHAR NOT NULL PRIMARY KEY, col1 DECIMAL(5,2), col2 DECIMAL(5,1), col3 DECIMAL(5,2), col4 DECIMAL(4,4))";
- createTestTable(getUrl(), ddl);
- ddl = "CREATE TABLE target" +
- " (pk VARCHAR NOT NULL PRIMARY KEY, col1 DECIMAL(5,1), col2 DECIMAL(5,2), col3 DECIMAL(4,4))";
- createTestTable(getUrl(), ddl);
-
- String query = "UPSERT INTO source(pk, col1) VALUES(?,?)";
- PreparedStatement stmt = conn.prepareStatement(query);
- stmt.setString(1, "1");
- stmt.setBigDecimal(2, new BigDecimal("100.12"));
- stmt.execute();
- conn.commit();
- stmt.setString(1, "2");
- stmt.setBigDecimal(2, new BigDecimal("100.34"));
- stmt.execute();
- conn.commit();
-
- // Evaluated on client side.
- // source and target in different tables, values scheme compatible.
- query = "UPSERT INTO target(pk, col2) SELECT pk, col1 from source";
- stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
- query = "SELECT col2 FROM target";
- stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.12"), rs.getBigDecimal(1));
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.34"), rs.getBigDecimal(1));
- assertFalse(rs.next());
- // source and target in different tables, values requires scale chopping.
- query = "UPSERT INTO target(pk, col1) SELECT pk, col1 from source";
- stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
- query = "SELECT col1 FROM target";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.1"), rs.getBigDecimal(1));
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.3"), rs.getBigDecimal(1));
- assertFalse(rs.next());
- // source and target in different tables, values scheme incompatible.
- try {
- query = "UPSERT INTO target(pk, col3) SELECT pk, col1 from source";
- stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
- fail("Should have caught bad upsert.");
- } catch (SQLException e) {
- assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
- }
-
- // Evaluate on server side.
- conn.setAutoCommit(true);
- // source and target in same table, values scheme compatible.
- query = "UPSERT INTO source(pk, col3) SELECT pk, col1 from source";
- stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
- query = "SELECT col3 FROM source";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.12"), rs.getBigDecimal(1));
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.34"), rs.getBigDecimal(1));
- assertFalse(rs.next());
- // source and target in same table, values requires scale chopping.
- query = "UPSERT INTO source(pk, col2) SELECT pk, col1 from source";
- stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
- query = "SELECT col2 FROM source";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.1"), rs.getBigDecimal(1));
- assertTrue(rs.next());
- assertEquals(new BigDecimal("100.3"), rs.getBigDecimal(1));
- assertFalse(rs.next());
- // source and target in same table, values scheme incompatible.
- query = "UPSERT INTO source(pk, col4) SELECT pk, col1 from source";
- stmt = conn.prepareStatement(query);
- stmt.execute();
- conn.commit();
- query = "SELECT col4 FROM source";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertNull(rs.getBigDecimal(1));
- assertTrue(rs.next());
- assertNull(rs.getBigDecimal(1));
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testDecimalAveraging() throws Exception {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.setAutoCommit(false);
- try {
- String ddl = "CREATE TABLE testDecimalArithmetic" +
- " (pk VARCHAR NOT NULL PRIMARY KEY, col1 DECIMAL(31, 11), col2 DECIMAL(31,1), col3 DECIMAL(38,1))";
- createTestTable(getUrl(), ddl);
-
- String query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3) VALUES(?,?,?,?)";
- PreparedStatement stmt = conn.prepareStatement(query);
- stmt.setString(1, "1");
- stmt.setBigDecimal(2, new BigDecimal("99999999999999999999.1"));
- stmt.setBigDecimal(3, new BigDecimal("99999999999999999999.1"));
- stmt.setBigDecimal(4, new BigDecimal("9999999999999999999999999999999999999.1"));
- stmt.execute();
- conn.commit();
- stmt.setString(1, "2");
- stmt.setBigDecimal(2, new BigDecimal("0"));
- stmt.setBigDecimal(3, new BigDecimal("0"));
- stmt.setBigDecimal(4, new BigDecimal("0"));
- stmt.execute();
- conn.commit();
- stmt.setString(1, "3");
- stmt.setBigDecimal(2, new BigDecimal("0"));
- stmt.setBigDecimal(3, new BigDecimal("0"));
- stmt.setBigDecimal(4, new BigDecimal("0"));
- stmt.execute();
- conn.commit();
-
- // Averaging
- // result scale should be: max(max(ls, rs), 4).
- // We are not imposing restriction on precisioin.
- query = "SELECT avg(col1) FROM testDecimalArithmetic";
- stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
- assertTrue(rs.next());
- BigDecimal result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("33333333333333333333.03333333333"), result);
-
- query = "SELECT avg(col2) FROM testDecimalArithmetic";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("33333333333333333333.0333"), result);
-
- // We cap our decimal to a precision of 38.
- query = "SELECT avg(col3) FROM testDecimalArithmetic";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("3333333333333333333333333333333333333"), result);
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testDecimalArithmeticWithIntAndLong() throws Exception {
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.setAutoCommit(false);
- try {
- String ddl = "CREATE TABLE testDecimalArithmetic" +
- " (pk VARCHAR NOT NULL PRIMARY KEY, " +
- "col1 DECIMAL(38,0), col2 DECIMAL(5, 2), col3 INTEGER, col4 BIGINT, col5 DECIMAL)";
- createTestTable(getUrl(), ddl);
-
- String query = "UPSERT INTO testDecimalArithmetic(pk, col1, col2, col3, col4, col5) VALUES(?,?,?,?,?,?)";
- PreparedStatement stmt = conn.prepareStatement(query);
- stmt.setString(1, "testValueOne");
- stmt.setBigDecimal(2, new BigDecimal("1234567890123456789012345678901"));
- stmt.setBigDecimal(3, new BigDecimal("123.45"));
- stmt.setInt(4, 10);
- stmt.setLong(5, 10L);
- stmt.setBigDecimal(6, new BigDecimal("111.111"));
- stmt.execute();
- conn.commit();
-
- stmt.setString(1, "testValueTwo");
- stmt.setBigDecimal(2, new BigDecimal("12345678901234567890123456789012345678"));
- stmt.setBigDecimal(3, new BigDecimal("123.45"));
- stmt.setInt(4, 10);
- stmt.setLong(5, 10L);
- stmt.setBigDecimal(6, new BigDecimal("123456789.0123456789"));
- stmt.execute();
- conn.commit();
-
- // INT has a default precision and scale of (10, 0)
- // LONG has a default precision and scale of (19, 0)
- query = "SELECT col1 + col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
- assertTrue(rs.next());
- BigDecimal result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1234567890123456789012345678911"), result);
-
- query = "SELECT col1 + col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1234567890123456789012345678911"), result);
-
- query = "SELECT col2 + col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("133.45"), result);
-
- query = "SELECT col2 + col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("133.45"), result);
-
- query = "SELECT col5 + col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("121.111"), result);
-
- query = "SELECT col5 + col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("121.111"), result);
-
- query = "SELECT col1 - col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1234567890123456789012345678891"), result);
-
- query = "SELECT col1 - col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1234567890123456789012345678891"), result);
-
- query = "SELECT col2 - col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("113.45"), result);
-
- query = "SELECT col2 - col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("113.45"), result);
-
- query = "SELECT col5 - col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("101.111"), result);
-
- query = "SELECT col5 - col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("101.111"), result);
-
- query = "SELECT col1 * col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1.234567890123456789012345678901E+31"), result);
-
- query = "SELECT col1 * col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1.234567890123456789012345678901E+31"), result);
-
- query = "SELECT col1 * col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1.234567890123456789012345678901E+31"), result);
-
- try {
- query = "SELECT col1 * col3 FROM testDecimalArithmetic WHERE pk='testValueTwo'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- fail("Should have caught error.");
- } catch (SQLException e) {
- assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
- }
-
- try {
- query = "SELECT col1 * col4 FROM testDecimalArithmetic WHERE pk='testValueTwo'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- fail("Should have caught error.");
- } catch (SQLException e) {
- assertEquals(SQLExceptionCode.DATA_EXCEEDS_MAX_CAPACITY.getErrorCode(),e.getErrorCode());
- }
-
- query = "SELECT col4 * col5 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(0, result.compareTo(new BigDecimal("1111.11")));
-
- query = "SELECT col3 * col5 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(0, result.compareTo(new BigDecimal("1111.11")));
-
- query = "SELECT col2 * col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1234.5"), result);
-
- // Result scale has value of 0
- query = "SELECT col1 / col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1.2345678901234567890123456789E+29"), result);
-
- query = "SELECT col1 / col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("1.2345678901234567890123456789E+29"), result);
-
- // Result scale is 2.
- query = "SELECT col2 / col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("12.34"), result);
-
- query = "SELECT col2 / col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("12.34"), result);
-
- // col5 has NO_SCALE, so the result's scale is not expected to be truncated to col5 value's scale of 4
- query = "SELECT col5 / col3 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("11.1111"), result);
-
- query = "SELECT col5 / col4 FROM testDecimalArithmetic WHERE pk='testValueOne'";
- stmt = conn.prepareStatement(query);
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- result = rs.getBigDecimal(1);
- assertEquals(new BigDecimal("11.1111"), result);
- } finally {
- conn.close();
- }
- }
- @Test
- public void testSumDouble() throws Exception {
- initSumDoubleValues(null);
- String query = "SELECT SUM(d) FROM SumDoubleTest";
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue (rs.next());
- assertTrue(Doubles.compare(rs.getDouble(1), 0.015)==0);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSumUnsignedDouble() throws Exception {
- initSumDoubleValues(null);
- String query = "SELECT SUM(ud) FROM SumDoubleTest";
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue (rs.next());
- assertTrue(Doubles.compare(rs.getDouble(1), 0.015)==0);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSumFloat() throws Exception {
- initSumDoubleValues(null);
- String query = "SELECT SUM(f) FROM SumDoubleTest";
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue (rs.next());
- assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSumUnsignedFloat() throws Exception {
- initSumDoubleValues(null);
- String query = "SELECT SUM(uf) FROM SumDoubleTest";
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue (rs.next());
- assertTrue(Floats.compare(rs.getFloat(1), 0.15f)==0);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/df23cf97/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
deleted file mode 100644
index 71e819f..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/ArrayTest.java
+++ /dev/null
@@ -1,1240 +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 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.PHOENIX_JDBC_URL;
-import static org.apache.phoenix.util.TestUtil.ROW1;
-import static org.apache.phoenix.util.TestUtil.TABLE_WITH_ARRAY;
-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.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.sql.Array;
-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.Properties;
-
-import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.schema.PhoenixArray;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.StringUtil;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.google.common.primitives.Floats;
-
-public class ArrayTest extends BaseClientManagedTimeTest {
-
- private static final String SIMPLE_TABLE_WITH_ARRAY = "SIMPLE_TABLE_WITH_ARRAY";
-
- @Test
- public void testScanByArrayValue() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array, /* comment ok? */ b_string, a_float FROM table_with_array WHERE ?=organization_id and ?=a_float";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- statement.setString(1, tenantId);
- statement.setFloat(2, 0.01f);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[4];
- doubleArr[0] = 25.343;
- doubleArr[1] = 36.763;
- doubleArr[2] = 37.56;
- doubleArr[3] = 386.63;
- Array array = conn.createArrayOf("DOUBLE",
- doubleArr);
- PhoenixArray resultArray = (PhoenixArray) rs.getArray(1);
- assertEquals(resultArray, array);
- 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 testScanWithArrayInWhereClause() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array, /* comment ok? */ b_string, a_float FROM table_with_array WHERE ?=organization_id and ?=a_byte_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- statement.setString(1, tenantId);
- // Need to support primitive
- Byte[] byteArr = new Byte[2];
- byteArr[0] = 25;
- byteArr[1] = 36;
- Array array = conn.createArrayOf("TINYINT", byteArr);
- statement.setArray(2, array);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[4];
- doubleArr[0] = 25.343;
- doubleArr[1] = 36.763;
- doubleArr[2] = 37.56;
- doubleArr[3] = 386.63;
- array = conn.createArrayOf("DOUBLE", doubleArr);
- Array resultArray = rs.getArray(1);
- assertEquals(resultArray, array);
- 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 testScanWithNonFixedWidthArrayInWhereClause() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array, /* comment ok? */ b_string, a_float FROM table_with_array WHERE ?=organization_id and ?=a_string_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- statement.setString(1, tenantId);
- // Need to support primitive
- String[] strArr = new String[4];
- strArr[0] = "ABC";
- strArr[1] = "CEDF";
- strArr[2] = "XYZWER";
- strArr[3] = "AB";
- Array array = conn.createArrayOf("VARCHAR", strArr);
- statement.setArray(2, array);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[4];
- doubleArr[0] = 25.343;
- doubleArr[1] = 36.763;
- doubleArr[2] = 37.56;
- doubleArr[3] = 386.63;
- array = conn.createArrayOf("DOUBLE", doubleArr);
- Array resultArray = rs.getArray(1);
- assertEquals(resultArray, array);
- 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 testScanWithNonFixedWidthArrayInSelectClause() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_string_array FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[4];
- strArr[0] = "ABC";
- strArr[1] = "CEDF";
- strArr[2] = "XYZWER";
- strArr[3] = "AB";
- Array array = conn.createArrayOf("VARCHAR", strArr);
- PhoenixArray resultArray = (PhoenixArray) rs.getArray(1);
- assertEquals(resultArray, array);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSpecificIndexOfAnArrayAsArrayFunction()
- throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT ARRAY_ELEM(a_double_array,2) FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 36.763;
- conn.createArrayOf("DOUBLE", doubleArr);
- Double result = rs.getDouble(1);
- assertEquals(doubleArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSpecificIndexOfAnArray() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array[3] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 37.56;
- Double result = rs.getDouble(1);
- assertEquals(doubleArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testCaseWithArray() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT CASE WHEN A_INTEGER = 1 THEN a_double_array ELSE null END [3] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 37.56;
- Double result = rs.getDouble(1);
- assertEquals(doubleArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testUpsertValuesWithArray() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_double_array) values('" + tenantId
- + "','00A123122312312',ARRAY[2.0d,345.8d])";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute
- // at
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- int executeUpdate = statement.executeUpdate();
- assertEquals(1, executeUpdate);
- conn.commit();
- statement.close();
- conn.close();
- // create another connection
- props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- query = "SELECT ARRAY_ELEM(a_double_array,2) FROM table_with_array";
- statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 345.8d;
- conn.createArrayOf("DOUBLE", doubleArr);
- Double result = rs.getDouble(1);
- assertEquals(doubleArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testUpsertSelectWithSelectAsSubQuery1() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- Connection conn = null;
- try {
- createSimpleTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(tenantId, null, ts, false);
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID,a_double_array) "
- + "SELECT organization_id, entity_id, a_double_array FROM " + SIMPLE_TABLE_WITH_ARRAY
- + " WHERE a_double_array[2] = 89.96d";
- PreparedStatement statement = conn.prepareStatement(query);
- int executeUpdate = statement.executeUpdate();
- assertEquals(1, executeUpdate);
- conn.commit();
- statement.close();
- conn.close();
- // create another connection
- props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
- conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- query = "SELECT ARRAY_ELEM(a_double_array,2) FROM table_with_array";
- statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 89.96d;
- Double result = rs.getDouble(1);
- assertEquals(result, doubleArr[0]);
- assertFalse(rs.next());
-
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
- }
-
- @Test
- public void testSelectWithArrayWithColumnRef() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_integer,ARRAY[1,2,a_integer] FROM table_with_array where organization_id = '"
- + tenantId + "'";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- int val = rs.getInt(1);
- assertEquals(val, 1);
- Array array = rs.getArray(2);
- // Need to support primitive
- Integer[] intArr = new Integer[3];
- intArr[0] = 1;
- intArr[1] = 2;
- intArr[2] = 1;
- Array resultArr = conn.createArrayOf("INTEGER", intArr);
- assertEquals(resultArr, array);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectWithArrayWithColumnRefWithVarLengthArray() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT b_string,ARRAY['abc','defgh',b_string] FROM table_with_array where organization_id = '"
- + tenantId + "'";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String val = rs.getString(1);
- assertEquals(val, "b");
- Array array = rs.getArray(2);
- // Need to support primitive
- String[] strArr = new String[3];
- strArr[0] = "abc";
- strArr[1] = "defgh";
- strArr[2] = "b";
- Array resultArr = conn.createArrayOf("VARCHAR", strArr);
- assertEquals(resultArr, array);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectWithArrayWithColumnRefWithVarLengthArrayWithNullValue() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT b_string,ARRAY['abc',null,'bcd',null,null,b_string] FROM table_with_array where organization_id = '"
- + tenantId + "'";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String val = rs.getString(1);
- assertEquals(val, "b");
- Array array = rs.getArray(2);
- // Need to support primitive
- String[] strArr = new String[6];
- strArr[0] = "abc";
- strArr[1] = null;
- strArr[2] = "bcd";
- strArr[3] = null;
- strArr[4] = null;
- strArr[5] = "b";
- Array resultArr = conn.createArrayOf("VARCHAR", strArr);
- assertEquals(resultArr, array);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testUpsertSelectWithColumnRef() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- Connection conn = null;
- try {
- createSimpleTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(tenantId, null, ts, false);
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- String query = "upsert into table_with_array(ORGANIZATION_ID,ENTITY_ID, a_unsigned_double, a_double_array) "
- + "SELECT organization_id, entity_id, x_double, ARRAY[23.4d, 22.1d, x_double] FROM " + SIMPLE_TABLE_WITH_ARRAY
- + " WHERE a_double_array[2] = 89.96d";
- PreparedStatement statement = conn.prepareStatement(query);
- int executeUpdate = statement.executeUpdate();
- assertEquals(1, executeUpdate);
- conn.commit();
- statement.close();
- conn.close();
- // create another connection
- props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
- conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- query = "SELECT ARRAY_ELEM(a_double_array,2) FROM table_with_array";
- statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 22.1d;
- Double result = rs.getDouble(1);
- assertEquals(result, doubleArr[0]);
- assertFalse(rs.next());
-
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
- }
-
- @Test
- public void testCharArraySpecificIndex() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createSimpleTableWithArray(BaseConnectedQueryTest.getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(tenantId, null, ts, false);
- String query = "SELECT a_char_array[2] FROM SIMPLE_TABLE_WITH_ARRAY";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] charArr = new String[1];
- charArr[0] = "b";
- String result = rs.getString(1);
- assertEquals(charArr[0], result);
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testFixedWidthCharArray() throws Exception {
- Connection conn;
- PreparedStatement stmt;
- ResultSet rs;
-
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE TABLE t ( k VARCHAR PRIMARY KEY, a CHAR(5) ARRAY)");
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
- conn = DriverManager.getConnection(getUrl(), props);
- rs = conn.getMetaData().getColumns(null, null, "T", "A");
- assertTrue(rs.next());
- assertEquals(5, rs.getInt("COLUMN_SIZE"));
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?)");
- stmt.setString(1, "a");
- String[] s = new String[] {"1","2"};
- Array array = conn.createArrayOf("CHAR", s);
- stmt.setArray(2, array);
- stmt.execute();
- conn.commit();
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- rs = conn.createStatement().executeQuery("SELECT k, a[2] FROM t");
- assertTrue(rs.next());
- assertEquals("a",rs.getString(1));
- assertEquals("2",rs.getString(2));
- conn.close();
-
- }
-
- @Test
- public void testSelectArrayUsingUpsertLikeSyntax() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array FROM TABLE_WITH_ARRAY WHERE a_double_array = ARRAY [ 25.343d, 36.763d, 37.56d,386.63d]";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- Double[] doubleArr = new Double[4];
- doubleArr[0] = 25.343;
- doubleArr[1] = 36.763;
- doubleArr[2] = 37.56;
- doubleArr[3] = 386.63;
- Array array = conn.createArrayOf("DOUBLE", doubleArr);
- PhoenixArray resultArray = (PhoenixArray) rs.getArray(1);
- assertEquals(resultArray, array);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testArrayIndexUsedInWhereClause() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- int a_index = 0;
- String query = "SELECT a_double_array[2] FROM table_with_array where a_double_array["+a_index+"2]<?";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 40.0;
- conn.createArrayOf("DOUBLE", doubleArr);
- statement.setDouble(1, 40.0d);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- // Need to support primitive
- doubleArr = new Double[1];
- doubleArr[0] = 36.763;
- Double result = rs.getDouble(1);
- assertEquals(doubleArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testArrayIndexUsedInGroupByClause() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array[2] FROM table_with_array GROUP BY a_double_array[2]";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 40.0;
- conn.createArrayOf("DOUBLE", doubleArr);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- doubleArr = new Double[1];
- doubleArr[0] = 36.763;
- Double result = rs.getDouble(1);
- assertEquals(doubleArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testVariableLengthArrayWithNullValue() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, true);
- String query = "SELECT a_string_array[2] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[1];
- strArr[0] = "XYZWER";
- String result = rs.getString(1);
- assertNull(result);
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSpecificIndexOfAVariableArrayAlongWithAnotherColumn1() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_string_array[3],A_INTEGER FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[1];
- strArr[0] = "XYZWER";
- String result = rs.getString(1);
- assertEquals(strArr[0], result);
- int a_integer = rs.getInt(2);
- assertEquals(1, a_integer);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSpecificIndexOfAVariableArrayAlongWithAnotherColumn2() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT A_INTEGER, a_string_array[3] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[1];
- strArr[0] = "XYZWER";
- int a_integer = rs.getInt(1);
- assertEquals(1, a_integer);
- String result = rs.getString(2);
- assertEquals(strArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectMultipleArrayColumns() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_string_array[3], a_double_array[2] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[1];
- strArr[0] = "XYZWER";
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 36.763d;
- Double a_double = rs.getDouble(2);
- assertEquals(doubleArr[0], a_double);
- String result = rs.getString(1);
- assertEquals(strArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSameArrayColumnMultipleTimesWithDifferentIndices() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_string_array[1], a_string_array[3] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[2];
- strArr[0] = "ABC";
- strArr[1] = "XYZWER";
- String result = rs.getString(1);
- assertEquals(strArr[0], result);
- result = rs.getString(2);
- assertEquals(strArr[1], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSameArrayColumnMultipleTimesWithSameIndices() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_string_array[3], a_string_array[3] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[1];
- strArr[0] = "XYZWER";
- String result = rs.getString(1);
- assertEquals(strArr[0], result);
- result = rs.getString(2);
- assertEquals(strArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testSelectSpecificIndexOfAVariableArray() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_string_array[3] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- String[] strArr = new String[1];
- strArr[0] = "XYZWER";
- String result = rs.getString(1);
- assertEquals(strArr[0], result);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testWithOutOfRangeIndex() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT a_double_array[100] FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- Double[] doubleArr = new Double[1];
- doubleArr[0] = 36.763;
- Array array = conn.createArrayOf("DOUBLE", doubleArr);
- PhoenixArray resultArray = (PhoenixArray) rs.getArray(1);
- assertEquals(resultArray, array);
- Assert.fail("Should have failed");
- } catch (Exception e) {
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testArrayLengthFunctionForVariableLength() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT ARRAY_LENGTH(a_string_array) FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- int result = rs.getInt(1);
- assertEquals(result, 4);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
-
- @Test
- public void testArrayLengthFunctionForFixedLength() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tenantId, null, ts, false);
- String query = "SELECT ARRAY_LENGTH(a_double_array) FROM table_with_array";
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- PreparedStatement statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertTrue(rs.next());
- int result = rs.getInt(1);
- assertEquals(result, 4);
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testArraySizeRoundtrip() throws Exception {
- long ts = nextTimestamp();
- String tenantId = getOrganizationId();
- createTableWithArray(BaseConnectedQueryTest.getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
- try {
- ResultSet rs = conn.getMetaData().getColumns(null, null, StringUtil.escapeLike(TABLE_WITH_ARRAY), StringUtil.escapeLike(SchemaUtil.normalizeIdentifier("x_long_array")));
- assertTrue(rs.next());
- assertEquals(5, rs.getInt("ARRAY_SIZE"));
- assertFalse(rs.next());
-
- rs = conn.getMetaData().getColumns(null, null, StringUtil.escapeLike(TABLE_WITH_ARRAY), StringUtil.escapeLike(SchemaUtil.normalizeIdentifier("a_string_array")));
- assertTrue(rs.next());
- assertEquals(3, rs.getInt("ARRAY_SIZE"));
- assertFalse(rs.next());
-
- rs = conn.getMetaData().getColumns(null, null, StringUtil.escapeLike(TABLE_WITH_ARRAY), StringUtil.escapeLike(SchemaUtil.normalizeIdentifier("a_double_array")));
- assertTrue(rs.next());
- assertEquals(0, rs.getInt("ARRAY_SIZE"));
- assertTrue(rs.wasNull());
- assertFalse(rs.next());
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testVarLengthArrComparisonInWhereClauseWithSameArrays() throws Exception {
- Connection conn;
- PreparedStatement stmt;
- ResultSet rs;
-
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement()
- .execute(
- "CREATE TABLE t_same_size ( k VARCHAR PRIMARY KEY, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO t_same_size VALUES(?,?,?)");
- stmt.setString(1, "a");
- String[] s = new String[] {"abc","def", "ghi","jkl"};
- Array array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(2, array);
- s = new String[] {"abc","def", "ghi","jkl"};
- array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(3, array);
- stmt.execute();
- conn.commit();
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- rs = conn.createStatement().executeQuery("SELECT k, a_string_array[2] FROM t_same_size where a_string_array=b_string_array");
- assertTrue(rs.next());
- assertEquals("a",rs.getString(1));
- assertEquals("def",rs.getString(2));
- conn.close();
- }
-
- @Test
- public void testVarLengthArrComparisonInWhereClauseWithDiffSizeArrays() throws Exception {
- Connection conn;
- PreparedStatement stmt;
- ResultSet rs;
-
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement()
- .execute(
- "CREATE TABLE t ( k VARCHAR PRIMARY KEY, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
- conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
- stmt.setString(1, "a");
- String[] s = new String[] { "abc", "def", "ghi", "jkll" };
- Array array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(2, array);
- s = new String[] { "abc", "def", "ghi", "jklm" };
- array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(3, array);
- stmt.execute();
- conn.commit();
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- rs = conn.createStatement().executeQuery(
- "SELECT k, a_string_array[2] FROM t where a_string_array<b_string_array");
- assertTrue(rs.next());
- assertEquals("a", rs.getString(1));
- assertEquals("def", rs.getString(2));
- conn.close();
- }
-
- @Test
- public void testVarLengthArrComparisonWithNulls() throws Exception {
- Connection conn;
- PreparedStatement stmt;
- ResultSet rs;
-
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement()
- .execute(
- "CREATE TABLE t ( k VARCHAR PRIMARY KEY, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4])");
- conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
- stmt.setString(1, "a");
- String[] s = new String[] { "abc", "def", "ghi", "jkll", null, null, "xxx" };
- Array array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(2, array);
- s = new String[] { "abc", "def", "ghi", "jkll", null, null, null, "xxx" };
- array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(3, array);
- stmt.execute();
- conn.commit();
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- rs = conn.createStatement().executeQuery(
- "SELECT k, a_string_array[2] FROM t where a_string_array>b_string_array");
- assertTrue(rs.next());
- assertEquals("a", rs.getString(1));
- assertEquals("def", rs.getString(2));
- conn.close();
- }
-
- @Test
- public void testPKWithArray() throws Exception {
- Connection conn;
- PreparedStatement stmt;
- ResultSet rs;
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement()
- .execute(
- "CREATE TABLE t ( k VARCHAR, a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4] \n"
- + " CONSTRAINT pk PRIMARY KEY (k, b_string_array)) \n");
- conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO t VALUES(?,?,?)");
- stmt.setString(1, "a");
- String[] s = new String[] { "abc", "def", "ghi", "jkll", null, null, "xxx" };
- Array array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(2, array);
- s = new String[] { "abc", "def", "ghi", "jkll", null, null, null, "xxx" };
- array = conn.createArrayOf("VARCHAR", s);
- stmt.setArray(3, array);
- stmt.execute();
- conn.commit();
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- rs = conn.createStatement().executeQuery(
- "SELECT k, a_string_array[2] FROM t where b_string_array[8]='xxx'");
- assertTrue(rs.next());
- assertEquals("a", rs.getString(1));
- assertEquals("def", rs.getString(2));
- conn.close();
- }
-
- @Test
- public void testPKWithArrayNotInEnd() throws Exception {
- Connection conn;
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- try {
- conn.createStatement().execute(
- "CREATE TABLE t ( a_string_array VARCHAR(100) ARRAY[4], b_string_array VARCHAR(100) ARRAY[4], k VARCHAR \n"
- + " CONSTRAINT pk PRIMARY KEY (b_string_array, k))");
- conn.close();
- fail();
- } catch (SQLException e) {
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
-
- }
-
- @Test
- public void testArrayRefToLiteral() throws Exception {
- Connection conn;
- long ts = nextTimestamp();
- Properties props = new Properties(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- conn = DriverManager.getConnection(getUrl(), props);
- try {
- PreparedStatement stmt = conn.prepareStatement("select ?[2] from system.\"catalog\" limit 1");
- Array array = conn.createArrayOf("CHAR", new String[] {"a","b","c"});
- stmt.setArray(1, array);
- ResultSet rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals("b", rs.getString(1));
- assertFalse(rs.next());
- } catch (SQLException e) {
- } finally {
- if (conn != null) {
- conn.close();
- }
- }
-
- }
-
- static void createTableWithArray(String url, byte[][] bs, Object object,
- long ts) throws SQLException {
- String ddlStmt = "create table "
- + TABLE_WITH_ARRAY
- + " (organization_id char(15) not null, \n"
- + " entity_id char(15) not null,\n"
- + " a_string_array varchar(100) array[3],\n"
- + " b_string varchar(100),\n"
- + " a_integer integer,\n"
- + " a_date date,\n"
- + " a_time time,\n"
- + " a_timestamp timestamp,\n"
- + " x_decimal decimal(31,10),\n"
- + " x_long_array bigint[5],\n"
- + " x_integer integer,\n"
- + " a_byte_array tinyint array,\n"
- + " a_short smallint,\n"
- + " a_float float,\n"
- + " a_double_array double array[],\n"
- + " a_unsigned_float unsigned_float,\n"
- + " a_unsigned_double unsigned_double \n"
- + " CONSTRAINT pk PRIMARY KEY (organization_id, entity_id)\n"
- + ")";
- BaseTest.createTestTable(url, ddlStmt, bs, ts);
- }
-
- static void createSimpleTableWithArray(String url, byte[][] bs, Object object,
- long ts) throws SQLException {
- String ddlStmt = "create table "
- + SIMPLE_TABLE_WITH_ARRAY
- + " (organization_id char(15) not null, \n"
- + " entity_id char(15) not null,\n"
- + " x_double double,\n"
- + " a_double_array double array[],\n"
- + " a_char_array char(5) array[],\n"
- + " CONSTRAINT pk PRIMARY KEY (organization_id, entity_id)\n"
- + ")";
- BaseTest.createTestTable(url, ddlStmt, bs, ts);
- }
-
- protected static void initSimpleArrayTable(String tenantId, Date date, Long ts, boolean useNull) throws Exception {
- Properties props = new Properties();
- if (ts != null) {
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, ts.toString());
- }
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- // Insert all rows at ts
- PreparedStatement stmt = conn.prepareStatement(
- "upsert into " +SIMPLE_TABLE_WITH_ARRAY+
- "(" +
- " ORGANIZATION_ID, " +
- " ENTITY_ID, " +
- " x_double, " +
- " a_double_array, a_char_array)" +
- "VALUES (?, ?, ?, ?, ?)");
- stmt.setString(1, tenantId);
- stmt.setString(2, ROW1);
- stmt.setDouble(3, 1.2d);
- // Need to support primitive
- Double[] doubleArr = new Double[2];
- doubleArr[0] = 64.87;
- doubleArr[1] = 89.96;
- //doubleArr[2] = 9.9;
- Array array = conn.createArrayOf("DOUBLE", doubleArr);
- stmt.setArray(4, array);
-
- // create character array
- String[] charArr = new String[2];
- charArr[0] = "a";
- charArr[1] = "b";
- array = conn.createArrayOf("CHAR", charArr);
- stmt.setArray(5, array);
- stmt.execute();
-
- conn.commit();
- } finally {
- conn.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/df23cf97/phoenix-core/src/test/java/org/apache/phoenix/end2end/AutoCommitTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/AutoCommitTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/AutoCommitTest.java
deleted file mode 100644
index ae9be62..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/AutoCommitTest.java
+++ /dev/null
@@ -1,81 +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 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.*;
-import static org.junit.Assert.*;
-
-import java.sql.*;
-import java.util.Properties;
-
-import org.junit.Test;
-
-
-public class AutoCommitTest extends BaseHBaseManagedTimeTest {
-
- @Test
- public void testMutationJoin() throws Exception {
-
- Properties props = new Properties(TEST_PROPERTIES);
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.setAutoCommit(true);
-
- String ddl = "CREATE TABLE test_table " +
- " (row varchar not null, col1 integer" +
- " CONSTRAINT pk PRIMARY KEY (row))\n";
- createTestTable(getUrl(), ddl);
-
- String query = "UPSERT INTO test_table(row, col1) VALUES('row1', 1)";
- PreparedStatement statement = conn.prepareStatement(query);
- statement.executeUpdate();
- conn.commit();
-
- conn.setAutoCommit(false);
- query = "UPSERT INTO test_table(row, col1) VALUES('row1', 2)";
- statement = conn.prepareStatement(query);
- statement.executeUpdate();
-
- query = "DELETE FROM test_table WHERE row='row1'";
- statement = conn.prepareStatement(query);
- statement.executeUpdate();
- conn.commit();
-
- query = "SELECT * FROM test_table";
- statement = conn.prepareStatement(query);
- ResultSet rs = statement.executeQuery();
- assertFalse(rs.next());
-
- query = "DELETE FROM test_table WHERE row='row1'";
- statement = conn.prepareStatement(query);
- statement.executeUpdate();
-
- query = "UPSERT INTO test_table(row, col1) VALUES('row1', 3)";
- statement = conn.prepareStatement(query);
- statement.executeUpdate();
- conn.commit();
-
- query = "SELECT * FROM test_table";
- statement = conn.prepareStatement(query);
- rs = statement.executeQuery();
- assertTrue(rs.next());
- assertEquals("row1", rs.getString(1));
- assertEquals(3, rs.getInt(2));
-
- conn.close();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/df23cf97/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseClientManagedTimeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseClientManagedTimeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseClientManagedTimeTest.java
deleted file mode 100644
index ad678a4..0000000
--- a/phoenix-core/src/test/java/org/apache/phoenix/end2end/BaseClientManagedTimeTest.java
+++ /dev/null
@@ -1,41 +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 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 org.junit.Before;
-
-/**
- *
- * Base class for tests that manage their own time stamps
- * We need to separate these from tests that manged the time stamp
- * themselves, because we create/destroy the Phoenix tables
- * between tests and only allow a table time stamp to increase.
- * If we let HBase set the time stamps, then our client time stamps
- * will usually be smaller than these time stamps and the table
- * deletion/creation would fail.
- *
- *
- * @since 0.1
- */
-public abstract class BaseClientManagedTimeTest extends BaseConnectedQueryTest {
- @Before
- public void doTestSetup() throws Exception {
- long ts = nextTimestamp();
- deletePriorTables(ts-1);
- }
-}