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 2017/09/13 23:08:30 UTC
[1/4] phoenix git commit: PHOENIX-4180 Modify tests to generate
unique table names and not use CURRENT_SCN (Rahul Shrivastava)
Repository: phoenix
Updated Branches:
refs/heads/master 41e137199 -> 26a7b9e8b
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/CursorWithRowValueConstructorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CursorWithRowValueConstructorIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CursorWithRowValueConstructorIT.java
index dda4bd1..e5457d6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CursorWithRowValueConstructorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CursorWithRowValueConstructorIT.java
@@ -17,42 +17,56 @@
*/
package org.apache.phoenix.end2end;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.phoenix.util.*;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.apache.phoenix.util.TestUtil.ENTITYHISTID3;
+import static org.apache.phoenix.util.TestUtil.ENTITYHISTID7;
+import static org.apache.phoenix.util.TestUtil.PARENTID3;
+import static org.apache.phoenix.util.TestUtil.PARENTID7;
+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.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 static org.junit.Assert.fail;
import java.math.BigDecimal;
-import java.sql.*;
+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.sql.Timestamp;
import java.util.Properties;
import java.util.Random;
-import static org.apache.phoenix.util.TestUtil.*;
-import static org.junit.Assert.*;
+import org.apache.phoenix.util.CursorUtil;
+import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Test;
public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
- private static final String TABLE_NAME = "CursorRVCTestTable";
- protected static final Log LOG = LogFactory.getLog(CursorWithRowValueConstructorIT.class);
+ private String tableName = generateUniqueName();
public void createAndInitializeTestTable() throws SQLException {
Connection conn = DriverManager.getConnection(getUrl());
-
- PreparedStatement stmt = conn.prepareStatement("CREATE TABLE IF NOT EXISTS " + TABLE_NAME +
+ tableName = generateUniqueName();
+ PreparedStatement stmt = conn.prepareStatement("CREATE TABLE " + tableName +
"(a_id INTEGER NOT NULL, " +
"a_data INTEGER, " +
"CONSTRAINT my_pk PRIMARY KEY (a_id))");
stmt.execute();
- synchronized (conn){
- conn.commit();
- }
+ conn.commit();
//Upsert test values into the test table
Random rand = new Random();
- stmt = conn.prepareStatement("UPSERT INTO " + TABLE_NAME +
+ stmt = conn.prepareStatement("UPSERT INTO " + tableName +
"(a_id, a_data) VALUES (?,?)");
int rowCount = 0;
while(rowCount < 100){
@@ -61,363 +75,340 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
stmt.execute();
++rowCount;
}
- synchronized (conn){
- conn.commit();
- }
- }
-
- public void deleteTestTable() throws SQLException {
- Connection conn = DriverManager.getConnection(getUrl());
- PreparedStatement stmt = conn.prepareStatement("DROP TABLE IF EXISTS " + TABLE_NAME);
- stmt.execute();
- synchronized (conn){
- conn.commit();
- }
+ conn.commit();
+ conn.close();
}
@Test
public void testCursorsOnTestTablePK() throws SQLException {
- try{
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
createAndInitializeTestTable();
- String querySQL = "SELECT a_id FROM " + TABLE_NAME;
+ String querySQL = "SELECT a_id FROM " + tableName;
//Test actual cursor implementation
- String cursorSQL = "DECLARE testCursor CURSOR FOR " + querySQL;
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "OPEN testCursor";
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "FETCH NEXT FROM testCursor";
- ResultSet rs = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ String cursorSQL = "DECLARE " + cursorName + " CURSOR FOR " + querySQL;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "OPEN " + cursorName;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursorSQL).executeQuery();
int rowID = 0;
while(rs.next()){
assertEquals(rowID,rs.getInt(1));
++rowID;
- rs = DriverManager.getConnection(getUrl()).createStatement().executeQuery(cursorSQL);
+ rs = conn.createStatement().executeQuery(cursorSQL);
}
- } finally{
- DriverManager.getConnection(getUrl()).prepareStatement("CLOSE testCursor").execute();
- deleteTestTable();
+ conn.prepareStatement("CLOSE " + cursorName).execute();
}
}
@Test
public void testCursorsOnRandomTableData() throws SQLException {
- try{
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
createAndInitializeTestTable();
- String querySQL = "SELECT a_id,a_data FROM " + TABLE_NAME + " ORDER BY a_data";
- String cursorSQL = "DECLARE testCursor CURSOR FOR " + querySQL;
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "OPEN testCursor";
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "FETCH NEXT FROM testCursor";
- ResultSet cursorRS = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
- ResultSet rs = DriverManager.getConnection(getUrl()).prepareStatement(querySQL).executeQuery();
+ String querySQL = "SELECT a_id,a_data FROM " + tableName + " ORDER BY a_data";
+ String cursorSQL = "DECLARE " + cursorName + " CURSOR FOR " + querySQL;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "OPEN " + cursorName;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "FETCH NEXT FROM " + cursorName;
+ ResultSet cursorRS = conn.prepareStatement(cursorSQL).executeQuery();
+ ResultSet rs = conn.prepareStatement(querySQL).executeQuery();
int rowCount = 0;
while(rs.next() && cursorRS.next()){
assertEquals(rs.getInt(2),cursorRS.getInt(2));
++rowCount;
- cursorRS = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ cursorRS = conn.prepareStatement(cursorSQL).executeQuery();
}
assertEquals(100, rowCount);
- } finally{
- DriverManager.getConnection(getUrl()).prepareStatement("CLOSE testCursor").execute();
- deleteTestTable();
+ conn.prepareStatement("CLOSE " + cursorName).execute();
}
}
@Test
public void testCursorsOnTestTablePKDesc() throws SQLException {
- try{
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
createAndInitializeTestTable();
- String dummySQL = "SELECT a_id FROM " + TABLE_NAME + " ORDER BY a_id DESC";
-
- String cursorSQL = "DECLARE testCursor CURSOR FOR " + dummySQL;
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "OPEN testCursor";
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "FETCH NEXT FROM testCursor";
- ResultSet rs = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ String dummySQL = "SELECT a_id FROM " + tableName + " ORDER BY a_id DESC";
+
+ String cursorSQL = "DECLARE " + cursorName + " CURSOR FOR " + dummySQL;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "OPEN " + cursorName;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursorSQL).executeQuery();
int rowCount = 0;
while(rs.next()){
assertEquals(99-rowCount, rs.getInt(1));
- rs = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ rs = conn.prepareStatement(cursorSQL).executeQuery();
++rowCount;
}
assertEquals(100, rowCount);
- } finally{
- DriverManager.getConnection(getUrl()).prepareStatement("CLOSE testCursor").execute();
- deleteTestTable();
+ conn.prepareStatement("CLOSE " + cursorName).execute();
}
}
@Test
public void testCursorsOnTestTableNonPKDesc() throws SQLException {
- try{
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
createAndInitializeTestTable();
- String dummySQL = "SELECT a_data FROM " + TABLE_NAME + " ORDER BY a_data DESC";
-
- String cursorSQL = "DECLARE testCursor CURSOR FOR " + dummySQL;
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "OPEN testCursor";
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "FETCH NEXT FROM testCursor";
- ResultSet rs = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ String dummySQL = "SELECT a_data FROM " + tableName + " ORDER BY a_data DESC";
+
+ String cursorSQL = "DECLARE " + cursorName + " CURSOR FOR " + dummySQL;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "OPEN " + cursorName;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursorSQL).executeQuery();
int rowCount = 0;
while(rs.next()){
- rs = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ rs = conn.prepareStatement(cursorSQL).executeQuery();
++rowCount;
}
assertEquals(100, rowCount);
- } finally{
- DriverManager.getConnection(getUrl()).prepareStatement("CLOSE testCursor").execute();
- deleteTestTable();
+ conn.prepareStatement("CLOSE " + cursorName).execute();
}
}
@Test
public void testCursorsOnWildcardSelect() throws SQLException {
- try{
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
createAndInitializeTestTable();
- String querySQL = "SELECT * FROM " + TABLE_NAME;
- ResultSet rs = DriverManager.getConnection(getUrl()).prepareStatement(querySQL).executeQuery();
-
- String cursorSQL = "DECLARE testCursor CURSOR FOR "+querySQL;
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "OPEN testCursor";
- DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).execute();
- cursorSQL = "FETCH NEXT FROM testCursor";
- ResultSet cursorRS = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ String querySQL = "SELECT * FROM " + tableName;
+ ResultSet rs = conn.prepareStatement(querySQL).executeQuery();
+
+ String cursorSQL = "DECLARE " + cursorName + " CURSOR FOR "+querySQL;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "OPEN " + cursorName;
+ conn.prepareStatement(cursorSQL).execute();
+ cursorSQL = "FETCH NEXT FROM " + cursorName;
+ ResultSet cursorRS = conn.prepareStatement(cursorSQL).executeQuery();
int rowCount = 0;
while(rs.next() && cursorRS.next()){
assertEquals(rs.getInt(1),cursorRS.getInt(1));
++rowCount;
- cursorRS = DriverManager.getConnection(getUrl()).prepareStatement(cursorSQL).executeQuery();
+ cursorRS = conn.prepareStatement(cursorSQL).executeQuery();
}
assertEquals(100, rowCount);
- } finally{
- DriverManager.getConnection(getUrl()).prepareStatement("CLOSE testCursor").execute();
- deleteTestTable();
+ conn.prepareStatement("CLOSE " + cursorName).execute();
}
}
@Test
public void testCursorsWithBindings() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE ?=organization_id AND (a_integer, x_integer) = (7, 5)";
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- PreparedStatement statement = conn.prepareStatement(cursor);
- statement.setString(1, tenantId);
- statement.execute();
- }catch(SQLException e){
- assertTrue(e.getMessage().equalsIgnoreCase("Cannot declare cursor, internal SELECT statement contains bindings!"));
- assertTrue(!CursorUtil.cursorDeclared("testCursor"));
- return;
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
+ String cursorName = generateUniqueName();
+ final String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+ aTable +" WHERE ?=organization_id AND (a_integer, x_integer) = (7, 5)";
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ PreparedStatement statement = conn.prepareStatement(cursor);
+ statement.setString(1, tenantId);
+ statement.execute();
+ }catch(SQLException e){
+ assertTrue(e.getMessage().equalsIgnoreCase("Cannot declare cursor, internal SELECT statement contains bindings!"));
+ assertFalse(CursorUtil.cursorDeclared(cursorName));
+ return;
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ }
+ fail();
}
- fail();
}
@Test
public void testCursorsInWhereWithEqualsExpression() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) = (7, 5)";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+aTable+" WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) = (7, 5)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
- conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
- ResultSet rs = conn.prepareStatement(cursor).executeQuery();
- int count = 0;
- while(rs.next()) {
- assertTrue(rs.getInt(1) == 7);
- assertTrue(rs.getInt(2) == 5);
- count++;
- rs = conn.prepareStatement(cursor).executeQuery();
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ conn.prepareStatement(cursor).execute();
+ cursor = "OPEN " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ cursor = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursor).executeQuery();
+ int count = 0;
+ while(rs.next()) {
+ assertTrue(rs.getInt(1) == 7);
+ assertTrue(rs.getInt(2) == 5);
+ count++;
+ rs = conn.prepareStatement(cursor).executeQuery();
+ }
+ assertTrue(count == 1);
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
}
- assertTrue(count == 1);
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
}
}
@Test
public void testCursorsInWhereWithGreaterThanExpression() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) >= (4, 4)";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+aTable+" WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) >= (4, 4)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
- conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
- ResultSet rs = conn.prepareStatement(cursor).executeQuery();
- int count = 0;
- while(rs.next()) {
- assertTrue(rs.getInt(1) >= 4);
- assertTrue(rs.getInt(1) == 4 ? rs.getInt(2) >= 4 : rs.getInt(2) >= 0);
- count++;
- rs = conn.prepareStatement(cursor).executeQuery();
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ conn.prepareStatement(cursor).execute();
+ cursor = "OPEN " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ cursor = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursor).executeQuery();
+ int count = 0;
+ while(rs.next()) {
+ assertTrue(rs.getInt(1) >= 4);
+ assertTrue(rs.getInt(1) == 4 ? rs.getInt(2) >= 4 : rs.getInt(2) >= 0);
+ count++;
+ rs = conn.prepareStatement(cursor).executeQuery();
+ }
+ assertTrue(count == 5);
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
}
- assertTrue(count == 5);
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
}
}
@Test
public void testCursorsInWhereWithUnEqualNumberArgs() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer, y_integer) >= (7, 5)";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+ aTable+" WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer, y_integer) >= (7, 5)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- double startTime = System.nanoTime();
- conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
- conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
- ResultSet rs = conn.prepareStatement(cursor).executeQuery();
- int count = 0;
- while(rs.next()) {
- assertTrue(rs.getInt(1) >= 7);
- assertTrue(rs.getInt(1) == 7 ? rs.getInt(2) >= 5 : rs.getInt(2) >= 0);
- count++;
- rs = conn.prepareStatement(cursor).executeQuery();
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ double startTime = System.nanoTime();
+ conn.prepareStatement(cursor).execute();
+ cursor = "OPEN " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ cursor = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursor).executeQuery();
+ int count = 0;
+ while(rs.next()) {
+ assertTrue(rs.getInt(1) >= 7);
+ assertTrue(rs.getInt(1) == 7 ? rs.getInt(2) >= 5 : rs.getInt(2) >= 0);
+ count++;
+ rs = conn.prepareStatement(cursor).executeQuery();
+ }
+ // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
+ assertTrue(count == 3);
+ double endTime = System.nanoTime();
+ System.out.println("Method Time in milliseconds: "+Double.toString((endTime-startTime)/1000000));
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
}
- // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
- assertTrue(count == 3);
- double endTime = System.nanoTime();
- System.out.println("Method Time in milliseconds: "+Double.toString((endTime-startTime)/1000000));
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
}
}
@Test
public void testCursorsOnLHSAndLiteralExpressionOnRHS() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) >= 7";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+ aTable +" WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) >= 7";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
- conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
- ResultSet rs = conn.prepareStatement(cursor).executeQuery();
- int count = 0;
- while(rs.next()) {
- count++;
- rs = conn.prepareStatement(cursor).executeQuery();
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ conn.prepareStatement(cursor).execute();
+ cursor = "OPEN " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ cursor = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursor).executeQuery();
+ int count = 0;
+ while(rs.next()) {
+ count++;
+ rs = conn.prepareStatement(cursor).executeQuery();
+ }
+ // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
+ assertTrue(count == 3);
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
}
- // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
- assertTrue(count == 3);
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
}
}
@Test
public void testCursorsOnRHSLiteralExpressionOnLHS() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE '"+tenantId+"'=organization_id AND 7 <= (a_integer, x_integer)";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+ aTable+" WHERE '"+tenantId+"'=organization_id AND 7 <= (a_integer, x_integer)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
- conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
- ResultSet rs = conn.prepareStatement(cursor).executeQuery();
- int count = 0;
- while(rs.next()) {
- count++;
- rs = conn.prepareStatement(cursor).executeQuery();
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ conn.prepareStatement(cursor).execute();
+ cursor = "OPEN " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ cursor = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursor).executeQuery();
+ int count = 0;
+ while(rs.next()) {
+ count++;
+ rs = conn.prepareStatement(cursor).executeQuery();
+ }
+ // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
+ assertTrue(count == 3);
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
}
- // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
- assertTrue(count == 3);
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
}
}
@Test
public void testCursorsOnBuiltInFunctionOperatingOnIntegerLiteral() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_integer, x_integer FROM aTable WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) >= to_number('7')";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_integer, x_integer FROM "+aTable+" WHERE '"+tenantId+"'=organization_id AND (a_integer, x_integer) >= to_number('7')";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
- try {
- conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
- conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
- ResultSet rs = conn.prepareStatement(cursor).executeQuery();
- int count = 0;
- while(rs.next()) {
- count++;
- rs = conn.prepareStatement(cursor).executeQuery();
+ String cursorName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
+ try {
+ conn.prepareStatement(cursor).execute();
+ cursor = "OPEN " + cursorName;
+ conn.prepareStatement(cursor).execute();
+ cursor = "FETCH NEXT FROM " + cursorName;
+ ResultSet rs = conn.prepareStatement(cursor).executeQuery();
+ int count = 0;
+ while(rs.next()) {
+ count++;
+ rs = conn.prepareStatement(cursor).executeQuery();
+ }
+ // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
+ assertEquals(3, count);
+ } finally {
+ cursor = "CLOSE " + cursorName;
+ conn.prepareStatement(cursor).execute();
}
- // we have key values (7,5) (8,4) and (9,3) present in aTable. So the query should return the 3 records.
- assertEquals(3, count);
- } finally {
- cursor = "CLOSE testCursor";
- conn.prepareStatement(cursor).execute();
- conn.close();
}
}
@@ -426,7 +417,6 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
* Test for the precision of Date datatype when used as part of a filter within the internal Select statement.
*/
public void testCursorsWithDateDatatypeFilter() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
long currentTime = System.currentTimeMillis();
java.sql.Date date = new java.sql.Date(currentTime);
@@ -442,13 +432,12 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
java.sql.Date midnight = new Date(currentTime+1);
- initEntityHistoryTableValues(tenantId, getDefaultSplits(tenantId), date, ts);
+ String tableName = initEntityHistoryTableValues(null, tenantId, getDefaultSplits(tenantId), date, null);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
Connection conn = DriverManager.getConnection(getUrl(), props);
- String query = "select parent_id from " + ENTITY_HISTORY_TABLE_NAME +
+ String query = "select parent_id from " + tableName +
" WHERE (organization_id, parent_id, created_date, entity_history_id) IN ((?,?,?,?),(?,?,?,?))";
query = query.replaceFirst("\\?", "'"+tenantId+"'");
@@ -459,12 +448,13 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
query = query.replaceFirst("\\?", "'"+PARENTID7+"'");
query = query.replaceFirst("\\?", "TO_DATE('"+DateUtil.getDateFormatter(DateUtil.DEFAULT_DATE_FORMAT).format(date)+"')");
query = query.replaceFirst("\\?", "'"+ENTITYHISTID7+"'");
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
+ String cursorName = generateUniqueName();
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
+ cursor = "OPEN " + cursorName;
conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
+ cursor = "FETCH NEXT FROM " + cursorName;
ResultSet rs = conn.prepareStatement(cursor).executeQuery();
assertTrue(rs.next());
@@ -476,7 +466,7 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
//Test against the same table for the same records, but this time use the 'midnight' java.sql.Date instance.
//'midnight' is identical to 'date' to the tens of millisecond precision.
- query = "select parent_id from " + ENTITY_HISTORY_TABLE_NAME +
+ query = "select parent_id from " + tableName +
" WHERE (organization_id, parent_id, created_date, entity_history_id) IN ((?,?,?,?),(?,?,?,?))";
query = query.replaceFirst("\\?", "'"+tenantId+"'");
query = query.replaceFirst("\\?", "'"+PARENTID3+"'");
@@ -486,35 +476,35 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
query = query.replaceFirst("\\?", "'"+PARENTID7+"'");
query = query.replaceFirst("\\?", "TO_DATE('"+DateUtil.getDateFormatter(DateUtil.DEFAULT_DATE_FORMAT).format(midnight)+"')");
query = query.replaceFirst("\\?", "'"+ENTITYHISTID7+"'");
- cursor = "DECLARE testCursor2 CURSOR FOR "+query;
+ String cursorName2 = generateUniqueName();
+ cursor = "DECLARE " + cursorName2 + " CURSOR FOR "+query;
conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor2";
+ cursor = "OPEN " + cursorName2;
conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor2";
+ cursor = "FETCH NEXT FROM " + cursorName2;
rs = conn.prepareStatement(cursor).executeQuery();
assertTrue(!rs.next());
- String sql = "CLOSE testCursor";
+ String sql = "CLOSE " + cursorName;
conn.prepareStatement(sql).execute();
- sql = "CLOSE testCursor2";
+ sql = "CLOSE " + cursorName2;
conn.prepareStatement(sql).execute();
}
@Test
public void testCursorsWithNonLeadingPkColsOfTypesTimeStampAndVarchar() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
+ String cursorName = generateUniqueName();
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
String updateStmt =
- "upsert into " +
- "ATABLE(" +
+ "upsert into " + aTable+
+ "(" +
" ORGANIZATION_ID, " +
" ENTITY_ID, " +
" A_TIMESTAMP) " +
"VALUES (?, ?, ?)";
- String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 1);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection upsertConn = DriverManager.getConnection(url, props);
upsertConn.setAutoCommit(true);
@@ -525,19 +515,18 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
stmt.setTimestamp(3, tsValue);
stmt.execute();
- String query = "SELECT a_timestamp, a_string FROM aTable WHERE ?=organization_id AND (a_timestamp, a_string) = (?, 'a')";
+ String query = "SELECT a_timestamp, a_string FROM "+aTable+" WHERE ?=organization_id AND (a_timestamp, a_string) = (?, 'a')";
query = query.replaceFirst("\\?", "'"+tenantId+"'");
query = query.replaceFirst("\\?", "TO_DATE('"+DateUtil.getDateFormatter(DateUtil.DEFAULT_TIMESTAMP_FORMAT).format(tsValue)+"')");
props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
+ cursor = "OPEN " + cursorName;
conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
+ cursor = "FETCH NEXT FROM " + cursorName;
ResultSet rs = conn.prepareStatement(cursor).executeQuery();
int count = 0;
@@ -549,7 +538,7 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
}
assertTrue(count == 1);
} finally {
- String sql = "CLOSE testCursor";
+ String sql = "CLOSE " + cursorName;
conn.prepareStatement(sql).execute();
conn.close();
}
@@ -557,14 +546,13 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
@Test
public void testCursorsQueryMoreWithInListClausePossibleNullValues() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
+ String cursorName = generateUniqueName();
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
String updateStmt =
- "upsert into " +
- "ATABLE(ORGANIZATION_ID, ENTITY_ID, Y_INTEGER, X_INTEGER) VALUES (?, ?, ?, ?)";
- String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 1);
+ "upsert into " +aTable+
+ "(ORGANIZATION_ID, ENTITY_ID, Y_INTEGER, X_INTEGER) VALUES (?, ?, ?, ?)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection upsertConn = DriverManager.getConnection(url, props);
upsertConn.setAutoCommit(true);
@@ -576,19 +564,18 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
stmt.execute();
//we have a row present in aTable where x_integer = 5 and y_integer = NULL which gets translated to 0 when retriving from HBase.
- String query = "SELECT x_integer, y_integer FROM aTable WHERE ? = organization_id AND (x_integer) IN ((5))";
+ String query = "SELECT x_integer, y_integer FROM "+ aTable+" WHERE ? = organization_id AND (x_integer) IN ((5))";
query = query.replaceFirst("\\?", "'"+tenantId+"'");
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
+ cursor = "OPEN " + cursorName;
conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
+ cursor = "FETCH NEXT FROM " + cursorName;
ResultSet rs = conn.prepareStatement(cursor).executeQuery();
assertTrue(rs.next());
@@ -599,7 +586,7 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
assertEquals(5, rs.getInt(1));
assertEquals(0, rs.getInt(2));
} finally {
- String sql = "CLOSE testCursor";
+ String sql = "CLOSE " + cursorName;
conn.prepareStatement(sql).execute();
conn.close();
}
@@ -607,26 +594,25 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
@Test
public void testCursorsWithColsOfTypesDecimal() throws Exception {
- long ts = nextTimestamp();
+ String cursorName = generateUniqueName();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String query = "SELECT x_decimal FROM aTable WHERE ?=organization_id AND entity_id IN (?,?,?)";
+ String query = "SELECT x_decimal FROM "+ aTable+" WHERE ?=organization_id AND entity_id IN (?,?,?)";
query = query.replaceFirst("\\?", "'"+tenantId+"'");
query = query.replaceFirst("\\?", "'"+ROW7+"'");
query = query.replaceFirst("\\?", "'"+ROW8+"'");
query = query.replaceFirst("\\?", "'"+ROW9+"'");
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
+ cursor = "OPEN " + cursorName;
conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
+ cursor = "FETCH NEXT FROM " + cursorName;
ResultSet rs = conn.prepareStatement(cursor).executeQuery();
int count = 0;
@@ -638,7 +624,7 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
}
assertTrue(count == 3);
} finally {
- String sql = "CLOSE testCursor";
+ String sql = "CLOSE " + cursorName;
conn.prepareStatement(sql).execute();
conn.close();
}
@@ -646,25 +632,24 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
@Test
public void testCursorsWithColsOfTypesTinyintSmallintFloatDouble() throws Exception {
- long ts = nextTimestamp();
+ String cursorName = generateUniqueName();
String tenantId = getOrganizationId();
- initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts-1, getUrl(), null);
- ensureTableCreated(getUrl(), CUSTOM_ENTITY_DATA_FULL_NAME, CUSTOM_ENTITY_DATA_FULL_NAME, ts-1);
- String query = "SELECT a_byte,a_short,a_float,a_double FROM aTable WHERE ?=organization_id AND entity_id IN (?,?,?)";
+ String aTable = initATableValues(null, tenantId,
+ getDefaultSplits(tenantId), null, null, getUrl(), null);
+ String query = "SELECT a_byte,a_short,a_float,a_double FROM "+ aTable+" WHERE ?=organization_id AND entity_id IN (?,?,?)";
query = query.replaceFirst("\\?", "'"+tenantId+"'");
query = query.replaceFirst("\\?", "'"+ROW1+"'");
query = query.replaceFirst("\\?", "'"+ROW2+"'");
query = query.replaceFirst("\\?", "'"+ROW3+"'");
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
- String cursor = "DECLARE testCursor CURSOR FOR "+query;
+ String cursor = "DECLARE " + cursorName + " CURSOR FOR "+query;
conn.prepareStatement(cursor).execute();
- cursor = "OPEN testCursor";
+ cursor = "OPEN " + cursorName;
conn.prepareStatement(cursor).execute();
- cursor = "FETCH NEXT FROM testCursor";
+ cursor = "FETCH NEXT FROM " + cursorName;
ResultSet rs = conn.prepareStatement(cursor).executeQuery();
int count = 0;
@@ -679,7 +664,7 @@ public class CursorWithRowValueConstructorIT extends ParallelStatsDisabledIT {
}
assertTrue(count == 3);
} finally {
- String sql = "CLOSE testCursor";
+ String sql = "CLOSE " + cursorName;
conn.prepareStatement(sql).execute();
conn.close();
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/OutOfOrderMutationsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OutOfOrderMutationsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/OutOfOrderMutationsIT.java
deleted file mode 100644
index 40b58f2..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/OutOfOrderMutationsIT.java
+++ /dev/null
@@ -1,386 +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.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.util.EnvironmentEdge;
-import org.apache.phoenix.util.EnvironmentEdgeManager;
-import org.apache.phoenix.util.IndexScrutiny;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.TestUtil;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class OutOfOrderMutationsIT extends ParallelStatsDisabledIT {
-
- private static class MyClock extends EnvironmentEdge {
- public volatile long time;
-
- public MyClock (long time) {
- this.time = time;
- }
-
- @Override
- public long currentTime() {
- return time;
- }
- }
-
- @Test
- @Ignore("PHOENIX-4058 Generate correct index updates when DeleteColumn processed before Put with same timestamp")
- public void testSetIndexedColumnToNullAndValueAtSameTS() throws Exception {
- try {
- final MyClock clock = new MyClock(1000);
- EnvironmentEdgeManager.injectEdge(clock);
- String tableName = generateUniqueName();
- String indexName = generateUniqueName();
- Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
- long ts = 1000;
- clock.time = ts;
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0");
- conn.close();
-
- ts = 1010;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
- conn.close();
-
- ts = 1020;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
- stmt.setTimestamp(1, new Timestamp(1000L));
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- Timestamp expectedTimestamp;
- ts = 1040;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
- expectedTimestamp = null;
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- stmt.setTimestamp(1, new Timestamp(3000L));
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- ts = 1050;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
-
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
- IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
-
- ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName);
- assertTrue(rs.next());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- assertEquals(null, rs.getString(2));
- assertFalse(rs.next());
-
- rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
- assertTrue(rs.next());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- assertEquals(null, rs.getString(2));
- assertFalse(rs.next());
-
- conn.close();
- } finally {
- EnvironmentEdgeManager.injectEdge(null);
- }
- }
-
- @Test
- public void testSetIndexedColumnToNullAndValueAtSameTSWithStoreNulls1() throws Exception {
- try {
- final MyClock clock = new MyClock(1000);
- EnvironmentEdgeManager.injectEdge(clock);
- String tableName = generateUniqueName();
- String indexName = generateUniqueName();
- Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
- long ts = 1000;
- clock.time = ts;
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
- conn.close();
-
- ts = 1010;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
- conn.close();
-
- ts = 1020;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
- stmt.setTimestamp(1, new Timestamp(1000L));
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- Timestamp expectedTimestamp;
- ts = 1040;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
- expectedTimestamp = null;
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- expectedTimestamp = new Timestamp(3000L);
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- ts = 1050;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
-
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
- IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
-
- ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName);
- assertTrue(rs.next());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- assertEquals(null, rs.getString(2));
- assertFalse(rs.next());
-
- rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
- assertTrue(rs.next());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- assertEquals(null, rs.getString(2));
- assertFalse(rs.next());
-
- conn.close();
- } finally {
- EnvironmentEdgeManager.injectEdge(null);
- }
- }
-
- @Test
- public void testSetIndexedColumnToNullAndValueAtSameTSWithStoreNulls2() throws Exception {
- try {
- final MyClock clock = new MyClock(1000);
- EnvironmentEdgeManager.injectEdge(clock);
- String tableName = generateUniqueName();
- String indexName = generateUniqueName();
- Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
- long ts = 1000;
- clock.time = ts;
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
- conn.close();
-
- ts = 1010;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
- conn.close();
-
- ts = 1020;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
- stmt.setTimestamp(1, new Timestamp(1000L));
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- Timestamp expectedTimestamp;
- ts = 1040;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
- expectedTimestamp = new Timestamp(3000L);
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- expectedTimestamp = null;
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- ts = 1050;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
-
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
- IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
-
- ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName);
- assertTrue(rs.next());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- assertEquals(null, rs.getString(2));
- assertFalse(rs.next());
-
- rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
- assertTrue(rs.next());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- assertEquals(null, rs.getString(2));
- assertFalse(rs.next());
-
- conn.close();
- } finally {
- EnvironmentEdgeManager.injectEdge(null);
- }
- }
-
- @Test
- public void testDeleteRowAndUpsertValueAtSameTS1() throws Exception {
- try {
- final MyClock clock = new MyClock(1000);
- EnvironmentEdgeManager.injectEdge(clock);
- String tableName = generateUniqueName();
- String indexName = generateUniqueName();
- Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
- long ts = 1000;
- clock.time = ts;
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, A.V VARCHAR, B.V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
- conn.close();
-
- ts = 1010;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
- conn.close();
-
- ts = 1020;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0','1')");
- stmt.setTimestamp(1, new Timestamp(1000L));
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- Timestamp expectedTimestamp;
- ts = 1040;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')");
- stmt.executeUpdate();
- conn.commit();
- expectedTimestamp = new Timestamp(3000L);
- stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null,'3')");
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- ts = 1050;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
-
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
- long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
- assertEquals(0,rowCount);
-
- conn.close();
- } finally {
- EnvironmentEdgeManager.injectEdge(null);
- }
- }
-
- @Test
- public void testDeleteRowAndUpsertValueAtSameTS2() throws Exception {
- try {
- final MyClock clock = new MyClock(1000);
- EnvironmentEdgeManager.injectEdge(clock);
- String tableName = generateUniqueName();
- String indexName = generateUniqueName();
- Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
- long ts = 1000;
- clock.time = ts;
- Connection conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
- conn.close();
-
- ts = 1010;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
- conn.close();
-
- ts = 1020;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
- stmt.setTimestamp(1, new Timestamp(1000L));
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- Timestamp expectedTimestamp;
- ts = 1040;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
- expectedTimestamp = new Timestamp(3000L);
- stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
- stmt.setTimestamp(1, expectedTimestamp);
- stmt.executeUpdate();
- conn.commit();
- stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')");
- stmt.executeUpdate();
- conn.commit();
- conn.close();
-
- ts = 1050;
- clock.time = ts;
- conn = DriverManager.getConnection(getUrl(), props);
-
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
- long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
- assertEquals(0,rowCount);
-
- conn.close();
- } finally {
- EnvironmentEdgeManager.injectEdge(null);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index 33193ff..a77305c 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -1020,6 +1020,10 @@ public abstract class BaseTest {
}
}
+ protected static String initATableValues(String tenantId, byte[][] splits) throws Exception {
+ return initATableValues(tenantId, splits, null, null, getUrl());
+ }
+
protected static String initATableValues(String tenantId, byte[][] splits, Date date, Long ts) throws Exception {
return initATableValues(tenantId, splits, date, ts, getUrl());
}
[4/4] phoenix git commit: PHOENIX-4180 Modify tests to generate
unique table names and not use CURRENT_SCN (Rahul Shrivastava)
Posted by ja...@apache.org.
PHOENIX-4180 Modify tests to generate unique table names and not use CURRENT_SCN (Rahul Shrivastava)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/26a7b9e8
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/26a7b9e8
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/26a7b9e8
Branch: refs/heads/master
Commit: 26a7b9e8b051c270ae8003332ed2ebb4bb91d972
Parents: 41e1371
Author: James Taylor <jt...@salesforce.com>
Authored: Wed Sep 13 15:45:00 2017 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Wed Sep 13 15:47:21 2017 -0700
----------------------------------------------------------------------
.../org/apache/phoenix/end2end/ArrayIT.java | 516 +++++-----------
.../end2end/ClientTimeArithmeticQueryIT.java | 26 -
.../end2end/ColumnProjectionOptimizationIT.java | 31 +-
.../phoenix/end2end/ConcurrentMutationsIT.java | 406 ++++++++++--
.../CursorWithRowValueConstructorIT.java | 617 +++++++++----------
.../phoenix/end2end/OutOfOrderMutationsIT.java | 386 ------------
.../java/org/apache/phoenix/query/BaseTest.java | 4 +
7 files changed, 799 insertions(+), 1187 deletions(-)
----------------------------------------------------------------------
[3/4] phoenix git commit: PHOENIX-4180 Modify tests to generate
unique table names and not use CURRENT_SCN (Rahul Shrivastava)
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
index 550c115..d05a200 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArrayIT.java
@@ -17,7 +17,6 @@
*/
package org.apache.phoenix.end2end;
-import static org.apache.phoenix.util.PhoenixRuntime.CURRENT_SCN_ATTRIB;
import static org.apache.phoenix.util.TestUtil.B_VALUE;
import static org.apache.phoenix.util.TestUtil.ROW1;
import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
@@ -35,37 +34,21 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
-import java.util.Map;
import java.util.Properties;
import org.apache.phoenix.query.BaseTest;
-import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.schema.types.PhoenixArray;
-import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
import org.apache.phoenix.util.StringUtil;
-import org.junit.BeforeClass;
import org.junit.Test;
-import com.google.common.collect.Maps;
import com.google.common.primitives.Floats;
-public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
+public class ArrayIT extends ParallelStatsDisabledIT {
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String,String> props = Maps.newHashMapWithExpectedSize(5);
- props.put(QueryServices.STATS_USE_CURRENT_TIME_ATTRIB, Boolean.FALSE.toString());
- setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
- }
-
- private static void initTablesWithArrays(String tableName, String tenantId, Date date, Long ts, boolean useNull, String url) throws Exception {
+ private static void initTablesWithArrays(String tableName, String tenantId, Date date, boolean useNull, String url) throws Exception {
Properties props = new Properties();
- if (ts != null) {
- props.setProperty(CURRENT_SCN_ATTRIB, ts.toString());
- }
Connection conn = DriverManager.getConnection(url, props);
try {
// Insert all rows at ts
@@ -141,15 +124,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testScanByArrayValue() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT a_double_array, /* comment ok? */ b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_float";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
//TODO: samarth do we need this
analyzeTable(conn, tableName);
@@ -186,15 +166,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testScanWithArrayInWhereClause() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT a_double_array, /* comment ok? */ b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_byte_array";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
//TODO: samarth do we need this?
analyzeTable(conn, tableName);
@@ -229,15 +206,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testScanWithNonFixedWidthArrayInWhereClause() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT a_double_array, /* comment ok? */ b_string, a_float FROM " + tableName + " WHERE ?=organization_id and ?=a_string_array";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -272,15 +246,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testScanWithNonFixedWidthArrayInSelectClause() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT a_string_array FROM " + tableName;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -304,15 +275,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSpecificIndexOfAnArrayAsArrayFunction()
throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT ARRAY_ELEM(a_double_array,2) FROM " + tableName;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -332,15 +300,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSpecificIndexOfAnArray() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT a_double_array[3] FROM " + tableName;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -359,15 +324,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testCaseWithArray() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String tableName = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(tableName, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(tableName, tenantId, null, false, getUrl());
String query = "SELECT CASE WHEN A_INTEGER = 1 THEN a_double_array ELSE null END [3] FROM " + tableName;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -386,13 +348,11 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testUpsertValuesWithArray() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- String tableName = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+ String tableName = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
String query = "upsert into " + tableName + " (ORGANIZATION_ID,ENTITY_ID,a_double_array) values('" + tenantId
+ "','00A123122312312',ARRAY[2.0,345.8])";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute
// at
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
@@ -404,7 +364,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.close();
// create another connection
props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
query = "SELECT ARRAY_ELEM(a_double_array,2) FROM " + tableName;
statement = conn.prepareStatement(query);
@@ -424,15 +383,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testUpsertSelectWithSelectAsSubQuery1() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- String table1 = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+ String table1 = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
Connection conn = null;
try {
- String table2 = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table2, tenantId, null, ts, false);
+ String table2 = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table2, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "upsert into " + table1 + " (ORGANIZATION_ID,ENTITY_ID,a_double_array) "
+ "SELECT organization_id, entity_id, a_double_array FROM " + table2
@@ -445,7 +402,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.close();
// create another connection
props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
conn = DriverManager.getConnection(getUrl(), props);
query = "SELECT ARRAY_ELEM(a_double_array,2) FROM " + table1;
statement = conn.prepareStatement(query);
@@ -467,14 +423,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArraySelectWithORCondition() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
Connection conn = null;
try {
- String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table, tenantId, null, ts, false);
+ String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "SELECT a_double_array[1] FROM " + table
+ " WHERE a_double_array[2] = 89.96 or a_char_array[0] = 'a'";
@@ -496,14 +450,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArraySelectWithANY() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
Connection conn = null;
try {
- String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table, tenantId, null, ts, false);
+ String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "SELECT a_double_array[1] FROM " + table
+ " WHERE CAST(89.96 AS DOUBLE) = ANY(a_double_array)";
@@ -524,14 +476,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArraySelectWithALL() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
Connection conn = null;
try {
- String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table, tenantId, null, ts, false);
+ String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "SELECT a_double_array[1] FROM " + table
+ " WHERE CAST(64.87 as DOUBLE) = ALL(a_double_array)";
@@ -547,14 +497,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArraySelectWithANYCombinedWithOR() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
Connection conn = null;
try {
- String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table, tenantId, null, ts, false);
+ String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "SELECT a_double_array[1] FROM " + table
+ " WHERE a_char_array[0] = 'f' or CAST(89.96 AS DOUBLE) > ANY(a_double_array)";
@@ -575,14 +523,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArraySelectWithALLCombinedWithOR() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
Connection conn = null;
try {
- String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table, tenantId, null, ts, false);
+ String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "SELECT a_double_array[1], a_double_array[2] FROM " + table
+ " WHERE a_char_array[0] = 'f' or CAST(100.0 AS DOUBLE) > ALL(a_double_array)";
@@ -608,12 +555,11 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
public void testArraySelectWithANYUsingVarLengthArray() throws Exception {
Connection conn = null;
try {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "SELECT a_string_array[1] FROM " + table
+ " WHERE 'XYZWER' = ANY(a_string_array)";
@@ -641,14 +587,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectWithArrayWithColumnRef() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_integer,ARRAY[1,2,a_integer] FROM " + table + " where organization_id = '"
+ tenantId + "'";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -673,14 +618,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectWithArrayWithColumnRefWithVarLengthArray() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT b_string,ARRAY['abc','defgh',b_string] FROM " + table + " where organization_id = '"
+ tenantId + "'";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -708,14 +652,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectWithArrayWithColumnRefWithVarLengthArrayWithNullValue() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT b_string,ARRAY['abc',null,'bcd',null,null,b_string] FROM " + table + " where organization_id = '"
+ tenantId + "'";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -745,15 +688,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testUpsertSelectWithColumnRef() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table1 = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+ String table1 = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
Connection conn = null;
try {
- String table2 = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table2, tenantId, null, ts, false);
+ String table2 = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table2, tenantId, null, false);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
String query = "upsert into " + table1 + " (ORGANIZATION_ID,ENTITY_ID, a_unsigned_double, a_double_array) "
+ "SELECT organization_id, entity_id, x_double, ARRAY[23.4, 22.1, x_double] FROM " + table2
@@ -766,7 +708,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.close();
// create another connection
props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 4));
conn = DriverManager.getConnection(getUrl(), props);
query = "SELECT ARRAY_ELEM(a_double_array,2) FROM " + table1;
statement = conn.prepareStatement(query);
@@ -788,13 +729,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testCharArraySpecificIndex() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
- initSimpleArrayTable(table, tenantId, null, ts, false);
+ String table = createSimpleTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
+ initSimpleArrayTable(table, tenantId, null, false);
String query = "SELECT a_char_array[2] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -814,16 +754,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute(
"CREATE TABLE " + table + " ( 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 DESC)) \n");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES(?,?,?)");
stmt.setString(1, "a");
@@ -837,7 +775,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT b_string_array FROM " + table);
assertTrue(rs.next());
@@ -852,22 +789,19 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + table + " ( k VARCHAR PRIMARY KEY, a Float ARRAY[])");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES('a',ARRAY[2.0,3.0])");
int res = stmt.executeUpdate();
assertEquals(1, res);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ARRAY_ELEM(a,2) FROM " + table);
assertTrue(rs.next());
@@ -881,22 +815,19 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + table + " ( k VARCHAR PRIMARY KEY, a VARCHAR ARRAY[])");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES('a',ARRAY['a',null])");
int res = stmt.executeUpdate();
assertEquals(1, res);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ARRAY_ELEM(a,2) FROM " + table);
assertTrue(rs.next());
@@ -909,15 +840,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + table + " ( k VARCHAR PRIMARY KEY, a bigint ARRAY[])");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES(?,?)");
stmt.setString(1, "a");
@@ -927,7 +856,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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, CAST(a[2] AS DOUBLE) FROM " + table);
assertTrue(rs.next());
@@ -941,15 +869,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
public void testArraySelectGetString() throws Exception {
Connection conn;
PreparedStatement stmt;
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
// create the table
- String tableName = createTableWithAllArrayTypes(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+ String tableName = createTableWithAllArrayTypes(getUrl(), getDefaultSplits(tenantId), null);
// populate the table with data
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
conn = DriverManager.getConnection(getUrl(), props);
stmt =
conn.prepareStatement("UPSERT INTO "
@@ -994,7 +921,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt =
conn.prepareStatement("SELECT organization_id, entity_id, boolean_array, byte_array, double_array, float_array, int_array, long_array, short_array, string_array FROM "
@@ -1030,15 +956,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + table + " ( k VARCHAR PRIMARY KEY, a bigint ARRAY[])");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES(?,?)");
stmt.setString(1, "a");
@@ -1048,7 +972,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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 CAST(a AS DOUBLE []) FROM " + table);
assertTrue(rs.next());
@@ -1065,14 +988,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + table + " ( k VARCHAR PRIMARY KEY, a VARCHAR(5) ARRAY)");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES(?,?)");
stmt.setString(1, "a");
@@ -1083,7 +1004,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT CAST(a AS CHAR ARRAY) FROM " + table);
assertTrue(rs.next());
@@ -1102,22 +1022,19 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement().execute("CREATE TABLE " + table + " ( 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, table, "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 " + table + " VALUES(?,?)");
stmt.setString(1, "a");
@@ -1128,7 +1045,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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 " + table);
assertTrue(rs.next());
@@ -1139,15 +1055,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectArrayUsingUpsertLikeSyntax() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_double_array FROM " + table + " WHERE a_double_array = CAST(ARRAY [ 25.343, 36.763, 37.56,386.63] AS DOUBLE ARRAY)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1170,16 +1083,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayIndexUsedInWhereClause() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
int a_index = 0;
String query = "SELECT a_double_array[2] FROM " + table + " where a_double_array["+a_index+"2]<?";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1202,15 +1112,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayIndexUsedInGroupByClause() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_double_array[2] FROM " + table + " GROUP BY a_double_array[2]";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1231,15 +1138,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testVariableLengthArrayWithNullValue() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, true, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, true, getUrl());
String query = "SELECT a_string_array[2] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1256,15 +1160,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSpecificIndexOfAVariableArrayAlongWithAnotherColumn1() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_string_array[3],A_INTEGER FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1284,15 +1185,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSpecificIndexOfAVariableArrayAlongWithAnotherColumn2() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT A_INTEGER, a_string_array[3] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1312,15 +1211,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectMultipleArrayColumns() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_string_array[3], a_double_array[2] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1342,17 +1239,15 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSameArrayColumnMultipleTimesWithDifferentIndices() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_string_array[1], a_string_array[2], " +
"a_string_array[3], a_double_array[1], a_double_array[2], a_double_array[3] " +
"FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1372,15 +1267,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSameArrayColumnMultipleTimesWithSameIndices() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_string_array[3], a_string_array[3] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1400,15 +1293,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testSelectSpecificIndexOfAVariableArray() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_string_array[3] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1426,15 +1316,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testWithOutOfRangeIndex() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT a_double_array[100] FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1449,15 +1336,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayLengthFunctionForVariableLength() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT ARRAY_LENGTH(a_string_array) FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1474,15 +1358,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayLengthFunctionForFixedLength() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
- initTablesWithArrays(table, tenantId, null, ts, false, getUrl());
+ getDefaultSplits(tenantId), null);
+ initTablesWithArrays(table, tenantId, null, false, getUrl());
String query = "SELECT ARRAY_LENGTH(a_double_array) FROM " + table;
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
PreparedStatement statement = conn.prepareStatement(query);
@@ -1498,13 +1379,11 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArraySizeRoundtrip() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
String table = createTableWithArray(getUrl(),
- getDefaultSplits(tenantId), null, ts - 2);
+ getDefaultSplits(tenantId), null);
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(ts + 2)); // Execute at timestamp 2
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
ResultSet rs = conn.getMetaData().getColumns(null, null, StringUtil.escapeLike(table), StringUtil.escapeLike(SchemaUtil.normalizeIdentifier("x_long_array")));
@@ -1533,9 +1412,8 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement()
@@ -1543,7 +1421,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
"CREATE TABLE " + table + " ( 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 " + table + " VALUES(?,?,?)");
stmt.setString(1, "a");
@@ -1557,7 +1434,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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 " + table + " where a_string_array=b_string_array");
assertTrue(rs.next());
@@ -1572,16 +1448,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement()
.execute(
"CREATE TABLE " + table + " ( 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 " + table + " VALUES(?,?,?)");
stmt.setString(1, "a");
@@ -1595,7 +1469,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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 " + table + " where a_string_array<b_string_array");
@@ -1611,16 +1484,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement()
.execute(
"CREATE TABLE " + table + " ( 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 " + table + " VALUES(?,?,?)");
stmt.setString(1, "a");
@@ -1634,7 +1505,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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 " + table + " where a_string_array>b_string_array");
@@ -1646,13 +1516,12 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testUpsertValuesWithNull() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+ String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
String query = "upsert into " + table + " (ORGANIZATION_ID,ENTITY_ID,a_double_array) values('" + tenantId
+ "','00A123122312312',null)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute
// at
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
@@ -1664,7 +1533,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.close();
// create another connection
props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
query = "SELECT ARRAY_ELEM(a_double_array,2) FROM " + table;
statement = conn.prepareStatement(query);
@@ -1684,12 +1552,11 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testUpsertValuesWithNullUsingPreparedStmt() throws Exception {
- long ts = nextTimestamp();
+
String tenantId = getOrganizationId();
- String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null, ts - 2);
+ String table = createTableWithArray(getUrl(), getDefaultSplits(tenantId), null);
String query = "upsert into " + table + " (ORGANIZATION_ID,ENTITY_ID,a_string_array) values(?, ?, ?)";
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts)); // Execute
// at
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
@@ -1704,7 +1571,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.close();
// create another connection
props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 2
conn = DriverManager.getConnection(getUrl(), props);
query = "SELECT ARRAY_ELEM(a_string_array,1) FROM " + table;
statement = conn.prepareStatement(query);
@@ -1726,9 +1592,8 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement()
@@ -1736,7 +1601,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
"CREATE TABLE " + table + " ( 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 " + table + " VALUES(?,?,?)");
stmt.setString(1, "a");
@@ -1750,7 +1614,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
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 " + table + " where b_string_array[8]='xxx'");
@@ -1763,9 +1626,8 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testPKWithArrayNotInEnd() throws Exception {
Connection conn;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
try {
@@ -1786,9 +1648,8 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayRefToLiteral() throws Exception {
Connection conn;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(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");
@@ -1807,8 +1668,7 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
}
- private static String createTableWithAllArrayTypes(String url, byte[][] bs, Object object,
- long ts) throws SQLException {
+ private static String createTableWithAllArrayTypes(String url, byte[][] bs, Object object) throws SQLException {
String tableName = generateUniqueName();
String ddlStmt = "create table "
+ tableName
@@ -1824,12 +1684,11 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
+ " string_array varchar(100) array[3],\n"
+ " CONSTRAINT pk PRIMARY KEY (organization_id, entity_id)\n"
+ ")";
- BaseTest.createTestTable(url, ddlStmt, bs, ts);
+ BaseTest.createTestTable(url, ddlStmt, bs, null);
return tableName;
}
- static String createTableWithArray(String url, byte[][] bs, Object object,
- long ts) throws SQLException {
+ private static String createTableWithArray(String url, byte[][] bs, Object object) throws SQLException {
String tableName = generateUniqueName();
String ddlStmt = "create table "
+ tableName
@@ -1852,12 +1711,11 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
+ " a_unsigned_double unsigned_double \n"
+ " CONSTRAINT pk PRIMARY KEY (organization_id, entity_id)\n"
+ ")";
- BaseTest.createTestTable(url, ddlStmt, bs, ts);
+ BaseTest.createTestTable(url, ddlStmt, bs, null);
return tableName;
}
- static String createSimpleTableWithArray(String url, byte[][] bs, Object object,
- long ts) throws SQLException {
+ private static String createSimpleTableWithArray(String url, byte[][] bs, Object object) throws SQLException {
String tableName = generateUniqueName();
String ddlStmt = "create table "
+ tableName
@@ -1868,15 +1726,13 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
+ " a_char_array char(5) array[],\n"
+ " CONSTRAINT pk PRIMARY KEY (organization_id, entity_id)\n"
+ ")";
- BaseTest.createTestTable(url, ddlStmt, bs, ts);
+ BaseTest.createTestTable(url, ddlStmt, bs, null);
return tableName;
}
- protected static void initSimpleArrayTable(String tableName, 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());
- }
+ private static void initSimpleArrayTable(String tableName, String tenantId, Date date, boolean useNull) throws Exception {
+ Properties props = new Properties();
+
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
// Insert all rows at ts
@@ -1915,16 +1771,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayConstructorWithMultipleRows1() throws Exception {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (region_name VARCHAR PRIMARY KEY, a INTEGER, b INTEGER)";
conn.createStatement().execute(ddl);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " (region_name, a, b) VALUES('a', 6,3)");
stmt.execute();
@@ -1934,7 +1788,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT ARRAY[a,b]) from " + table);
@@ -1944,16 +1797,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayConstructorWithMultipleRows2() throws Exception {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (region_name VARCHAR PRIMARY KEY, a INTEGER, b INTEGER)";
conn.createStatement().execute(ddl);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " (region_name, a, b) VALUES('a', 6,3)");
stmt.execute();
@@ -1963,7 +1814,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT ARRAY[a,b] from " + table + " ");
@@ -1981,16 +1831,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayConstructorWithMultipleRows3() throws Exception {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (region_name VARCHAR PRIMARY KEY, a VARCHAR, b VARCHAR)";
conn.createStatement().execute(ddl);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " (region_name, a, b) VALUES('a', 'foo', 'abc')");
stmt.execute();
@@ -2000,7 +1848,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT ARRAY[a,b] from " + table + " ");
@@ -2018,16 +1865,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayConstructorWithMultipleRows4() throws Exception {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (region_name VARCHAR PRIMARY KEY, a VARCHAR, b VARCHAR)";
conn.createStatement().execute(ddl);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " (region_name, a, b) VALUES('a', 'foo', 'abc')");
stmt.execute();
@@ -2037,7 +1882,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT ARRAY[a,b]) from " + table);
@@ -2047,16 +1891,14 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testArrayConstructorWithMultipleRows5() throws Exception {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (region_name VARCHAR PRIMARY KEY, a VARCHAR, b VARCHAR)";
conn.createStatement().execute(ddl);
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 20));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " (region_name, a, b) VALUES('a', 'foo', 'abc')");
stmt.execute();
@@ -2066,7 +1908,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
rs = conn.createStatement().executeQuery("SELECT ARRAY_APPEND(ARRAY[a,b], 'oo') from " + table);
@@ -2087,9 +1928,8 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
Connection conn;
PreparedStatement stmt;
ResultSet rs;
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
conn.createStatement()
@@ -2097,7 +1937,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
"CREATE TABLE " + table + " ( a VARCHAR ARRAY PRIMARY KEY DESC)\n");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES(?)");
Array a1 = conn.createArrayOf("VARCHAR", new String[] { "a", "ba" });
@@ -2109,7 +1948,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT a FROM " + table + " ORDER BY a DESC");
assertTrue(rs.next());
@@ -2119,7 +1957,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
assertFalse(rs.next());
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 50));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES(?)");
Array a3 = conn.createArrayOf("VARCHAR", new String[] { "a", "b" });
@@ -2128,7 +1965,6 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT a FROM " + table + " ORDER BY a DESC");
assertTrue(rs.next());
@@ -2143,23 +1979,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc1()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k varchar array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array['a', 'c'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k >= array['a', 'b']");
@@ -2169,23 +2002,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc2()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k varchar array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array['a', 'c'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k >= array['a', 'c']");
@@ -2195,23 +2025,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc3()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k varchar array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array['a', 'c'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k > array['a', 'b']");
@@ -2221,23 +2048,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc4()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k varchar array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array['a', 'b'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k <= array['a', 'c']");
@@ -2247,23 +2071,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc5()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k varchar array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array['a', 'b'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k <= array['a', 'b']");
@@ -2273,23 +2094,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc6()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k varchar array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array['a', 'b'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k < array['a', 'c']");
@@ -2299,23 +2117,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc7()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k integer array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array[1, 2])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k < array[1, 4]");
@@ -2325,23 +2140,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testComparisonOperatorsForDesc8()throws Exception{
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "create table " + table + " (k integer array primary key desc)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("upsert into " + table + " values (array[1, 2])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("select * from " + table + " where k <= array[1, 2]");
@@ -2351,23 +2163,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection1() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 VARCHAR ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES (1, ARRAY[1, 2], ARRAY['a', 'b'])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("SELECT arr1, arr1[1], arr2[1] FROM " + table);
@@ -2380,23 +2189,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection2() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 VARCHAR ARRAY, arr3 INTEGER ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES (1, ARRAY[1, 2], ARRAY['a', 'b'], ARRAY[2, 3])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("SELECT arr1, arr1[1], arr2[1], arr3[1] from " + table);
@@ -2410,23 +2216,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection3() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 VARCHAR ARRAY, arr3 INTEGER ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES (1, ARRAY[1, 2], ARRAY['a', 'b'], ARRAY[2, 3])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("SELECT arr1, arr1[1], arr2[1], arr3, arr3[1] from " + table);
@@ -2441,23 +2244,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection4() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 VARCHAR ARRAY, arr3 INTEGER ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES (1, ARRAY[1, 2], ARRAY['a', 'b'], ARRAY[2, 3])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("SELECT arr1, arr1[1], arr2[1], ARRAY_APPEND(arr3, 4), arr3[1] from " + table);
@@ -2472,23 +2272,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection5() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr3 INTEGER ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES (1, ARRAY[1, 2], ARRAY[2, 3])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("SELECT arr1, arr1[1], ARRAY_APPEND(arr1, arr3[1]) from " + table);
@@ -2501,23 +2298,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection6() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 INTEGER ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + table + " VALUES (1, ARRAY[1, 2], ARRAY[2, 3])");
stmt.execute();
conn.commit();
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
conn = DriverManager.getConnection(getUrl(), props);
ResultSet rs;
stmt = conn.prepareStatement("SELECT arr1, arr1[1], ARRAY_APPEND(arr1, arr2[1]), p from " + table);
@@ -2531,23 +2325,20 @@ public class ArrayIT extends BaseUniqueNamesOwnClusterIT {
@Test
public void testServerArrayElementProjection7() throws SQLException {
- long ts = nextTimestamp();
+
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn = DriverManager.getConnection(getUrl(), props);
String table = generateUniqueName();
String ddl = "CREATE TABLE " + table + " (p INTEGER PRIMARY KEY, arr1 INTEGER ARRAY, arr2 INTEGER ARRAY)";
conn.createStatement().execute(ddl);
conn.close();
- props.setPrope
<TRUNCATED>
[2/4] phoenix git commit: PHOENIX-4180 Modify tests to generate
unique table names and not use CURRENT_SCN (Rahul Shrivastava)
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
index 52044a8..46dd598 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ClientTimeArithmeticQueryIT.java
@@ -47,7 +47,6 @@ import java.util.Collection;
import java.util.List;
import java.util.Properties;
-import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -616,27 +615,22 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
ResultSet rs;
String tName = generateUniqueName();
- long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement()
.execute(
"create table " + tName + " (ts timestamp primary key)");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
stmt.setTimestamp(1, new Timestamp(1995 - 1900, 4, 2, 1, 1, 1, 1));
stmt.execute();
conn.commit();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName + "");
assertTrue(rs.next());
assertEquals("1995-05-02 01:01:01.000000001",rs.getTimestamp(1).toString());
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts + 1 FROM " + tName + "");
assertTrue(rs.next());
@@ -649,27 +643,22 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
PreparedStatement stmt;
ResultSet rs;
String tName = generateUniqueName();
- long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement()
.execute(
"create table " + tName + " (ts timestamp primary key)");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
stmt.setTimestamp(1, new Timestamp(1995 - 1900, 4, 2, 1, 1, 1, 1));
stmt.execute();
conn.commit();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName);
assertTrue(rs.next());
assertEquals("1995-05-02 01:01:01.000000001",rs.getTimestamp(1).toString());
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts - 1 FROM " + tName);
assertTrue(rs.next());
@@ -683,28 +672,23 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
ResultSet rs;
String tName = generateUniqueName();
- long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement()
.execute(
"create table " + tName + " (ts time primary key)");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
Time time = new Time(1995 - 1900, 4, 2);
stmt.setTime(1, time);
stmt.execute();
conn.commit();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName);
assertTrue(rs.next());
assertEquals(time.getTime(),rs.getTimestamp(1).getTime());
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts + 1 FROM " + tName);
assertTrue(rs.next());
@@ -717,28 +701,23 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
PreparedStatement stmt;
ResultSet rs;
String tName = generateUniqueName();
- long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement()
.execute(
"create table " + tName + " (ts time primary key)");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
Time time = new Time(1995 - 1900, 4, 2);
stmt.setTime(1, time);
stmt.execute();
conn.commit();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName + "");
assertTrue(rs.next());
assertEquals(time.getTime(),rs.getTimestamp(1).getTime());
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts - 1 FROM " + tName);
assertTrue(rs.next());
@@ -752,27 +731,22 @@ public class ClientTimeArithmeticQueryIT extends BaseQueryIT {
ResultSet rs;
String tName = generateUniqueName();
- long ts = nextTimestamp();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement()
.execute(
"create table " + tName + " (ts date primary key)");
conn.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
conn = DriverManager.getConnection(getUrl(), props);
stmt = conn.prepareStatement("upsert into " + tName + " values (?)");
stmt.setDate(1, new Date(1995 - 1900, 4, 2));
stmt.execute();
conn.commit();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 60));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts FROM " + tName);
assertTrue(rs.next());
assertEquals("1995-05-02",rs.getDate(1).toString());
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 70));
conn = DriverManager.getConnection(getUrl(), props);
rs = conn.createStatement().executeQuery("SELECT ts - 1 FROM " + tName);
assertTrue(rs.next());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
index 05de7f3..e4ff66f 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ColumnProjectionOptimizationIT.java
@@ -52,7 +52,6 @@ import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.schema.types.PInteger;
import org.apache.phoenix.schema.types.PLong;
import org.apache.phoenix.schema.types.PVarchar;
-import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.SchemaUtil;
import org.junit.Test;
@@ -62,12 +61,10 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
@Test
public void testSelect() throws Exception {
- long ts = nextTimestamp();
String tenantId = getOrganizationId();
- String tableName = initATableValues(tenantId, getDefaultSplits(tenantId), null, ts);
+ String tableName = initATableValues(tenantId, getDefaultSplits(tenantId));
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
Connection conn = DriverManager.getConnection(getUrl(), props);
// Table wildcard query
@@ -229,9 +226,7 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
}
admin.createTable(descriptor);
- long ts = nextTimestamp();
Properties props = new Properties();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
Connection conn1 = DriverManager.getConnection(getUrl(), props);
String createStmt = "create view " + table + " (id integer not null primary key,"
@@ -239,7 +234,6 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
conn1.createStatement().execute(createStmt);
conn1.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 6));
PhoenixConnection conn2 = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
byte[] c1 = Bytes.toBytes("COL1");
byte[] c2 = Bytes.toBytes("COL2");
@@ -248,24 +242,23 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
try {
htable = conn2.getQueryServices().getTable(htableName);
Put put = new Put(PInteger.INSTANCE.toBytes(1));
- put.add(cfB, c1, ts + 6, PInteger.INSTANCE.toBytes(1));
- put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(2));
+ put.add(cfB, c1, PInteger.INSTANCE.toBytes(1));
+ put.add(cfC, c2, PLong.INSTANCE.toBytes(2));
htable.put(put);
put = new Put(PInteger.INSTANCE.toBytes(2));
- put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(10));
- put.add(cfC, c3, ts + 6, PVarchar.INSTANCE.toBytes("abcd"));
+ put.add(cfC, c2, PLong.INSTANCE.toBytes(10));
+ put.add(cfC, c3, PVarchar.INSTANCE.toBytes("abcd"));
htable.put(put);
put = new Put(PInteger.INSTANCE.toBytes(3));
- put.add(cfB, c1, ts + 6, PInteger.INSTANCE.toBytes(3));
- put.add(cfC, c2, ts + 6, PLong.INSTANCE.toBytes(10));
- put.add(cfC, c3, ts + 6, PVarchar.INSTANCE.toBytes("abcd"));
+ put.add(cfB, c1, PInteger.INSTANCE.toBytes(3));
+ put.add(cfC, c2, PLong.INSTANCE.toBytes(10));
+ put.add(cfC, c3, PVarchar.INSTANCE.toBytes("abcd"));
htable.put(put);
conn2.close();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
Connection conn7 = DriverManager.getConnection(getUrl(), props);
String select = "SELECT id, b.col1 FROM " + table + " WHERE c.col2=?";
PreparedStatement ps = conn7.prepareStatement(select);
@@ -312,11 +305,10 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
}
- private static String initMultiCFTable(long ts) throws Exception {
+ private static String initMultiCFTable() throws Exception {
String url = getUrl();
String tableName = generateUniqueName();
Properties props = new Properties();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
String ddl = "create table " + tableName +
" (id char(15) not null primary key,\n" +
" a.unique_user_count integer,\n" +
@@ -330,7 +322,6 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
conn.createStatement().execute(ddl);
}
props = new Properties();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2));
Connection conn = DriverManager.getConnection(url, props);
try {
PreparedStatement stmt = conn.prepareStatement(
@@ -361,11 +352,9 @@ public class ColumnProjectionOptimizationIT extends ParallelStatsDisabledIT {
@Test
public void testSelectWithConditionOnMultiCF() throws Exception {
- long ts = nextTimestamp();
- String tableName = initMultiCFTable(ts);
+ String tableName = initMultiCFTable();
Properties props = new Properties();
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 5));
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
String query = "SELECT c.db_cpu_utilization FROM " + tableName + " WHERE a.unique_user_count = ? and b.unique_org_count = ?";
http://git-wip-us.apache.org/repos/asf/phoenix/blob/26a7b9e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
index 6d327f7..e5f22da 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ConcurrentMutationsIT.java
@@ -25,8 +25,10 @@ import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.Properties;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
@@ -34,8 +36,6 @@ import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseIOException;
-import org.apache.hadoop.hbase.HTableDescriptor;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.Mutation;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
@@ -43,14 +43,14 @@ import org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver;
import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.query.ConnectionQueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.EnvironmentEdge;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
import org.apache.phoenix.util.IndexScrutiny;
-import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.Repeat;
import org.apache.phoenix.util.RunUntilFailure;
import org.apache.phoenix.util.TestUtil;
+import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,36 +62,27 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
private static final int ROW_LOCK_WAIT_TIME = 10000;
private final Object lock = new Object();
- private long scn = 100;
-
- private static void addDelayingCoprocessor(Connection conn, String tableName) throws Exception {
- int priority = QueryServicesOptions.DEFAULT_COPROCESSOR_PRIORITY + 100;
- ConnectionQueryServices services = conn.unwrap(PhoenixConnection.class).getQueryServices();
- HTableDescriptor descriptor = services.getTableDescriptor(Bytes.toBytes(tableName));
- descriptor.addCoprocessor(DelayingRegionObserver.class.getName(), null, priority, null);
- int numTries = 10;
- try (HBaseAdmin admin = services.getAdmin()) {
- admin.modifyTable(Bytes.toBytes(tableName), descriptor);
- while (!admin.getTableDescriptor(Bytes.toBytes(tableName)).equals(descriptor)
- && numTries > 0) {
- numTries--;
- if (numTries == 0) {
- throw new Exception(
- "Check to detect if delaying co-processor was added failed after "
- + numTries + " retries.");
- }
- Thread.sleep(1000);
- }
+
+ private static class MyClock extends EnvironmentEdge {
+ public volatile long time;
+
+ public MyClock (long time) {
+ this.time = time;
+ }
+
+ @Override
+ public long currentTime() {
+ return time;
}
}
-
+
@Test
public void testSynchronousDeletesAndUpsertValues() throws Exception {
final String tableName = generateUniqueName();
final String indexName = generateUniqueName();
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0");
- addDelayingCoprocessor(conn, tableName);
+ TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v1)");
final CountDownLatch doneSignal = new CountDownLatch(2);
Runnable r1 = new Runnable() {
@@ -103,10 +94,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
for (int i = 0; i < 50; i++) {
Thread.sleep(20);
synchronized (lock) {
- scn += 10;
PhoenixConnection conn = null;
try {
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(scn));
conn = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
conn.setAutoCommit(true);
conn.createStatement().execute("DELETE FROM " + tableName);
@@ -135,10 +124,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
int nRowsToUpsert = 1000;
for (int i = 0; i < nRowsToUpsert; i++) {
synchronized(lock) {
- scn += 10;
PhoenixConnection conn = null;
try {
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(scn));
conn = DriverManager.getConnection(getUrl(), props).unwrap(PhoenixConnection.class);
conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES (" + (i % 10) + ", 0, 1)");
if ((i % 20) == 0 || i == nRowsToUpsert-1 ) {
@@ -163,9 +150,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
t2.start();
doneSignal.await(60, TimeUnit.SECONDS);
- long count1 = getRowCount(conn, tableName);
- long count2 = getRowCount(conn, indexName);
- assertTrue("Expected table row count ( " + count1 + ") to match index row count (" + count2 + ")", count1 == count2);
+ IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
}
@Test
@@ -174,7 +159,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
final String indexName = generateUniqueName();
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2))");
- addDelayingCoprocessor(conn, tableName);
+ TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v1)");
final CountDownLatch doneSignal = new CountDownLatch(2);
Runnable r1 = new Runnable() {
@@ -226,9 +211,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
t2.start();
doneSignal.await(60, TimeUnit.SECONDS);
- long count1 = getRowCount(conn, tableName);
- long count2 = getRowCount(conn, indexName);
- assertTrue("Expected table row count ( " + count1 + ") to match index row count (" + count2 + ")", count1 == count2);
+ IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
}
@Test
@@ -242,7 +225,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
final String indexName = generateUniqueName();
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 INTEGER, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, VERSIONS=1");
- addDelayingCoprocessor(conn, tableName);
+ TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v1)");
final CountDownLatch doneSignal = new CountDownLatch(nThreads);
Runnable[] runnables = new Runnable[nThreads];
@@ -288,7 +271,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE " + tableName + "(k VARCHAR PRIMARY KEY, v INTEGER) COLUMN_ENCODED_BYTES = 0");
- addDelayingCoprocessor(conn, tableName);
+ TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v)");
final CountDownLatch doneSignal = new CountDownLatch(2);
final String[] failedMsg = new String[1];
@@ -335,6 +318,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
doneSignal.await(ROW_LOCK_WAIT_TIME + 5000, TimeUnit.SECONDS);
assertNull(failedMsg[0], failedMsg[0]);
+ long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+ assertEquals(1, actualRowCount);
}
@Test
@@ -346,7 +331,7 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(v,k)");
conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES ('foo',0)");
conn.commit();
- addDelayingCoprocessor(conn, tableName);
+ TestUtil.addCoprocessor(conn, tableName, DelayingRegionObserver.class);
final CountDownLatch doneSignal = new CountDownLatch(2);
final String[] failedMsg = new String[1];
Runnable r1 = new Runnable() {
@@ -389,27 +374,8 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
t2.start();
doneSignal.await(ROW_LOCK_WAIT_TIME + 5000, TimeUnit.SECONDS);
-
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(tableName)));
- TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexName)));
-
- long count1 = getRowCount(conn, tableName);
- long count2 = getRowCount(conn, indexName);
- assertTrue("Expected table row count ( " + count1 + ") to match index row count (" + count2 + ")", count1 == count2);
-
- ResultSet rs1 = conn.createStatement().executeQuery("SELECT * FROM " + indexName);
- assertTrue(rs1.next());
- ResultSet rs2 = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ * FROM " + tableName + " WHERE k = '" + rs1.getString(2) + "'");
- assertTrue("Could not find row in table where k = '" + rs1.getString(2) + "'", rs2.next());
- assertEquals(rs1.getInt(1), rs2.getInt(2));
- assertFalse(rs1.next());
- assertFalse(rs2.next());
- }
-
- private static long getRowCount(Connection conn, String tableName) throws SQLException {
- ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM " + tableName);
- assertTrue(rs.next());
- return rs.getLong(1);
+ long actualRowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+ assertEquals(1, actualRowCount);
}
public static class DelayingRegionObserver extends SimpleRegionObserver {
@@ -445,4 +411,320 @@ public class ConcurrentMutationsIT extends ParallelStatsDisabledIT {
}
}
+
+ @Test
+ @Ignore("PHOENIX-4058 Generate correct index updates when DeleteColumn processed before Put with same timestamp")
+ public void testSetIndexedColumnToNullAndValueAtSameTS() throws Exception {
+ try {
+ final MyClock clock = new MyClock(1000);
+ EnvironmentEdgeManager.injectEdge(clock);
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ long ts = 1000;
+ clock.time = ts;
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0");
+ conn.close();
+
+ ts = 1010;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
+ conn.close();
+
+ ts = 1020;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
+ stmt.setTimestamp(1, new Timestamp(1000L));
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ Timestamp expectedTimestamp;
+ ts = 1040;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
+ expectedTimestamp = null;
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ stmt.setTimestamp(1, new Timestamp(3000L));
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ ts = 1050;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+
+ IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+
+ rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
+ assertTrue(rs.next());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+
+ conn.close();
+ } finally {
+ EnvironmentEdgeManager.injectEdge(null);
+ }
+ }
+
+ @Test
+ public void testSetIndexedColumnToNullAndValueAtSameTSWithStoreNulls1() throws Exception {
+ try {
+ final MyClock clock = new MyClock(1000);
+ EnvironmentEdgeManager.injectEdge(clock);
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ long ts = 1000;
+ clock.time = ts;
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+ conn.close();
+
+ ts = 1010;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
+ conn.close();
+
+ ts = 1020;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
+ stmt.setTimestamp(1, new Timestamp(1000L));
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ Timestamp expectedTimestamp;
+ ts = 1040;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
+ expectedTimestamp = null;
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ expectedTimestamp = new Timestamp(3000L);
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ ts = 1050;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+
+ IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+
+ rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
+ assertTrue(rs.next());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+
+ conn.close();
+ } finally {
+ EnvironmentEdgeManager.injectEdge(null);
+ }
+ }
+
+ @Test
+ public void testSetIndexedColumnToNullAndValueAtSameTSWithStoreNulls2() throws Exception {
+ try {
+ final MyClock clock = new MyClock(1000);
+ EnvironmentEdgeManager.injectEdge(clock);
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ long ts = 1000;
+ clock.time = ts;
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+ conn.close();
+
+ ts = 1010;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
+ conn.close();
+
+ ts = 1020;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
+ stmt.setTimestamp(1, new Timestamp(1000L));
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ Timestamp expectedTimestamp;
+ ts = 1040;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
+ expectedTimestamp = new Timestamp(3000L);
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ expectedTimestamp = null;
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ ts = 1050;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+
+ IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+
+ ResultSet rs = conn.createStatement().executeQuery("SELECT /*+ NO_INDEX */ ts,v FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+
+ rs = conn.createStatement().executeQuery("SELECT \"0:TS\", \"0:V\" FROM " + indexName);
+ assertTrue(rs.next());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ assertEquals(null, rs.getString(2));
+ assertFalse(rs.next());
+
+ conn.close();
+ } finally {
+ EnvironmentEdgeManager.injectEdge(null);
+ }
+ }
+
+ @Test
+ public void testDeleteRowAndUpsertValueAtSameTS1() throws Exception {
+ try {
+ final MyClock clock = new MyClock(1000);
+ EnvironmentEdgeManager.injectEdge(clock);
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ long ts = 1000;
+ clock.time = ts;
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, A.V VARCHAR, B.V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+ conn.close();
+
+ ts = 1010;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
+ conn.close();
+
+ ts = 1020;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0','1')");
+ stmt.setTimestamp(1, new Timestamp(1000L));
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ Timestamp expectedTimestamp;
+ ts = 1040;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')");
+ stmt.executeUpdate();
+ conn.commit();
+ expectedTimestamp = new Timestamp(3000L);
+ stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null,'3')");
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ ts = 1050;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+
+ long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+ assertEquals(0,rowCount);
+
+ conn.close();
+ } finally {
+ EnvironmentEdgeManager.injectEdge(null);
+ }
+ }
+
+ @Test
+ public void testDeleteRowAndUpsertValueAtSameTS2() throws Exception {
+ try {
+ final MyClock clock = new MyClock(1000);
+ EnvironmentEdgeManager.injectEdge(clock);
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ long ts = 1000;
+ clock.time = ts;
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 CHAR(2) NOT NULL, k2 CHAR(2) NOT NULL, ts TIMESTAMP, V VARCHAR, V2 VARCHAR, CONSTRAINT pk PRIMARY KEY (k1,k2)) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true");
+ conn.close();
+
+ ts = 1010;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + "(k2,k1,ts) INCLUDE (V, v2)");
+ conn.close();
+
+ ts = 1020;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, '0')");
+ stmt.setTimestamp(1, new Timestamp(1000L));
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ Timestamp expectedTimestamp;
+ ts = 1040;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+ expectedTimestamp = new Timestamp(3000L);
+ stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES('aa','aa',?, null)");
+ stmt.setTimestamp(1, expectedTimestamp);
+ stmt.executeUpdate();
+ conn.commit();
+ stmt = conn.prepareStatement("DELETE FROM " + tableName + " WHERE (K1,K2) = ('aa','aa')");
+ stmt.executeUpdate();
+ conn.commit();
+ conn.close();
+
+ ts = 1050;
+ clock.time = ts;
+ conn = DriverManager.getConnection(getUrl(), props);
+
+ long rowCount = IndexScrutiny.scrutinizeIndex(conn, tableName, indexName);
+ assertEquals(0,rowCount);
+
+ conn.close();
+ } finally {
+ EnvironmentEdgeManager.injectEdge(null);
+ }
+ }
}