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 22:32:01 UTC
[34/41] PHOENIX-130 Separate execution of slow (integration) tests
from fast unit tests (Gabriel Reid)
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
new file mode 100644
index 0000000..3275999
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java
@@ -0,0 +1,40 @@
+/*
+ * 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 java.util.Map;
+
+import org.junit.BeforeClass;
+
+import com.google.common.collect.Maps;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.ReadOnlyProps;
+
+public class InMemoryOrderByIT extends OrderByIT {
+
+ public InMemoryOrderByIT() {
+ }
+
+ @BeforeClass
+ public static void doSetup() throws Exception {
+ Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
+ props.put(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(1024*1024));
+ // Must update config before starting server
+ startServer(getUrl(), new ReadOnlyProps(props.entrySet().iterator()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
new file mode 100644
index 0000000..d9d8364
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IsNullIT.java
@@ -0,0 +1,65 @@
+/*
+ * 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.junit.Assert.*;
+
+import java.sql.*;
+import java.util.Properties;
+
+import org.junit.Test;
+
+import org.apache.phoenix.util.PhoenixRuntime;
+
+
+public class IsNullIT extends BaseClientManagedTimeIT {
+ @Test
+ public void testIsNullInPk() throws Exception {
+ long ts = nextTimestamp();
+ ensureTableCreated(getUrl(),"IntIntKeyTest",null, ts-2);
+ Properties props = new Properties();
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 1)); // Execute at timestamp 1
+ Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
+ String upsert = "UPSERT INTO IntIntKeyTest VALUES(4,2)";
+ PreparedStatement upsertStmt = conn.prepareStatement(upsert);
+ int rowsInserted = upsertStmt.executeUpdate();
+ assertEquals(1, rowsInserted);
+ upsert = "UPSERT INTO IntIntKeyTest VALUES(6)";
+ upsertStmt = conn.prepareStatement(upsert);
+ rowsInserted = upsertStmt.executeUpdate();
+ assertEquals(1, rowsInserted);
+ conn.commit();
+ conn.close();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 1
+ conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props);
+ String select = "SELECT i/j FROM IntIntKeyTest WHERE j IS NULL";
+ ResultSet rs;
+ rs = conn.createStatement().executeQuery(select);
+ assertTrue(rs.next());
+ assertEquals(0,rs.getInt(1));
+ assertTrue(rs.wasNull());
+ assertFalse(rs.next());
+ select = "SELECT i/j FROM IntIntKeyTest WHERE j IS NOT NULL";
+ rs = conn.createStatement().executeQuery(select);
+ assertTrue(rs.next());
+ assertEquals(2,rs.getInt(1));
+ assertFalse(rs.next());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
new file mode 100644
index 0000000..36c89f0
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
@@ -0,0 +1,146 @@
+/*
+ * 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.KEYONLY_NAME;
+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.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Properties;
+
+import org.junit.Test;
+
+import org.apache.phoenix.util.PhoenixRuntime;
+
+
+public class KeyOnlyIT extends BaseClientManagedTimeIT {
+ @Test
+ public void testKeyOnly() throws Exception {
+ long ts = nextTimestamp();
+ ensureTableCreated(getUrl(),KEYONLY_NAME,null, ts);
+ initTableValues(ts+1);
+ Properties props = new Properties();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+5));
+ Connection conn5 = DriverManager.getConnection(getUrl(), props);
+ String query = "SELECT i1, i2 FROM KEYONLY";
+ PreparedStatement statement = conn5.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ assertEquals(2, rs.getInt(2));
+ assertTrue(rs.next());
+ assertEquals(3, rs.getInt(1));
+ assertEquals(4, rs.getInt(2));
+ assertFalse(rs.next());
+ conn5.close();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+6));
+ Connection conn6 = DriverManager.getConnection(getUrl(), props);
+ conn6.createStatement().execute("ALTER TABLE KEYONLY ADD s1 varchar");
+ conn6.close();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+7));
+ Connection conn7 = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn7.prepareStatement(
+ "upsert into " +
+ "KEYONLY VALUES (?, ?, ?)");
+ stmt.setInt(1, 5);
+ stmt.setInt(2, 6);
+ stmt.setString(3, "foo");
+ stmt.execute();
+ conn7.commit();
+ conn7.close();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+8));
+ Connection conn8 = DriverManager.getConnection(getUrl(), props);
+ query = "SELECT i1 FROM KEYONLY";
+ statement = conn8.prepareStatement(query);
+ rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ assertTrue(rs.next());
+ assertEquals(3, rs.getInt(1));
+ assertTrue(rs.next());
+ assertEquals(5, rs.getInt(1));
+ assertFalse(rs.next());
+
+ query = "SELECT i1,s1 FROM KEYONLY";
+ statement = conn8.prepareStatement(query);
+ rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ assertEquals(null, rs.getString(2));
+ assertTrue(rs.next());
+ assertEquals(3, rs.getInt(1));
+ assertEquals(null, rs.getString(2));
+ assertTrue(rs.next());
+ assertEquals(5, rs.getInt(1));
+ assertEquals("foo", rs.getString(2));
+ assertFalse(rs.next());
+
+ conn8.close();
+ }
+
+ @Test
+ public void testOr() throws Exception {
+ long ts = nextTimestamp();
+ ensureTableCreated(getUrl(),KEYONLY_NAME,null, ts);
+ initTableValues(ts+1);
+ Properties props = new Properties();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+5));
+ Connection conn5 = DriverManager.getConnection(getUrl(), props);
+ String query = "SELECT i1 FROM KEYONLY WHERE i1 < 2 or i1 = 3";
+ PreparedStatement statement = conn5.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(1, rs.getInt(1));
+ assertTrue(rs.next());
+ assertEquals(3, rs.getInt(1));
+ assertFalse(rs.next());
+ conn5.close();
+ }
+
+ protected static void initTableValues(long ts) throws Exception {
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ PreparedStatement stmt = conn.prepareStatement(
+ "upsert into " +
+ "KEYONLY VALUES (?, ?)");
+ stmt.setInt(1, 1);
+ stmt.setInt(2, 2);
+ stmt.execute();
+
+ stmt.setInt(1, 3);
+ stmt.setInt(2, 4);
+ stmt.execute();
+
+ conn.commit();
+ conn.close();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
new file mode 100644
index 0000000..ade0915
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MD5FunctionIT.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.security.MessageDigest;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+
+import org.junit.Test;
+
+public class MD5FunctionIT extends BaseHBaseManagedTimeIT {
+
+ @Test
+ public void testRetrieve() throws Exception {
+ String testString = "mwalsh";
+
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl = "CREATE TABLE IF NOT EXISTS MD5_RETRIEVE_TEST (pk VARCHAR NOT NULL PRIMARY KEY)";
+ conn.createStatement().execute(ddl);
+ String dml = String.format("UPSERT INTO MD5_RETRIEVE_TEST VALUES('%s')", testString);
+ conn.createStatement().execute(dml);
+ conn.commit();
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT MD5(pk) FROM MD5_RETRIEVE_TEST");
+ assertTrue(rs.next());
+ byte[] first = MessageDigest.getInstance("MD5").digest(testString.getBytes());
+ byte[] second = rs.getBytes(1);
+ assertArrayEquals(first, second);
+ assertFalse(rs.next());
+ }
+
+ @Test
+ public void testUpsert() throws Exception {
+ String testString1 = "mwalsh1";
+ String testString2 = "mwalsh2";
+
+ Connection conn = DriverManager.getConnection(getUrl());
+ String ddl = "CREATE TABLE IF NOT EXISTS MD5_UPSERT_TEST (k1 binary(16) NOT NULL,k2 binary(16) NOT NULL CONSTRAINT pk PRIMARY KEY (k1, k2))";
+ conn.createStatement().execute(ddl);
+ String dml = String.format("UPSERT INTO MD5_UPSERT_TEST VALUES(md5('%s'),md5('%s'))", testString1, testString2);
+ conn.createStatement().execute(dml);
+ conn.commit();
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT k1,k2 FROM MD5_UPSERT_TEST");
+ assertTrue(rs.next());
+ byte[] pk1 = MessageDigest.getInstance("MD5").digest(testString1.getBytes());
+ byte[] pk2 = MessageDigest.getInstance("MD5").digest(testString2.getBytes());
+ assertArrayEquals(pk1, rs.getBytes(1));
+ assertArrayEquals(pk2, rs.getBytes(2));
+ assertFalse(rs.next());
+ PreparedStatement stmt = conn.prepareStatement("SELECT k1,k2 FROM MD5_UPSERT_TEST WHERE k1=md5(?)");
+ stmt.setString(1, testString1);
+ rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ byte[] second1 = rs.getBytes(1);
+ byte[] second2 = rs.getBytes(2);
+ assertArrayEquals(pk1, second1);
+ assertArrayEquals(pk2, second2);
+ assertFalse(rs.next());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
new file mode 100644
index 0000000..33a7a2c
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
@@ -0,0 +1,229 @@
+/*
+ * 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.*;
+
+import java.math.BigDecimal;
+import java.sql.*;
+import java.util.Properties;
+
+import org.junit.Test;
+
+import org.apache.phoenix.util.PhoenixRuntime;
+
+
+public class MultiCfQueryExecIT extends BaseClientManagedTimeIT {
+ private static final String MULTI_CF = "MULTI_CF";
+
+ protected static void initTableValues(long ts) throws Exception {
+ ensureTableCreated(getUrl(),MULTI_CF,null, ts-2);
+
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts;
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ conn.setAutoCommit(true);
+ // Insert all rows at ts
+ PreparedStatement stmt = conn.prepareStatement(
+ "upsert into " +
+ "MULTI_CF(" +
+ " ID, " +
+ " TRANSACTION_COUNT, " +
+ " CPU_UTILIZATION, " +
+ " DB_CPU_UTILIZATION," +
+ " UNIQUE_USER_COUNT," +
+ " F.RESPONSE_TIME," +
+ " G.RESPONSE_TIME)" +
+ "VALUES (?, ?, ?, ?, ?, ?, ?)");
+ stmt.setString(1, "000000000000001");
+ stmt.setInt(2, 100);
+ stmt.setBigDecimal(3, BigDecimal.valueOf(0.5));
+ stmt.setBigDecimal(4, BigDecimal.valueOf(0.2));
+ stmt.setInt(5, 1000);
+ stmt.setLong(6, 11111);
+ stmt.setLong(7, 11112);
+ stmt.execute();
+ stmt.setString(1, "000000000000002");
+ stmt.setInt(2, 200);
+ stmt.setBigDecimal(3, BigDecimal.valueOf(2.5));
+ stmt.setBigDecimal(4, BigDecimal.valueOf(2.2));
+ stmt.setInt(5, 2000);
+ stmt.setLong(6, 2222);
+ stmt.setLong(7, 22222);
+ stmt.execute();
+ }
+
+ @Test
+ public void testConstantCount() throws Exception {
+ long ts = nextTimestamp();
+ String query = "SELECT count(1) from multi_cf";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ initTableValues(ts);
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(2, rs.getLong(1));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testCFToDisambiguateInSelectOnly1() throws Exception {
+ long ts = nextTimestamp();
+ String query = "SELECT F.RESPONSE_TIME,G.RESPONSE_TIME from multi_cf where ID = '000000000000002'";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ initTableValues(ts);
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(2222, rs.getLong(1));
+ assertEquals(22222, rs.getLong(2));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testCFToDisambiguateInSelectOnly2() throws Exception {
+ long ts = nextTimestamp();
+ String query = "SELECT F.RESPONSE_TIME,G.RESPONSE_TIME from multi_cf where TRANSACTION_COUNT = 200";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ initTableValues(ts);
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(2222, rs.getLong(1));
+ assertEquals(22222, rs.getLong(2));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testCFToDisambiguate1() throws Exception {
+ long ts = nextTimestamp();
+ String query = "SELECT F.RESPONSE_TIME,G.RESPONSE_TIME from multi_cf where F.RESPONSE_TIME = 2222";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ initTableValues(ts);
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(2222, rs.getLong(1));
+ assertEquals(22222, rs.getLong(2));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testCFToDisambiguate2() throws Exception {
+ long ts = nextTimestamp();
+ String query = "SELECT F.RESPONSE_TIME,G.RESPONSE_TIME from multi_cf where G.RESPONSE_TIME-1 = F.RESPONSE_TIME";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ initTableValues(ts);
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(11111, rs.getLong(1));
+ assertEquals(11112, rs.getLong(2));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testDefaultCFToDisambiguate() throws Exception {
+ long ts = nextTimestamp();
+ initTableValues(ts);
+
+ String ddl = "ALTER TABLE multi_cf ADD response_time BIGINT";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 3);
+ Connection conn = DriverManager.getConnection(url);
+ conn.createStatement().execute(ddl);
+ conn.close();
+
+ String dml = "upsert into " +
+ "MULTI_CF(" +
+ " ID, " +
+ " RESPONSE_TIME)" +
+ "VALUES ('000000000000003', 333)";
+ url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 4); // Run query at timestamp 5
+ conn = DriverManager.getConnection(url);
+ conn.createStatement().execute(dml);
+ conn.commit();
+ conn.close();
+
+ String query = "SELECT ID,RESPONSE_TIME from multi_cf where RESPONSE_TIME = 333";
+ url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ conn = DriverManager.getConnection(url);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("000000000000003", rs.getString(1));
+ assertEquals(333, rs.getLong(2));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testEssentialColumnFamilyForRowKeyFilter() throws Exception {
+ long ts = nextTimestamp();
+ String query = "SELECT F.RESPONSE_TIME,G.RESPONSE_TIME from multi_cf where SUBSTR(ID, 15) = '2'";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ initTableValues(ts);
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(2222, rs.getLong(1));
+ assertEquals(22222, rs.getLong(2));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/NativeHBaseTypesIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NativeHBaseTypesIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NativeHBaseTypesIT.java
new file mode 100644
index 0000000..a914711
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NativeHBaseTypesIT.java
@@ -0,0 +1,305 @@
+/*
+ * 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.HBASE_NATIVE;
+import static org.apache.phoenix.util.TestUtil.HBASE_NATIVE_SCHEMA_NAME;
+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.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.client.Delete;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.client.HTableInterface;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Row;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.query.ConnectionQueryServices;
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.SchemaUtil;
+
+
+/**
+ *
+ * Tests using native HBase types (i.e. Bytes.toBytes methods) for
+ * integers and longs. Phoenix can support this if the numbers are
+ * positive.
+ *
+ *
+ * @since 0.1
+ */
+public class NativeHBaseTypesIT extends BaseClientManagedTimeIT {
+ private static final byte[] HBASE_NATIVE_BYTES = SchemaUtil.getTableNameAsBytes(HBASE_NATIVE_SCHEMA_NAME, HBASE_NATIVE);
+ private static final byte[] FAMILY_NAME = Bytes.toBytes(SchemaUtil.normalizeIdentifier("1"));
+ private static final byte[][] SPLITS = new byte[][] {Bytes.toBytes(20), Bytes.toBytes(30)};
+ private static final long ts = nextTimestamp();
+
+ @BeforeClass
+ public static void doBeforeTestSetup() throws Exception {
+ HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES).getAdmin();
+ try {
+ try {
+ admin.disableTable(HBASE_NATIVE_BYTES);
+ admin.deleteTable(HBASE_NATIVE_BYTES);
+ } catch (org.apache.hadoop.hbase.TableNotFoundException e) {
+ }
+ HTableDescriptor descriptor = new HTableDescriptor(HBASE_NATIVE_BYTES);
+ HColumnDescriptor columnDescriptor = new HColumnDescriptor(FAMILY_NAME);
+ columnDescriptor.setKeepDeletedCells(true);
+ descriptor.addFamily(columnDescriptor);
+ admin.createTable(descriptor, SPLITS);
+ initTableValues();
+ } finally {
+ admin.close();
+ }
+ }
+
+ private static void initTableValues() throws Exception {
+ ConnectionQueryServices services = driver.getConnectionQueryServices(getUrl(), TEST_PROPERTIES);
+ HTableInterface hTable = services.getTable(SchemaUtil.getTableNameAsBytes(HBASE_NATIVE_SCHEMA_NAME, HBASE_NATIVE));
+ try {
+ // Insert rows using standard HBase mechanism with standard HBase "types"
+ List<Row> mutations = new ArrayList<Row>();
+ byte[] family = Bytes.toBytes("1");
+ byte[] uintCol = Bytes.toBytes("UINT_COL");
+ byte[] ulongCol = Bytes.toBytes("ULONG_COL");
+ byte[] key, bKey;
+ Put put;
+
+ key = ByteUtil.concat(Bytes.toBytes(10), Bytes.toBytes(100L), Bytes.toBytes("a"));
+ put = new Put(key);
+ put.add(family, uintCol, ts-2, Bytes.toBytes(5));
+ put.add(family, ulongCol, ts-2, Bytes.toBytes(50L));
+ mutations.add(put);
+ put = new Put(key);
+ put.add(family, uintCol, ts, Bytes.toBytes(10));
+ put.add(family, ulongCol, ts, Bytes.toBytes(100L));
+ mutations.add(put);
+
+ bKey = key = ByteUtil.concat(Bytes.toBytes(20), Bytes.toBytes(200L), Bytes.toBytes("b"));
+ put = new Put(key);
+ put.add(family, uintCol, ts-4, Bytes.toBytes(5000));
+ put.add(family, ulongCol, ts-4, Bytes.toBytes(50000L));
+ mutations.add(put);
+ @SuppressWarnings("deprecation") // FIXME: Remove when unintentionally deprecated method is fixed (HBASE-7870).
+ // FIXME: the version of the Delete constructor without the lock args was introduced
+ // in 0.94.4, thus if we try to use it here we can no longer use the 0.94.2 version
+ // of the client.
+ Delete del = new Delete(key, ts-2, null);
+ mutations.add(del);
+ put = new Put(key);
+ put.add(family, uintCol, ts, Bytes.toBytes(2000));
+ put.add(family, ulongCol, ts, Bytes.toBytes(20000L));
+ mutations.add(put);
+
+ key = ByteUtil.concat(Bytes.toBytes(30), Bytes.toBytes(300L), Bytes.toBytes("c"));
+ put = new Put(key);
+ put.add(family, uintCol, ts, Bytes.toBytes(3000));
+ put.add(family, ulongCol, ts, Bytes.toBytes(30000L));
+ mutations.add(put);
+
+ key = ByteUtil.concat(Bytes.toBytes(40), Bytes.toBytes(400L), Bytes.toBytes("d"));
+ put = new Put(key);
+ put.add(family, uintCol, ts, Bytes.toBytes(4000));
+ put.add(family, ulongCol, ts, Bytes.toBytes(40000L));
+ mutations.add(put);
+
+ hTable.batch(mutations);
+
+ Result r = hTable.get(new Get(bKey));
+ assertFalse(r.isEmpty());
+ } finally {
+ hTable.close();
+ }
+ // Create Phoenix table after HBase table was created through the native APIs
+ // The timestamp of the table creation must be later than the timestamp of the data
+ ensureTableCreated(getUrl(),HBASE_NATIVE,null, ts+1);
+ }
+
+ @Test
+ public void testRangeQuery1() throws Exception {
+ String query = "SELECT uint_key, ulong_key, string_key FROM HBASE_NATIVE WHERE uint_key > 20 and ulong_key >= 400";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(40, rs.getInt(1));
+ assertEquals(400L, rs.getLong(2));
+ assertEquals("d", rs.getString(3));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testRangeQuery2() throws Exception {
+ String query = "SELECT uint_key, ulong_key, string_key FROM HBASE_NATIVE WHERE uint_key > 20 and uint_key < 40";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(30, rs.getInt(1));
+ assertEquals(300L, rs.getLong(2));
+ assertEquals("c", rs.getString(3));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testRangeQuery3() throws Exception {
+ String query = "SELECT uint_key, ulong_key, string_key FROM HBASE_NATIVE WHERE ulong_key > 200 and ulong_key < 400";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(30, rs.getInt(1));
+ assertEquals(300L, rs.getLong(2));
+ assertEquals("c", rs.getString(3));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testNegativeAgainstUnsignedNone() throws Exception {
+ String query = "SELECT uint_key, ulong_key, string_key FROM HBASE_NATIVE WHERE ulong_key < -1";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testNegativeAgainstUnsignedAll() throws Exception {
+ String query = "SELECT string_key FROM HBASE_NATIVE WHERE ulong_key > -100";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("a", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("b", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("c", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("d", rs.getString(1));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testNegativeAddNegativeValue() throws Exception {
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 5); // Run query at timestamp 5
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(url, props);
+ try {
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO HBASE_NATIVE(uint_key,ulong_key,string_key, uint_col) VALUES(?,?,?,?)");
+ stmt.setInt(1, -1);
+ stmt.setLong(2, 2L);
+ stmt.setString(3,"foo");
+ stmt.setInt(4, 3);
+ stmt.execute();
+ fail();
+ } catch (SQLException e) {
+ assertTrue(e.getMessage().contains("Type mismatch"));
+ }
+ }
+
+ @Test
+ public void testNegativeCompareNegativeValue() throws Exception {
+ String query = "SELECT string_key FROM HBASE_NATIVE WHERE uint_key > 100000";
+ String url = PHOENIX_JDBC_URL + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 7); // Run query at timestamp 7
+ Properties props = new Properties(TEST_PROPERTIES);
+ PhoenixConnection conn = DriverManager.getConnection(url, props).unwrap(PhoenixConnection.class);
+ HTableInterface hTable = conn.getQueryServices().getTable(SchemaUtil.getTableNameAsBytes(HBASE_NATIVE_SCHEMA_NAME, HBASE_NATIVE));
+
+ List<Row> mutations = new ArrayList<Row>();
+ byte[] family = Bytes.toBytes("1");
+ byte[] uintCol = Bytes.toBytes("UINT_COL");
+ byte[] ulongCol = Bytes.toBytes("ULONG_COL");
+ byte[] key;
+ Put put;
+
+ // Need to use native APIs because the Phoenix APIs wouldn't let you insert a
+ // negative number for an unsigned type
+ key = ByteUtil.concat(Bytes.toBytes(-10), Bytes.toBytes(100L), Bytes.toBytes("e"));
+ put = new Put(key);
+ // Insert at later timestamp than other queries in this test are using, so that
+ // we don't affect them
+ put.add(family, uintCol, ts+6, Bytes.toBytes(10));
+ put.add(family, ulongCol, ts+6, Bytes.toBytes(100L));
+ put.add(family, QueryConstants.EMPTY_COLUMN_BYTES, ts+6, ByteUtil.EMPTY_BYTE_ARRAY);
+ mutations.add(put);
+ hTable.batch(mutations);
+
+ // Demonstrates weakness of HBase Bytes serialization. Negative numbers
+ // show up as bigger than positive numbers
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ assertEquals("e", rs.getString(1));
+ assertFalse(rs.next());
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
new file mode 100644
index 0000000..45be69d
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OrderByIT.java
@@ -0,0 +1,153 @@
+/*
+ * 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.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.Properties;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import org.apache.phoenix.util.PhoenixRuntime;
+
+public class OrderByIT extends BaseClientManagedTimeIT {
+
+ @Test
+ public void testMultiOrderByExpr() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+ String query = "SELECT entity_id FROM aTable ORDER BY b_string, entity_id";
+ 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());
+ assertEquals(ROW1,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW4,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW7,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW2,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW5,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW8,rs.getString(1));
+ 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 testDescMultiOrderByExpr() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+ String query = "SELECT entity_id FROM aTable ORDER BY b_string || entity_id desc";
+ 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());
+ assertEquals(ROW9,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW6,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW3,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW8,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW5,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW2,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW7,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW4,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW1,rs.getString(1));
+
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+
+ @Ignore("When reverse scan is in HBase re-enable this test")
+ @Test
+ public void testReverseScan() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+ String query = "SELECT entity_id FROM aTable WHERE entity_id >= ? ORDER BY organization_id DESC, entity_id DESC";
+ 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, ROW7);
+ ResultSet rs = statement.executeQuery();
+
+ assertTrue (rs.next());
+ assertEquals(ROW9,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW8,rs.getString(1));
+ assertTrue (rs.next());
+ assertEquals(ROW7,rs.getString(1));
+
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-phoenix/blob/8d6e2a58/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
new file mode 100644
index 0000000..2f2ec93
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java
@@ -0,0 +1,687 @@
+/*
+ * 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.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.*;
+import java.util.Properties;
+
+import org.apache.phoenix.query.QueryConstants;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.junit.Test;
+
+public class PercentileIT extends BaseClientManagedTimeIT {
+
+ @Test
+ public void testPercentile() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
+
+ 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());
+ BigDecimal percentile = rs.getBigDecimal(1);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(8.6, percentile.doubleValue(),0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileDesc() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
+
+ 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());
+ BigDecimal percentile = rs.getBigDecimal(1);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(1.4, percentile.doubleValue(),0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileWithGroupby() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable GROUP BY A_STRING";
+
+ 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());
+ assertEquals("a",rs.getString(1));
+ BigDecimal percentile = rs.getBigDecimal(2);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(7.0, percentile.doubleValue(),0.0);
+ assertTrue(rs.next());
+ assertEquals("b",rs.getString(1));
+ percentile = rs.getBigDecimal(2);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(9.0, percentile.doubleValue(),0.0);
+ assertTrue(rs.next());
+ assertEquals("c",rs.getString(1));
+ percentile = rs.getBigDecimal(2);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(8.0, percentile.doubleValue(),0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileWithGroupbyAndOrderBy() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) AS PC FROM aTable GROUP BY A_STRING ORDER BY PC";
+
+ 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());
+ assertEquals("a",rs.getString(1));
+ BigDecimal percentile = rs.getBigDecimal(2);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(7.0, percentile.doubleValue(),0.0);
+ assertTrue(rs.next());
+ assertEquals("c",rs.getString(1));
+ percentile = rs.getBigDecimal(2);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(8.0, percentile.doubleValue(),0.0);
+ assertTrue(rs.next());
+ assertEquals("b",rs.getString(1));
+ percentile = rs.getBigDecimal(2);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(9.0, percentile.doubleValue(),0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileDiscAsc() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
+
+ 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 percentile_disc = rs.getInt(1);
+ assertEquals(9, percentile_disc);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileDiscDesc() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
+
+ 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 percentile_disc = rs.getInt(1);
+ assertEquals(1, percentile_disc);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileDiscWithGroupby() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT A_STRING, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable GROUP BY A_STRING";
+
+ 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());
+ assertEquals("a",rs.getString(1));
+ int percentile_disc = rs.getInt(2);
+ assertEquals(2, percentile_disc);
+ assertTrue(rs.next());
+ assertEquals("b",rs.getString(1));
+ percentile_disc = rs.getInt(2);
+ assertEquals(5, percentile_disc);
+ assertTrue(rs.next());
+ assertEquals("c",rs.getString(1));
+ percentile_disc = rs.getInt(2);
+ assertEquals(8, percentile_disc);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileDiscWithGroupbyAndOrderBy() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT A_STRING, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable GROUP BY A_STRING ORDER BY A_STRING DESC";
+
+ 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());
+ assertEquals("c",rs.getString(1));
+ int percentile_disc = rs.getInt(2);
+ assertEquals(8, percentile_disc);
+ assertTrue(rs.next());
+ assertEquals("b",rs.getString(1));
+ percentile_disc = rs.getInt(2);
+ assertEquals(5, percentile_disc);
+ assertTrue(rs.next());
+ assertEquals("a",rs.getString(1));
+ percentile_disc = rs.getInt(2);
+ assertEquals(2, percentile_disc);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentRank() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENT_RANK(5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
+
+ 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());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.56, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentRankWithNegativeNumeric() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENT_RANK(-2) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM aTable";
+
+ 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());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.0, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentRankDesc() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
+
+ 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());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.11, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentRankDescOnVARCHARColumn() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENT_RANK('ba') WITHIN GROUP (ORDER BY A_STRING DESC) FROM aTable";
+
+ 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());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.11, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentRankDescOnDECIMALColumn() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC) FROM aTable";
+
+ 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());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.33, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testMultiplePercentRanksOnSelect() throws Exception {
+ long ts = nextTimestamp();
+ String tenantId = getOrganizationId();
+ initATableValues(tenantId, null, getDefaultSplits(tenantId), null, ts);
+
+ String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC), PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM aTable";
+
+ 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());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.33, rank.doubleValue(), 0.0);
+ rank = rs.getBigDecimal(2);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.11, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileContOnDescPKColumn() throws Exception {
+ ensureTableCreated(getUrl(), INDEX_DATA_TABLE);
+ populateINDEX_DATA_TABLETable();
+
+ String query = "SELECT PERCENTILE_CONT(1) WITHIN GROUP (ORDER BY long_pk ASC) FROM " + INDEX_DATA_SCHEMA
+ + QueryConstants.NAME_SEPARATOR + INDEX_DATA_TABLE;
+
+ Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ BigDecimal percentile = rs.getBigDecimal(1);
+ percentile = percentile.setScale(1, RoundingMode.HALF_UP);
+ assertEquals(3.0, percentile.doubleValue(),0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentRankOnDescPKColumn() throws Exception {
+ ensureTableCreated(getUrl(), INDEX_DATA_TABLE);
+ populateINDEX_DATA_TABLETable();
+
+ String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY long_pk ASC) FROM " + INDEX_DATA_SCHEMA
+ + QueryConstants.NAME_SEPARATOR + INDEX_DATA_TABLE;
+
+ Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ BigDecimal rank = rs.getBigDecimal(1);
+ rank = rank.setScale(2, RoundingMode.HALF_UP);
+ assertEquals(0.67, rank.doubleValue(), 0.0);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testPercentileDiscOnDescPKColumn() throws Exception {
+ ensureTableCreated(getUrl(), INDEX_DATA_TABLE);
+ populateINDEX_DATA_TABLETable();
+
+ String query = "SELECT PERCENTILE_DISC(0.4) WITHIN GROUP (ORDER BY long_pk DESC) FROM " + INDEX_DATA_SCHEMA
+ + QueryConstants.NAME_SEPARATOR + INDEX_DATA_TABLE;
+
+ Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL);
+ try {
+ PreparedStatement statement = conn.prepareStatement(query);
+ ResultSet rs = statement.executeQuery();
+ assertTrue(rs.next());
+ long percentile_disc = rs.getLong(1);
+ assertEquals(2, percentile_disc);
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ private static void populateINDEX_DATA_TABLETable() throws SQLException {
+ Properties props = new Properties(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ String upsert = "UPSERT INTO " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + INDEX_DATA_TABLE
+ + " VALUES(?, ?, ?, ?, ?)";
+ PreparedStatement stmt = conn.prepareStatement(upsert);
+ stmt.setString(1, "varchar1");
+ stmt.setString(2, "char1");
+ stmt.setInt(3, 1);
+ stmt.setLong(4, 1L);
+ stmt.setBigDecimal(5, new BigDecimal(1.0));
+ stmt.executeUpdate();
+
+ stmt.setString(1, "varchar2");
+ stmt.setString(2, "char2");
+ stmt.setInt(3, 2);
+ stmt.setLong(4, 2L);
+ stmt.setBigDecimal(5, new BigDecimal(2.0));
+ stmt.executeUpdate();
+
+ stmt.setString(1, "varchar3");
+ stmt.setString(2, "char3");
+ stmt.setInt(3, 3);
+ stmt.setLong(4, 3L);
+ stmt.setBigDecimal(5, new BigDecimal(3.0));
+ stmt.executeUpdate();
+
+ conn.commit();
+ } finally {
+ conn.close();
+ }
+ }
+
+ protected static void initATableValues(String tenantId1, String tenantId2, byte[][] splits,
+ Date date, Long ts) throws Exception {
+ if (ts == null) {
+ ensureTableCreated(getUrl(), ATABLE_NAME, splits);
+ } else {
+ ensureTableCreated(getUrl(), ATABLE_NAME, splits, ts - 2);
+ }
+
+ 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 " + "ATABLE("
+ + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_STRING, "
+ + " B_STRING, " + " A_INTEGER, " + " A_DATE, " + " X_DECIMAL, "
+ + " X_LONG, " + " X_INTEGER," + " Y_INTEGER)"
+ + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ if (tenantId1 != null) {
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW1);
+ stmt.setString(3, A_VALUE);
+ stmt.setString(4, B_VALUE);
+ stmt.setInt(5, 1);
+ stmt.setDate(6, date);
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW2);
+ stmt.setString(3, A_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 2);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW3);
+ stmt.setString(3, A_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 3);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW4);
+ stmt.setString(3, A_VALUE);
+ stmt.setString(4, B_VALUE);
+ stmt.setInt(5, 7);
+ stmt.setDate(6, date == null ? null : date);
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW5);
+ stmt.setString(3, B_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 6);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW6);
+ stmt.setString(3, B_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 5);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW7);
+ stmt.setString(3, B_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 4);
+ stmt.setDate(6, date == null ? null : date);
+ stmt.setBigDecimal(7, BigDecimal.valueOf(0.1));
+ stmt.setLong(8, 5L);
+ stmt.setInt(9, 5);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW8);
+ stmt.setString(3, B_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 9);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
+ stmt.setBigDecimal(7, BigDecimal.valueOf(3.9));
+ long l = Integer.MIN_VALUE - 1L;
+ assert (l < Integer.MIN_VALUE);
+ stmt.setLong(8, l);
+ stmt.setInt(9, 4);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId1);
+ stmt.setString(2, ROW9);
+ stmt.setString(3, C_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 8);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 2));
+ stmt.setBigDecimal(7, BigDecimal.valueOf(3.3));
+ l = Integer.MAX_VALUE + 1L;
+ assert (l > Integer.MAX_VALUE);
+ stmt.setLong(8, l);
+ stmt.setInt(9, 3);
+ stmt.setInt(10, 300);
+ stmt.execute();
+ }
+ if (tenantId2 != null) {
+ stmt.setString(1, tenantId2);
+ stmt.setString(2, ROW1);
+ stmt.setString(3, A_VALUE);
+ stmt.setString(4, B_VALUE);
+ stmt.setInt(5, 1);
+ stmt.setDate(6, date);
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+
+ stmt.setString(1, tenantId2);
+ stmt.setString(2, ROW2);
+ stmt.setString(3, A_VALUE);
+ stmt.setString(4, C_VALUE);
+ stmt.setInt(5, 2);
+ stmt.setDate(6, date == null ? null : new Date(date.getTime() + MILLIS_IN_DAY * 1));
+ stmt.setBigDecimal(7, null);
+ stmt.setNull(8, Types.BIGINT);
+ stmt.setNull(9, Types.INTEGER);
+ stmt.setNull(10, Types.INTEGER);
+ stmt.execute();
+ }
+ conn.commit();
+ } finally {
+ conn.close();
+ }
+ }
+}