http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java index b78bb63..7466cd3 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CSVCommonsLoaderIT.java @@ -45,15 +45,13 @@ import org.apache.phoenix.util.DateUtil; import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Test; -public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { +public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeTableReuseIT { private static final String DATATYPE_TABLE = "DATATYPE"; private static final String DATATYPES_CSV_VALUES = "CKEY, CVARCHAR, CCHAR, CINTEGER, CDECIMAL, CUNSIGNED_INT, CBOOLEAN, CBIGINT, CUNSIGNED_LONG, CTIME, CDATE\n" + "KEY1,A,A,2147483647,1.1,0,TRUE,9223372036854775807,0,1990-12-31 10:59:59,1999-12-31 23:59:59\n" + "KEY2,B,B,-2147483648,-1.1,2147483647,FALSE,-9223372036854775808,9223372036854775807,2000-01-01 00:00:01,2012-02-29 23:59:59\n" + "KEY3,,,,,,,,,,\n"; - private static final String STOCK_TABLE = "STOCK_SYMBOL"; - private static final String STOCK_TABLE_MULTI = "STOCK_SYMBOL_MULTI"; private static final String STOCK_CSV_VALUES = "AAPL,APPLE Inc.\n" + "CRM,SALESFORCE\n" + "GOOG,Google\n" + "HOG,Harlet-Davidson Inc.\n" + "HPQ,Hewlett Packard\n" @@ -105,9 +103,9 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { - + String stockTableName = generateRandomString(); // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()).unwrap( PhoenixConnection.class); @@ -115,14 +113,14 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Collections.<String> emptyList(), true); csvUtil.upsert(new StringReader(STOCK_CSV_VALUES_WITH_HEADER)); // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = conn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE); + + stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES_WITH_HEADER), csvUtil.getFormat()); @@ -149,9 +147,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { PhoenixConnection globalConn = null; PhoenixConnection tenantConn = null; try { + String stockTableMultiName = generateRandomString(); // Create table using the global connection - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE_MULTI + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableMultiName + "(TENANT_ID VARCHAR NOT NULL, SYMBOL VARCHAR NOT NULL, COMPANY VARCHAR," + " CONSTRAINT PK PRIMARY KEY(TENANT_ID,SYMBOL)) MULTI_TENANT = true;"; globalConn = DriverManager.getConnection(getUrl()).unwrap( @@ -164,14 +163,14 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { PhoenixConnection.class); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(tenantConn, STOCK_TABLE_MULTI, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(tenantConn, stockTableMultiName, Collections.<String> emptyList(), true); csvUtil.upsert(new StringReader(STOCK_CSV_VALUES_WITH_HEADER)); // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = tenantConn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE_MULTI); + + stockTableMultiName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES_WITH_HEADER), csvUtil.getFormat()); @@ -197,9 +196,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()).unwrap( PhoenixConnection.class); @@ -207,14 +207,14 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert TDV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE,Collections.<String> emptyList() + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName,Collections.<String> emptyList() , true, '\t', '"', null, CSVCommonsLoader.DEFAULT_ARRAY_ELEMENT_SEPARATOR); csvUtil.upsert(new StringReader(STOCK_TDV_VALUES_WITH_HEADER)); // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = conn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE); + + stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_TDV_VALUES_WITH_HEADER), csvUtil.getFormat()); @@ -240,8 +240,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()).unwrap( PhoenixConnection.class); @@ -249,7 +251,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Arrays.<String> asList(STOCK_COLUMNS), true, '1', '2', '3', CSVCommonsLoader.DEFAULT_ARRAY_ELEMENT_SEPARATOR); csvUtil.upsert(new StringReader(STOCK_CSV_VALUES_WITH_DELIMITER)); @@ -257,7 +259,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = conn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE); + + stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES_WITH_DELIMITER), csvUtil.getFormat()); @@ -283,8 +285,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()) .unwrap(PhoenixConnection.class); @@ -292,7 +296,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Arrays.<String> asList(STOCK_COLUMNS), true); // no header csvUtil.upsert(new StringReader(STOCK_CSV_VALUES)); @@ -300,7 +304,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = conn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE); + + stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES), csvUtil.getFormat()); @@ -327,8 +331,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()) .unwrap(PhoenixConnection.class); @@ -336,14 +342,14 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, null, true); csvUtil.upsert(new StringReader(STOCK_CSV_VALUES)); // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = conn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE); + + stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader( STOCK_CSV_VALUES), csvUtil.getFormat()); @@ -370,8 +376,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()) .unwrap(PhoenixConnection.class); @@ -379,14 +387,14 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file, not strict - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Arrays.asList(STOCK_COLUMNS_WITH_BOGUS), false); csvUtil.upsert(new StringReader(STOCK_CSV_VALUES)); // Compare Phoenix ResultSet with CSV file content PreparedStatement statement = conn .prepareStatement("SELECT SYMBOL, COMPANY FROM " - + STOCK_TABLE); + + stockTableName); ResultSet phoenixResultSet = statement.executeQuery(); parser = new CSVParser(new StringReader(STOCK_CSV_VALUES), csvUtil.getFormat()); @@ -412,8 +420,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY_ID BIGINT);"; conn = DriverManager.getConnection(getUrl()) .unwrap(PhoenixConnection.class); @@ -421,7 +431,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file in strict mode - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Arrays.asList("SYMBOL", "COMPANY_ID"), true); try { csvUtil.upsert(new StringReader(STOCK_CSV_VALUES)); @@ -444,8 +454,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()) .unwrap(PhoenixConnection.class); @@ -453,7 +465,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Arrays.asList("FOO", "BAR"), false); try { @@ -464,7 +476,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { e.getMessage(), e.getMessage() .contains( - "ERROR 504 (42703): Undefined column. columnName=STOCK_SYMBOL.[FOO, BAR]")); + "ERROR 504 (42703): Undefined column. columnName=" + stockTableName + ".[FOO, BAR]")); } } finally { if (parser != null) @@ -479,8 +491,10 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { CSVParser parser = null; PhoenixConnection conn = null; try { + String stockTableName = generateRandomString(); + // Create table - String statements = "CREATE TABLE IF NOT EXISTS " + STOCK_TABLE + String statements = "CREATE TABLE IF NOT EXISTS " + stockTableName + "(SYMBOL VARCHAR NOT NULL PRIMARY KEY, COMPANY VARCHAR);"; conn = DriverManager.getConnection(getUrl()) .unwrap(PhoenixConnection.class); @@ -488,7 +502,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { new StringReader(statements), null); // Upsert CSV file - CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, STOCK_TABLE, + CSVCommonsLoader csvUtil = new CSVCommonsLoader(conn, stockTableName, Arrays.asList(STOCK_COLUMNS_WITH_BOGUS), true); try { csvUtil.upsert(new StringReader(STOCK_CSV_VALUES)); @@ -498,7 +512,7 @@ public class CSVCommonsLoaderIT extends BaseHBaseManagedTimeIT { e.getMessage(), e.getMessage() .contains( - "ERROR 504 (42703): Undefined column. columnName=STOCK_SYMBOL.BOGUS")); + "ERROR 504 (42703): Undefined column. columnName=" + stockTableName + ".BOGUS")); } } finally { if (parser != null)
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java index 68165e2..0c270f2 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CoalesceFunctionIT.java @@ -38,15 +38,15 @@ import org.junit.Assert; import org.junit.Test; -public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { +public class CoalesceFunctionIT extends BaseHBaseManagedTimeTableReuseIT { @Test public void testCoalesce() throws Exception { String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId), getUrl()); + String tableName = initATableValues(tenantId, getDefaultSplits(tenantId), getUrl()); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - String query = "SELECT entity_id, a_integer + COALESCE(x_integer,1) FROM ATABLE WHERE organization_id = ? AND a_integer >= 6 AND a_integer <= 7"; + String query = "SELECT entity_id, a_integer + COALESCE(x_integer,1) FROM " + tableName + " WHERE organization_id = ? AND a_integer >= 6 AND a_integer <= 7"; PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, tenantId); ResultSet rs = statement.executeQuery(); @@ -66,21 +66,21 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void coalesceWithSumExplicitLong() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - - String ddl = "CREATE TABLE TEST_COALESCE(" + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + "(" + " ID BIGINT NOT NULL, " + " COUNT BIGINT " + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(2, null)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery( "SELECT " + "COALESCE(SUM(COUNT), CAST(0 AS BIGINT)) " //explicitly def long - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); @@ -90,21 +90,21 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void coalesceWithSumImplicitLong() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - - String ddl = "CREATE TABLE TEST_COALESCE(" + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + "(" + " ID BIGINT NOT NULL, " + " COUNT BIGINT " + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(2, null)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery( "SELECT " + "COALESCE(SUM(COUNT), 0) " // no long def - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); @@ -114,21 +114,21 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void coalesceWithSecondParamAsExpression() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - - String ddl = "CREATE TABLE TEST_COALESCE(" + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + "(" + " ID BIGINT NOT NULL, " + " COUNT BIGINT " + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(2, null)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery( "SELECT " + "COALESCE(SUM(COUNT), SUM(ID)) " // second param as expression - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(2, rs.getLong(1)); @@ -138,21 +138,22 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void nonTypedSecondParameterLong() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); + String tableName = generateRandomString(); - String ddl = "CREATE TABLE TEST_COALESCE(" + String ddl = "CREATE TABLE " + tableName + "(" + " ID BIGINT NOT NULL, " + " COUNT BIGINT " //first parameter to coalesce + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(2, null)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery( "SELECT " + "COALESCE(NTH_VALUE(COUNT, 100) WITHIN GROUP (ORDER BY COUNT DESC), 0) " //second param is int - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); @@ -162,21 +163,21 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void nonTypedSecondParameterUnsignedDataTypes() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - - String ddl = "CREATE TABLE TEST_COALESCE (" + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + "(" + " ID BIGINT NOT NULL, " + " COUNT UNSIGNED_INT " //first parameter to coalesce + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE (ID, COUNT) VALUES(2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " (ID, COUNT) VALUES(2, null)"); conn.commit(); //second param to coalesce is signed int ResultSet rs = conn.createStatement().executeQuery( "SELECT " + " COALESCE(NTH_VALUE(COUNT, 100) WITHIN GROUP (ORDER BY COUNT DESC), 1) " - + " FROM TEST_COALESCE" + + " FROM " + tableName + " GROUP BY ID"); assertTrue(rs.next()); @@ -187,17 +188,18 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void testWithNthValueAggregationFunction() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); + String tableName = generateRandomString(); - String ddl = "CREATE TABLE TEST_NTH(" + String ddl = "CREATE TABLE " + tableName + "(" + " ID BIGINT NOT NULL, " + " DATE TIMESTAMP NOT NULL, " + " COUNT BIGINT " + " CONSTRAINT pk PRIMARY KEY(ID, DATE))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_NTH(ID, DATE, COUNT) VALUES(1, CURRENT_TIME(), 1)"); - conn.createStatement().execute("UPSERT INTO TEST_NTH(ID, DATE, COUNT) VALUES(1, CURRENT_TIME(), 2)"); - conn.createStatement().execute("UPSERT INTO TEST_NTH(ID, DATE, COUNT) VALUES(2, CURRENT_TIME(), 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, DATE, COUNT) VALUES(1, CURRENT_TIME(), 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, DATE, COUNT) VALUES(1, CURRENT_TIME(), 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, DATE, COUNT) VALUES(2, CURRENT_TIME(), 1)"); conn.commit(); //second param to coalesce is signed int @@ -207,8 +209,8 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { + " NTH_VALUE(COUNT, 2000)" // should evaluate null + " WITHIN GROUP (ORDER BY COUNT DESC)," + " 0)" - + "FROM TEST_NTH " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); @@ -218,22 +220,23 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void wrongDataTypeOfSecondParameter() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); + String tableName = generateRandomString(); - String ddl = "CREATE TABLE TEST_COALESCE(" + String ddl = "CREATE TABLE " + tableName + "(" + " ID UNSIGNED_INT NOT NULL, " + " COUNT UNSIGNED_INT " + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(2, null)"); conn.commit(); try { conn.createStatement().executeQuery( "SELECT " + "COALESCE(MIN(COUNT), -1) " // invalid value for UNSIGNED_INT - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); Assert.fail("CANNOT CONVERT TYPE exception expected"); } catch (SQLException e) { @@ -244,22 +247,23 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void testImplicitSecondArgCastingException() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); + String tableName = generateRandomString(); - String ddl = "CREATE TABLE TEST_COALESCE(" + String ddl = "CREATE TABLE " + tableName + "(" + " ID INTEGER NOT NULL, " + " COUNT UNSIGNED_INT " //first parameter to coalesce + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(-2, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(-2, null)"); conn.commit(); try { ResultSet rs = conn.createStatement().executeQuery( "SELECT " + "COALESCE(MIN(COUNT), ID) " - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); @@ -272,21 +276,22 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { @Test public void testImplicitSecondArgCasting() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); + String tableName = generateRandomString(); - String ddl = "CREATE TABLE TEST_COALESCE(" + String ddl = "CREATE TABLE " + tableName + "(" + " ID DOUBLE NOT NULL, " + " COUNT INTEGER " //first parameter to coalesce + " CONSTRAINT pk PRIMARY KEY(ID))"; conn.createStatement().execute(ddl); - conn.createStatement().execute("UPSERT INTO TEST_COALESCE(ID, COUNT) VALUES(2.0, null)"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(ID, COUNT) VALUES(2.0, null)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery( "SELECT " + "COALESCE(MIN(COUNT), ID) " - + "FROM TEST_COALESCE " - + "GROUP BY ID"); + + "FROM " + tableName + + " GROUP BY ID"); assertTrue(rs.next()); assertEquals(2, rs.getLong(1)); @@ -297,13 +302,14 @@ public class CoalesceFunctionIT extends BaseHBaseManagedTimeIT { public void testCoalesceInRowKeyColumn() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE coalesceTest(k1 decimal, k2 decimal, constraint pk primary key (k1,k2))"); - conn.createStatement().execute("UPSERT INTO coalesceTest(k2) VALUES (1)"); - conn.createStatement().execute("UPSERT INTO coalesceTest VALUES (2,2)"); - conn.createStatement().execute("UPSERT INTO coalesceTest VALUES (3,3)"); + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + "(k1 decimal, k2 decimal, constraint pk primary key (k1,k2))"); + conn.createStatement().execute("UPSERT INTO " + tableName + "(k2) VALUES (1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES (2,2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES (3,3)"); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT coalesce(k1, 1) ,k2 FROM coalesceTest"); + ResultSet rs = conn.createStatement().executeQuery("SELECT coalesce(k1, 1) ,k2 FROM " + tableName); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(1, rs.getInt(2)); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/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 e97c7e1..9a56136 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 @@ -63,18 +63,19 @@ import org.junit.Test; public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { + private String tableName; @Test public void testSelect() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + String tableName = initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); 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 - String query = "SELECT * FROM aTable"; + String query = "SELECT * FROM " + tableName ; try { PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); @@ -99,7 +100,7 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { assertFalse(rs.next()); // Select only specific columns - query = "SELECT A_STRING, A_INTEGER FROM aTable"; + query = "SELECT A_STRING, A_INTEGER FROM " + tableName ; statement = conn.prepareStatement(query); rs = statement.executeQuery(); assertTrue(rs.next()); @@ -132,7 +133,7 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { assertFalse(rs.next()); // Select only specific columns with condition on another column (Not in select) - query = "SELECT B_STRING, A_SHORT FROM aTable WHERE X_INTEGER = ?"; + query = "SELECT B_STRING, A_SHORT FROM " + tableName + " WHERE X_INTEGER = ?"; statement = conn.prepareStatement(query); statement.setInt(1, 4); rs = statement.executeQuery(); @@ -143,7 +144,7 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { // Select only specific columns with condition on another column (Not in select) and one row elements are // nulls - query = "SELECT X_LONG, X_INTEGER, Y_INTEGER FROM aTable WHERE B_STRING = ?"; + query = "SELECT X_LONG, X_INTEGER, Y_INTEGER FROM " + tableName + " WHERE B_STRING = ?"; statement = conn.prepareStatement(query); statement.setString(1, E_VALUE); rs = statement.executeQuery(); @@ -168,7 +169,7 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { assertFalse(rs.next()); // Select only specific columns with condition on one of the selected column - query = "SELECT A_STRING, A_INTEGER FROM aTable WHERE A_INTEGER = ?"; + query = "SELECT A_STRING, A_INTEGER FROM " + tableName + " WHERE A_INTEGER = ?"; statement = conn.prepareStatement(query); statement.setInt(1, 9); rs = statement.executeQuery(); @@ -177,7 +178,7 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { assertEquals(9, rs.getInt(2)); // Select all columns with order by on non PK column - query = "SELECT * FROM aTable ORDER BY A_INTEGER"; + query = "SELECT * FROM " + tableName + " ORDER BY A_INTEGER"; statement = conn.prepareStatement(query); rs = statement.executeQuery(); assertTrue(rs.next()); @@ -316,7 +317,7 @@ public class ColumnProjectionOptimizationIT extends BaseClientManagedTimeIT { private static void initMultiCFTable(long ts) throws Exception { String url = getUrl(); - ensureTableCreated(url, MULTI_CF_NAME, ts); + ensureTableCreated(url, MULTI_CF_NAME, MULTI_CF_NAME, ts); Properties props = new Properties(); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/CountDistinctCompressionIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CountDistinctCompressionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CountDistinctCompressionIT.java index b4c84b0..677d76f 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CountDistinctCompressionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CountDistinctCompressionIT.java @@ -18,6 +18,7 @@ package org.apache.phoenix.end2end; import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.apache.phoenix.util.TestUtil.ATABLE_NAME; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -51,7 +52,7 @@ public class CountDistinctCompressionIT extends BaseOwnClusterHBaseManagedTimeIT @Test public void testDistinctCountOnColumn() throws Exception { String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId), (Date)null, getUrl()); + initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), (Date)null, null, getUrl()); String query = "SELECT count(DISTINCT A_STRING) FROM aTable"; http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/CustomEntityDataIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CustomEntityDataIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CustomEntityDataIT.java index 3717396..ad0f308 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CustomEntityDataIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CustomEntityDataIT.java @@ -43,7 +43,7 @@ import org.junit.Test; public class CustomEntityDataIT extends BaseClientManagedTimeIT { protected static void initTableValues(String tenantId, byte[][] splits, long ts) throws Exception { - ensureTableCreated(getUrl(),CUSTOM_ENTITY_DATA_FULL_NAME,null, ts-2); + ensureTableCreated(getUrl(),CUSTOM_ENTITY_DATA_FULL_NAME,CUSTOM_ENTITY_DATA_FULL_NAME, ts-2); String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + ts; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java index 7ffc54f..abdcf3b 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DateTimeIT.java @@ -57,12 +57,13 @@ import org.junit.Before; import org.junit.Test; -public class DateTimeIT extends BaseHBaseManagedTimeIT { +public class DateTimeIT extends BaseHBaseManagedTimeTableReuseIT { protected Connection conn; protected Date date; protected static final String tenantId = getOrganizationId(); protected final static String ROW10 = "00D123122312312"; + protected String tableName; public DateTimeIT() throws Exception { super(); @@ -72,7 +73,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Before public void setUp() throws SQLException { conn = DriverManager.getConnection(getUrl()); - initAtable(); + this.tableName = initAtable(); } @After @@ -80,10 +81,11 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { conn.close(); } - private void initAtable() throws SQLException { - ensureTableCreated(getUrl(), ATABLE_NAME, (byte[][])null); + private String initAtable() throws SQLException { + String tableName = generateRandomString(); + ensureTableCreated(getUrl(), tableName, ATABLE_NAME, (byte[][])null); PreparedStatement stmt = conn.prepareStatement( - "upsert into " + ATABLE_NAME + + "upsert into " + tableName + "(" + " ORGANIZATION_ID, " + " ENTITY_ID, " + @@ -288,6 +290,8 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { stmt.execute(); conn.commit(); + return tableName; + } @Test @@ -298,9 +302,10 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { java.util.Date dateToday = cal.getTime(); cal.add(Calendar.DAY_OF_YEAR, 1); java.util.Date dateTomorrow = cal.getTime(); + String tableName = generateRandomString(); String today = formatter.format(dateToday); String tomorrow = formatter.format(dateTomorrow); - String query = "SELECT entity_id FROM ATABLE WHERE a_integer < 4 AND a_date BETWEEN date '" + today + "' AND date '" + tomorrow + "' "; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_integer < 4 AND a_date BETWEEN date '" + today + "' AND date '" + tomorrow + "' "; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertTrue(rs.next()); @@ -311,7 +316,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSelectLiteralDate() throws Exception { String s = DateUtil.DEFAULT_DATE_FORMATTER.format(date); - String query = "SELECT DATE '" + s + "' FROM ATABLE"; + String query = "SELECT DATE '" + s + "' FROM " + this.tableName; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertTrue(rs.next()); @@ -320,7 +325,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSelectLiteralDateCompare() throws Exception { - String query = "SELECT (DATE '" + date + "' = DATE '" + date + "') FROM ATABLE"; + String query = "SELECT (DATE '" + date + "' = DATE '" + date + "') FROM " + this.tableName; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertTrue(rs.next()); @@ -329,7 +334,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSelectWhereDatesEqual() throws Exception { - String query = "SELECT entity_id FROM ATABLE WHERE a_integer < 4 AND DATE '" + date + "' = DATE '" + date + "'"; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_integer < 4 AND DATE '" + date + "' = DATE '" + date + "'"; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertTrue(rs.next()); @@ -338,7 +343,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSelectWhereDateAndToDateEqual() throws Exception { - String query = "SELECT entity_id FROM ATABLE WHERE a_integer < 4 AND DATE '" + date + "' = TO_DATE ('" + date + "')"; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_integer < 4 AND DATE '" + date + "' = TO_DATE ('" + date + "')"; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertTrue(rs.next()); @@ -348,7 +353,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSelectWhereDateAndTimestampEqual() throws Exception { final String timestamp = "2012-09-08 07:08:23"; - String query = "SELECT entity_id FROM ATABLE WHERE a_integer < 4 AND DATE '" + timestamp + "' = TIMESTAMP '" + timestamp + "'"; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_integer < 4 AND DATE '" + timestamp + "' = TIMESTAMP '" + timestamp + "'"; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); @@ -357,7 +362,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSelectWhereSameDatesUnequal() throws Exception { - String query = "SELECT entity_id FROM ATABLE WHERE a_integer < 4 AND DATE '" + date + "' > DATE '" + date + "'"; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_integer < 4 AND DATE '" + date + "' > DATE '" + date + "'"; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertFalse(rs.next()); @@ -365,7 +370,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testDateInList() throws Exception { - String query = "SELECT entity_id FROM ATABLE WHERE a_date IN (?,?) AND a_integer < 4"; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_date IN (?,?) AND a_integer < 4"; PreparedStatement statement = conn.prepareStatement(query); statement.setDate(1, new Date(0)); statement.setDate(2, date); @@ -385,7 +390,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { java.util.Date dateTomorrow = cal.getTime(); String today = formatter.format(dateToday); String tomorrow = formatter.format(dateTomorrow); - String query = "SELECT entity_id FROM ATABLE WHERE a_integer < 4 AND a_date BETWEEN date '" + today + "' AND date '" + tomorrow + "' "; + String query = "SELECT entity_id FROM " + this.tableName + " WHERE a_integer < 4 AND a_date BETWEEN date '" + today + "' AND date '" + tomorrow + "' "; Statement statement = conn.createStatement(); ResultSet rs = statement.executeQuery(query); assertTrue(rs.next()); @@ -456,23 +461,24 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testYearFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('2004-03-01 00:00:00'), TO_TIMESTAMP('2006-02-01 00:00:00'), TO_TIME('2008-02-01 00:00:00'), " + + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2004-03-01 00:00:00'), TO_TIMESTAMP('2006-02-01 00:00:00'), TO_TIME('2008-02-01 00:00:00'), " + "TO_DATE('2010-03-01 00:00:00:896', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-02-01'), TO_TIME('2015-02-01 00:00:00'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('2005-03-01 00:00:00'), TO_TIMESTAMP('2006-02-01 00:00:00'), TO_TIME('2008-02-01 00:00:00'), " + + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2005-03-01 00:00:00'), TO_TIMESTAMP('2006-02-01 00:00:00'), TO_TIME('2008-02-01 00:00:00'), " + "TO_DATE('2010-03-01 00:00:00:896', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-02-01'), TO_TIME('2015-02-01 00:00:00'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (3, TO_DATE('2006-03-01 00:00:00'), TO_TIMESTAMP('2006-02-01 00:00:00'), TO_TIME('2008-02-01 00:00:00'), " + + dml = "UPSERT INTO " + tableName + " VALUES (3, TO_DATE('2006-03-01 00:00:00'), TO_TIMESTAMP('2006-02-01 00:00:00'), TO_TIME('2008-02-01 00:00:00'), " + "TO_DATE('2010-03-01 00:00:00:896', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-02-01'), TO_TIME('2015-02-01 00:00:00'))"; conn.createStatement().execute(dml); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT k1, YEAR(timestamps), YEAR(times), Year(unsignedDates), YEAR(unsignedTimestamps), " + - "YEAR(unsignedTimes) FROM T1 where YEAR(dates) = 2004"); + "YEAR(unsignedTimes) FROM " + tableName + " where YEAR(dates) = 2004"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(2006, rs.getInt(2)); @@ -485,23 +491,24 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testMonthFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('2004-03-10 00:00:00'), TO_TIMESTAMP('2006-04-12 00:00:00'), TO_TIME('2008-05-16 00:00:00'), " + + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2004-03-10 00:00:00'), TO_TIMESTAMP('2006-04-12 00:00:00'), TO_TIME('2008-05-16 00:00:00'), " + "TO_DATE('2010-06-20 00:00:00:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:00:00'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('2004-04-10 00:00:00'), TO_TIMESTAMP('2006-04-12 00:00:00'), TO_TIME('2008-05-16 00:00:00'), " + + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2004-04-10 00:00:00'), TO_TIMESTAMP('2006-04-12 00:00:00'), TO_TIME('2008-05-16 00:00:00'), " + "TO_DATE('2010-06-20 00:00:00:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:00:00'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (3, TO_DATE('2004-05-10 00:00:00'), TO_TIMESTAMP('2006-04-12 00:00:00'), TO_TIME('2008-05-16 00:00:00'), " + + dml = "UPSERT INTO " + tableName + " VALUES (3, TO_DATE('2004-05-10 00:00:00'), TO_TIMESTAMP('2006-04-12 00:00:00'), TO_TIME('2008-05-16 00:00:00'), " + "TO_DATE('2010-06-20 00:00:00:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:00:00'))"; conn.createStatement().execute(dml); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT k1, MONTH(timestamps), MONTH(times), MONTH(unsignedDates), MONTH(unsignedTimestamps), " + - "MONTH(unsignedTimes) FROM T1 where MONTH(dates) = 3"); + "MONTH(unsignedTimes) FROM " + tableName + " where MONTH(dates) = 3"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(4, rs.getInt(2)); @@ -514,17 +521,18 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testUnsignedTimeDateWithLiteral() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS UT (k1 INTEGER NOT NULL," + + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL," + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO UT VALUES (1, " + + String dml = "UPSERT INTO " + tableName + " VALUES (1, " + "'2010-06-20 12:00:00', '2012-07-28 12:00:00', '2015-12-25 12:00:00')"; conn.createStatement().execute(dml); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT k1, unsignedDates, " + - "unsignedTimestamps, unsignedTimes FROM UT where k1 = 1"); + "unsignedTimestamps, unsignedTimes FROM " + tableName + " where k1 = 1"); assertTrue(rs.next()); assertEquals(DateUtil.parseDate("2010-06-20 12:00:00"), rs.getDate(2)); assertEquals(DateUtil.parseTimestamp("2012-07-28 12:00:00"), rs.getTimestamp(3)); @@ -534,23 +542,24 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testSecondFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('2004-03-01 00:00:10'), TO_TIMESTAMP('2006-04-12 00:00:20'), TO_TIME('2008-05-16 10:00:30'), " + + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2004-03-01 00:00:10'), TO_TIMESTAMP('2006-04-12 00:00:20'), TO_TIME('2008-05-16 10:00:30'), " + "TO_DATE('2010-06-20 00:00:40:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:00:50'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('2004-03-01 00:00:10'), TO_TIMESTAMP('2006-04-12 00:20:30'), TO_TIME('2008-05-16 10:00:30'), " + + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2004-03-01 00:00:10'), TO_TIMESTAMP('2006-04-12 00:20:30'), TO_TIME('2008-05-16 10:00:30'), " + "TO_DATE('2010-06-20 00:00:40:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:00:50'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (3, TO_DATE('2004-03-01 00:00:10'), TO_TIMESTAMP('2006-04-12 00:50:30'), TO_TIME('2008-05-16 10:00:30'), " + + dml = "UPSERT INTO " + tableName + " VALUES (3, TO_DATE('2004-03-01 00:00:10'), TO_TIMESTAMP('2006-04-12 00:50:30'), TO_TIME('2008-05-16 10:00:30'), " + "TO_DATE('2010-06-20 00:00:40:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:00:50'))"; conn.createStatement().execute(dml); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT k1, SECOND(dates), SECOND(times), SECOND(unsignedDates), SECOND(unsignedTimestamps), " + - "SECOND(unsignedTimes) FROM T1 where SECOND(timestamps)=20"); + "SECOND(unsignedTimes) FROM " + tableName + " where SECOND(timestamps)=20"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(10, rs.getInt(2)); @@ -563,18 +572,19 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testWeekFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))"; + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('2004-01-10 10:00:10'), TO_TIMESTAMP('2006-04-12 08:00:20'), TO_TIME('2008-05-16 10:00:30'))"; + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2004-01-10 10:00:10'), TO_TIMESTAMP('2006-04-12 08:00:20'), TO_TIME('2008-05-16 10:00:30'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('2004-01-10 10:00:10'), TO_TIMESTAMP('2006-05-18 08:00:20'), TO_TIME('2008-05-16 10:00:30'))"; + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2004-01-10 10:00:10'), TO_TIMESTAMP('2006-05-18 08:00:20'), TO_TIME('2008-05-16 10:00:30'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (3, TO_DATE('2004-01-10 10:00:10'), TO_TIMESTAMP('2006-05-18 08:00:20'), TO_TIME('2008-05-16 10:00:30'))"; + dml = "UPSERT INTO " + tableName + " VALUES (3, TO_DATE('2004-01-10 10:00:10'), TO_TIMESTAMP('2006-05-18 08:00:20'), TO_TIME('2008-05-16 10:00:30'))"; conn.createStatement().execute(dml); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT k1, WEEK(dates), WEEK(times) FROM T1 where WEEK(timestamps)=15"); + ResultSet rs = conn.createStatement().executeQuery("SELECT k1, WEEK(dates), WEEK(times) FROM " + tableName + " where WEEK(timestamps)=15"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(2, rs.getInt(2)); @@ -584,21 +594,22 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testHourFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))"; + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'), TO_TIMESTAMP('2006-04-12 15:10:20'), " + + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'), TO_TIMESTAMP('2006-04-12 15:10:20'), " + "TO_TIME('2008-05-16 20:40:30'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'), TO_TIMESTAMP('2006-04-12 10:10:20'), " + + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'), TO_TIMESTAMP('2006-04-12 10:10:20'), " + "TO_TIME('2008-05-16 20:40:30'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (3, TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'), TO_TIMESTAMP('2006-04-12 08:10:20'), " + + dml = "UPSERT INTO " + tableName + " VALUES (3, TO_DATE('Sat, 3 Feb 2008 03:05:06 GMT', 'EEE, d MMM yyyy HH:mm:ss z', 'UTC'), TO_TIMESTAMP('2006-04-12 08:10:20'), " + "TO_TIME('2008-05-16 20:40:30'))"; conn.createStatement().execute(dml); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT k1, HOUR(dates), HOUR(times) FROM T1 where HOUR(timestamps)=15"); + ResultSet rs = conn.createStatement().executeQuery("SELECT k1, HOUR(dates), HOUR(times) FROM " + tableName + " where HOUR(timestamps)=15"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(3, rs.getInt(2)); @@ -608,11 +619,12 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testNowFunction() throws Exception { + String tableName = generateRandomString(); Date date = new Date(System.currentTimeMillis()); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, timestamps TIMESTAMP CONSTRAINT pk PRIMARY KEY (k1))"; + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, timestamps TIMESTAMP CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (?, ?)"; + String dml = "UPSERT INTO " + tableName + " VALUES (?, ?)"; PreparedStatement stmt = conn.prepareStatement(dml); stmt.setInt(1, 1); stmt.setDate(2, new Date(date.getTime()-500)); @@ -622,7 +634,7 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { stmt.execute(); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT * from T1 where now() > timestamps"); + ResultSet rs = conn.createStatement().executeQuery("SELECT * from " + tableName + " where now() > timestamps"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(new Date(date.getTime()-500), rs.getDate(2)); @@ -631,20 +643,21 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testMinuteFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME, " + "unsignedDates UNSIGNED_DATE, unsignedTimestamps UNSIGNED_TIMESTAMP, unsignedTimes UNSIGNED_TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('2004-03-01 00:10:10'), TO_TIMESTAMP('2006-04-12 00:20:20'), TO_TIME('2008-05-16 10:30:30'), " + + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2004-03-01 00:10:10'), TO_TIMESTAMP('2006-04-12 00:20:20'), TO_TIME('2008-05-16 10:30:30'), " + "TO_DATE('2010-06-20 00:40:40:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:50:50'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('2004-03-01 00:10:10'), TO_TIMESTAMP('2006-04-12 00:50:20'), TO_TIME('2008-05-16 10:30:30'), " + + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2004-03-01 00:10:10'), TO_TIMESTAMP('2006-04-12 00:50:20'), TO_TIME('2008-05-16 10:30:30'), " + "TO_DATE('2010-06-20 00:40:40:789', 'yyyy-MM-dd HH:mm:ss:SSS'), TO_TIMESTAMP('2012-07-28'), TO_TIME('2015-12-25 00:50:50'))"; conn.createStatement().execute(dml); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT k1, MINUTE(dates), MINUTE(times), MINUTE(unsignedDates), MINUTE(unsignedTimestamps), " + - "MINUTE(unsignedTimes) FROM T1 where MINUTE(timestamps)=20"); + "MINUTE(unsignedTimes) FROM " + tableName + " where MINUTE(timestamps)=20"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(10, rs.getInt(2)); @@ -657,16 +670,17 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testDayOfMonthFuncAgainstColumns() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS T1 (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))"; + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL, dates DATE, timestamps TIMESTAMP, times TIME CONSTRAINT pk PRIMARY KEY (k1))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO T1 VALUES (1, TO_DATE('2004-01-08 10:00:10'), TO_TIMESTAMP('2006-04-12 08:00:20'), TO_TIME('2008-05-26 11:00:30'))"; + String dml = "UPSERT INTO " + tableName + " VALUES (1, TO_DATE('2004-01-08 10:00:10'), TO_TIMESTAMP('2006-04-12 08:00:20'), TO_TIME('2008-05-26 11:00:30'))"; conn.createStatement().execute(dml); - dml = "UPSERT INTO T1 VALUES (2, TO_DATE('2004-01-18 10:00:10'), TO_TIMESTAMP('2006-05-22 08:00:20'), TO_TIME('2008-12-30 11:00:30'))"; + dml = "UPSERT INTO " + tableName + " VALUES (2, TO_DATE('2004-01-18 10:00:10'), TO_TIMESTAMP('2006-05-22 08:00:20'), TO_TIME('2008-12-30 11:00:30'))"; conn.createStatement().execute(dml); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT k1, DAYOFMONTH(dates), DAYOFMONTH(times) FROM T1 where DAYOFMONTH(timestamps)=12"); + ResultSet rs = conn.createStatement().executeQuery("SELECT k1, DAYOFMONTH(dates), DAYOFMONTH(times) FROM " + tableName + " where DAYOFMONTH(timestamps)=12"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertEquals(8, rs.getInt(2)); @@ -676,7 +690,8 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testNullDate() throws Exception { - ResultSet rs = conn.createStatement().executeQuery("SELECT a_date, entity_id from " + ATABLE_NAME + " WHERE entity_id = '" + ROW10 + "'"); + + ResultSet rs = conn.createStatement().executeQuery("SELECT a_date, entity_id from " + this.tableName + " WHERE entity_id = '" + ROW10 + "'"); assertNotNull(rs); assertTrue(rs.next()); assertEquals(ROW10, rs.getString(2)); @@ -695,19 +710,20 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { } @Test public void testSelectBetweenNanos() throws Exception { + String tableName = generateRandomString(); String ddl = - "CREATE TABLE IF NOT EXISTS N1 (k1 INTEGER NOT NULL PRIMARY KEY, ts " + + "CREATE TABLE IF NOT EXISTS " + tableName + " (k1 INTEGER NOT NULL PRIMARY KEY, ts " + "TIMESTAMP(3))"; conn.createStatement().execute(ddl); - String dml = "UPSERT INTO N1 VALUES (1, TIMESTAMP'2015-01-01 00:00:00.111111111')"; + String dml = "UPSERT INTO " + tableName + " VALUES (1, TIMESTAMP'2015-01-01 00:00:00.111111111')"; conn.createStatement().execute(dml); - dml = "UPSERT INTO N1 VALUES (2, TIMESTAMP'2015-01-01 00:00:00.111111115')"; + dml = "UPSERT INTO " + tableName + " VALUES (2, TIMESTAMP'2015-01-01 00:00:00.111111115')"; conn.createStatement().execute(dml); - dml = "UPSERT INTO N1 VALUES (3, TIMESTAMP'2015-01-01 00:00:00.111111113')"; + dml = "UPSERT INTO " + tableName + " VALUES (3, TIMESTAMP'2015-01-01 00:00:00.111111113')"; conn.createStatement().execute(dml); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT k1,ts from N1 where ts between" + + ResultSet rs = conn.createStatement().executeQuery("SELECT k1,ts from " + tableName + " where ts between" + " TIMESTAMP'2015-01-01 00:00:00.111111112' AND TIMESTAMP'2015-01-01 00:00:00" + ".111111114'"); assertTrue(rs.next()); @@ -718,17 +734,19 @@ public class DateTimeIT extends BaseHBaseManagedTimeIT { @Test public void testCurrentTimeWithProjectedTable () throws Exception { - String ddl = "CREATE TABLE T1 ( ID integer primary key)"; + String tableName1 = generateRandomString(); + String tableName2 = generateRandomString(); + String ddl = "CREATE TABLE " + tableName1 + " ( ID integer primary key)"; conn.createStatement().execute(ddl); - ddl = "CREATE TABLE T2 ( ID integer primary key)"; + ddl = "CREATE TABLE " + tableName2 + " ( ID integer primary key)"; conn.createStatement().execute(ddl); - String ups = "UPSERT INTO T1 VALUES (1)"; + String ups = "UPSERT INTO " + tableName1 + " VALUES (1)"; conn.createStatement().execute(ups); - ups = "UPSERT INTO T2 VALUES (1)"; + ups = "UPSERT INTO " + tableName2 + " VALUES (1)"; conn.createStatement().execute(ups); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("select /*+ USE_SORT_MERGE_JOIN */ op" + - ".id, current_time() from t1 op where op.id in (select id from t2)"); + ".id, current_time() from " +tableName1 + " op where op.id in (select id from " + tableName2 + ")"); assertTrue(rs.next()); assertEquals(new java.util.Date().getYear(),rs.getTimestamp(2).getYear()); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java index 1536ea6..cca4eb4 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java @@ -37,13 +37,14 @@ import org.apache.phoenix.util.QueryUtil; import org.junit.Test; -public class DeleteIT extends BaseHBaseManagedTimeIT { +public class DeleteIT extends BaseHBaseManagedTimeTableReuseIT { private static final int NUMBER_OF_ROWS = 20; private static final int NTH_ROW_NULL = 5; - private static void initTableValues(Connection conn) throws SQLException { - ensureTableCreated(getUrl(),"IntIntKeyTest"); - String upsertStmt = "UPSERT INTO IntIntKeyTest VALUES(?,?)"; + private static String initTableValues(Connection conn) throws SQLException { + String tableName = generateRandomString(); + ensureTableCreated(getUrl(), tableName, "IntIntKeyTest"); + String upsertStmt = "UPSERT INTO " + tableName + " VALUES(?,?)"; PreparedStatement stmt = conn.prepareStatement(upsertStmt); for (int i = 0; i < NUMBER_OF_ROWS; i++) { stmt.setInt(1, i); @@ -55,6 +56,7 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { stmt.execute(); } conn.commit(); + return tableName; } @Test @@ -69,18 +71,18 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { private void testDeleteFilter(boolean autoCommit) throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - initTableValues(conn); + String tableName = initTableValues(conn); - assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS); + assertTableCount(conn, tableName, NUMBER_OF_ROWS); conn.setAutoCommit(autoCommit); - String deleteStmt = "DELETE FROM IntIntKeyTest WHERE 20 = j"; + String deleteStmt = "DELETE FROM " + tableName + " WHERE 20 = j"; assertEquals(1,conn.createStatement().executeUpdate(deleteStmt)); if (!autoCommit) { conn.commit(); } - assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS - 1); + assertTableCount(conn, tableName, NUMBER_OF_ROWS - 1); } @Test @@ -96,34 +98,34 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { private void testDeleteByFilterAndRow(boolean autoCommit) throws SQLException { Connection conn = DriverManager.getConnection(getUrl()); - initTableValues(conn); + String tableName = initTableValues(conn); - assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS); + assertTableCount(conn, tableName, NUMBER_OF_ROWS); conn.setAutoCommit(autoCommit); Statement stmt = conn.createStatement(); // This shouldn't delete anything, because the key matches but the filter doesn't - assertEquals(0, stmt.executeUpdate("DELETE FROM IntIntKeyTest WHERE i = 1 AND j = 1")); + assertEquals(0, stmt.executeUpdate("DELETE FROM " + tableName + " WHERE i = 1 AND j = 1")); if (!autoCommit) { conn.commit(); } - assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS); + assertTableCount(conn, tableName, NUMBER_OF_ROWS); // This shouldn't delete anything, because the filter matches but the key doesn't - assertEquals(0, stmt.executeUpdate("DELETE FROM IntIntKeyTest WHERE i = -1 AND j = 20")); + assertEquals(0, stmt.executeUpdate("DELETE FROM " + tableName + " WHERE i = -1 AND j = 20")); if (!autoCommit) { conn.commit(); } - assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS); + assertTableCount(conn, tableName, NUMBER_OF_ROWS); // This should do a delete, because both the filter and key match - assertEquals(1, stmt.executeUpdate("DELETE FROM IntIntKeyTest WHERE i = 1 AND j = 10")); + assertEquals(1, stmt.executeUpdate("DELETE FROM " + tableName + " WHERE i = 1 AND j = 10")); if (!autoCommit) { conn.commit(); } - assertTableCount(conn, "IntIntKeyTest", NUMBER_OF_ROWS - 1); + assertTableCount(conn, tableName, NUMBER_OF_ROWS - 1); } @@ -154,40 +156,42 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { private void testDeleteRange(boolean autoCommit, boolean createIndex, boolean local) throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - initTableValues(conn); - - String indexName = "IDX"; + String tableName = initTableValues(conn); + String indexName = generateRandomString(); + String localIndexName = generateRandomString(); + + String indexInUse = indexName; if (createIndex) { if (local) { - conn.createStatement().execute("CREATE LOCAL INDEX IF NOT EXISTS local_idx ON IntIntKeyTest(j)"); - indexName = "INTINTKEYTEST"; + conn.createStatement().execute("CREATE LOCAL INDEX IF NOT EXISTS " + localIndexName + " ON " + tableName + "(j)"); + indexInUse = tableName; } else { - conn.createStatement().execute("CREATE INDEX IF NOT EXISTS idx ON IntIntKeyTest(j)"); + conn.createStatement().execute("CREATE INDEX IF NOT EXISTS " + indexName + " ON " + tableName + "(j)"); } } ResultSet rs; - rs = conn.createStatement().executeQuery("SELECT count(*) FROM IntIntKeyTest"); + rs = conn.createStatement().executeQuery("SELECT count(*) FROM " + tableName); assertTrue(rs.next()); assertEquals(NUMBER_OF_ROWS, rs.getInt(1)); - rs = conn.createStatement().executeQuery("SELECT i FROM IntIntKeyTest WHERE j IS NULL"); + rs = conn.createStatement().executeQuery("SELECT i FROM " + tableName + " WHERE j IS NULL"); int i = 0, isNullCount = 0; while (rs.next()) { assertEquals(i,rs.getInt(1)); i += NTH_ROW_NULL; isNullCount++; } - rs = conn.createStatement().executeQuery("SELECT count(*) FROM IntIntKeyTest WHERE j IS NOT NULL"); + rs = conn.createStatement().executeQuery("SELECT count(*) FROM " + tableName + " WHERE j IS NOT NULL"); assertTrue(rs.next()); assertEquals(NUMBER_OF_ROWS-isNullCount, rs.getInt(1)); String deleteStmt ; PreparedStatement stmt; conn.setAutoCommit(autoCommit); - deleteStmt = "DELETE FROM IntIntKeyTest WHERE i >= ? and i < ?"; + deleteStmt = "DELETE FROM " + tableName + " WHERE i >= ? and i < ?"; if(!local) { - assertIndexUsed(conn, deleteStmt, Arrays.<Object>asList(5,10), indexName, false); + assertIndexUsed(conn, deleteStmt, Arrays.<Object>asList(5,10), indexInUse, false); } stmt = conn.prepareStatement(deleteStmt); stmt.setInt(1, 5); @@ -197,24 +201,24 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { conn.commit(); } - String query = "SELECT count(*) FROM IntIntKeyTest"; - assertIndexUsed(conn, query, indexName, createIndex); - query = "SELECT count(*) FROM IntIntKeyTest"; + String query = "SELECT count(*) FROM " + tableName; + assertIndexUsed(conn, query, indexInUse, createIndex); + query = "SELECT count(*) FROM " + tableName; rs = conn.createStatement().executeQuery(query); assertTrue(rs.next()); assertEquals(NUMBER_OF_ROWS - (10-5), rs.getInt(1)); - deleteStmt = "DELETE FROM IntIntKeyTest WHERE j IS NULL"; + deleteStmt = "DELETE FROM " + tableName + " WHERE j IS NULL"; stmt = conn.prepareStatement(deleteStmt); if(!local) { - assertIndexUsed(conn, deleteStmt, indexName, createIndex); + assertIndexUsed(conn, deleteStmt, indexInUse, createIndex); } int deleteCount = stmt.executeUpdate(); assertEquals(3, deleteCount); if (!autoCommit) { conn.commit(); } - rs = conn.createStatement().executeQuery("SELECT count(*) FROM IntIntKeyTest"); + rs = conn.createStatement().executeQuery("SELECT count(*) FROM " + tableName); assertTrue(rs.next()); assertEquals(NUMBER_OF_ROWS - (10-5)-isNullCount+1, rs.getInt(1)); } @@ -290,7 +294,8 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con.setAutoCommit(autoCommit); Statement stm = con.createStatement(); - String s = "CREATE TABLE IF NOT EXISTS web_stats (" + + String tableName = generateRandomString(); + String s = "CREATE TABLE IF NOT EXISTS " + tableName + "(" + "HOST CHAR(2) NOT NULL," + "DOMAIN VARCHAR NOT NULL, " + "FEATURE VARCHAR NOT NULL, " + @@ -300,15 +305,17 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { "STATS.ACTIVE_VISITOR INTEGER " + "CONSTRAINT PK PRIMARY KEY (HOST, DOMAIN, FEATURE, DATE))" + (isSalted ? " SALT_BUCKETS=3" : ""); stm.execute(s); + String localIndexName = generateRandomString(); + String indexName = generateRandomString(); if (localIndex) { - stm.execute("CREATE LOCAL INDEX local_web_stats_idx ON web_stats (CORE,DB,ACTIVE_VISITOR)"); + stm.execute("CREATE LOCAL INDEX " + localIndexName + " ON " + tableName + " (CORE,DB,ACTIVE_VISITOR)"); } else { - stm.execute("CREATE INDEX web_stats_idx ON web_stats (CORE,DB,ACTIVE_VISITOR)"); + stm.execute("CREATE INDEX " + indexName + " ON " + tableName + " (CORE,DB,ACTIVE_VISITOR)"); } stm.close(); PreparedStatement psInsert = con - .prepareStatement("UPSERT INTO web_stats(HOST, DOMAIN, FEATURE, DATE, CORE, DB, ACTIVE_VISITOR) VALUES(?,?, ? , ?, ?, ?, ?)"); + .prepareStatement("UPSERT INTO " + tableName + "(HOST, DOMAIN, FEATURE, DATE, CORE, DB, ACTIVE_VISITOR) VALUES(?,?, ? , ?, ?, ?, ?)"); psInsert.setString(1, "AA"); psInsert.setString(2, "BB"); psInsert.setString(3, "CC"); @@ -322,18 +329,18 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con.commit(); } - con.createStatement().execute("DELETE FROM web_stats"); + con.createStatement().execute("DELETE FROM " + tableName ); if (!autoCommit) { con.commit(); } - ResultSet rs = con.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM web_stats"); + ResultSet rs = con.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM " + tableName); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); if(localIndex){ - rs = con.createStatement().executeQuery("SELECT count(*) FROM local_web_stats_idx"); + rs = con.createStatement().executeQuery("SELECT count(*) FROM " + localIndexName); } else { - rs = con.createStatement().executeQuery("SELECT count(*) FROM web_stats_idx"); + rs = con.createStatement().executeQuery("SELECT count(*) FROM " + indexName); } assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); @@ -364,7 +371,12 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con.setAutoCommit(autoCommit); Statement stm = con.createStatement(); - stm.execute("CREATE TABLE IF NOT EXISTS web_stats (" + + + String tableName = generateRandomString(); + String indexName1 = generateRandomString(); + String indexName2 = generateRandomString(); + + stm.execute("CREATE TABLE IF NOT EXISTS " + tableName + " (" + "HOST CHAR(2) NOT NULL," + "DOMAIN VARCHAR NOT NULL, " + "FEATURE VARCHAR NOT NULL, " + @@ -373,13 +385,13 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { "USAGE.DB BIGINT," + "STATS.ACTIVE_VISITOR INTEGER " + "CONSTRAINT PK PRIMARY KEY (HOST, DOMAIN, FEATURE, DATE)) IMMUTABLE_ROWS=true"); - stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX web_stats_idx ON web_stats (DATE, FEATURE)"); - stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX web_stats_idx2 ON web_stats (DATE, FEATURE, USAGE.DB)"); + stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName1 + " ON " + tableName + " (DATE, FEATURE)"); + stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName2 + " ON " + tableName + " (DATE, FEATURE, USAGE.DB)"); stm.close(); Date date = new Date(0); PreparedStatement psInsert = con - .prepareStatement("UPSERT INTO web_stats(HOST, DOMAIN, FEATURE, DATE, CORE, DB, ACTIVE_VISITOR) VALUES(?,?, ? , ?, ?, ?, ?)"); + .prepareStatement("UPSERT INTO " + tableName + "(HOST, DOMAIN, FEATURE, DATE, CORE, DB, ACTIVE_VISITOR) VALUES(?,?, ? , ?, ?, ?, ?)"); psInsert.setString(1, "AA"); psInsert.setString(2, "BB"); psInsert.setString(3, "CC"); @@ -393,7 +405,7 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con.commit(); } - psInsert = con.prepareStatement("DELETE FROM web_stats WHERE (HOST, DOMAIN, FEATURE, DATE) = (?,?,?,?)"); + psInsert = con.prepareStatement("DELETE FROM " + tableName + " WHERE (HOST, DOMAIN, FEATURE, DATE) = (?,?,?,?)"); psInsert.setString(1, "AA"); psInsert.setString(2, "BB"); psInsert.setString(3, "CC"); @@ -403,21 +415,21 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con.commit(); } - ResultSet rs = con.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM web_stats"); + ResultSet rs = con.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM " + tableName); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); - rs = con.createStatement().executeQuery("SELECT count(*) FROM web_stats_idx"); + rs = con.createStatement().executeQuery("SELECT count(*) FROM " + indexName1); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); - stm.execute("DROP INDEX web_stats_idx ON web_stats"); - stm.execute("DROP INDEX web_stats_idx2 ON web_stats"); + stm.execute("DROP INDEX " + indexName1 + " ON " + tableName); + stm.execute("DROP INDEX " + indexName2 + " ON " + tableName); - stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX web_stats_idx ON web_stats (USAGE.DB)"); - stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX web_stats_idx2 ON web_stats (USAGE.DB, DATE)"); + stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName1 + " ON " + tableName + " (USAGE.DB)"); + stm.execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexName2 + " ON " + tableName + " (USAGE.DB, DATE)"); try{ - psInsert = con.prepareStatement("DELETE FROM web_stats WHERE USAGE.DB=2"); + psInsert = con.prepareStatement("DELETE FROM " + tableName + " WHERE USAGE.DB=2"); } catch(Exception e) { fail("There should not be any exception while deleting row"); } @@ -446,9 +458,11 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con = DriverManager.getConnection(getUrl()); con.setAutoCommit(autoCommit); + String tableName = generateRandomString(); + Statement stm = con.createStatement(); - stm.execute("CREATE TABLE IF NOT EXISTS web_stats (" + - "HOST CHAR(2) NOT NULL," + + stm.execute("CREATE TABLE IF NOT EXISTS " + tableName + "(" + + " HOST CHAR(2) NOT NULL," + "DOMAIN VARCHAR NOT NULL, " + "FEATURE VARCHAR NOT NULL, " + "DATE DATE NOT NULL, \n" + @@ -459,7 +473,7 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { stm.close(); PreparedStatement psInsert = con - .prepareStatement("UPSERT INTO web_stats(HOST, DOMAIN, FEATURE, DATE, CORE, DB, ACTIVE_VISITOR) VALUES(?,?, ? , ?, ?, ?, ?)"); + .prepareStatement("UPSERT INTO " + tableName + "(HOST, DOMAIN, FEATURE, DATE, CORE, DB, ACTIVE_VISITOR) VALUES(?,?, ? , ?, ?, ?, ?)"); psInsert.setString(1, "AA"); psInsert.setString(2, "BB"); psInsert.setString(3, "CC"); @@ -473,12 +487,12 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { con.commit(); } - con.createStatement().execute("DELETE FROM web_stats"); + con.createStatement().execute("DELETE FROM " + tableName); if (!autoCommit) { con.commit(); } - ResultSet rs = con.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM web_stats"); + ResultSet rs = con.createStatement().executeQuery("SELECT /*+ NO_INDEX */ count(*) FROM " + tableName); assertTrue(rs.next()); assertEquals(0, rs.getLong(1)); } finally { @@ -568,17 +582,19 @@ public class DeleteIT extends BaseHBaseManagedTimeIT { } private void testDeleteCount(boolean autoCommit, Integer limit) throws Exception { - String ddl = "CREATE TABLE IF NOT EXISTS TEST_TABLE (pk1 DECIMAL NOT NULL, v1 VARCHAR CONSTRAINT PK PRIMARY KEY (pk1))"; + String tableName = generateRandomString(); + + String ddl = "CREATE TABLE IF NOT EXISTS " + tableName + " (pk1 DECIMAL NOT NULL, v1 VARCHAR CONSTRAINT PK PRIMARY KEY (pk1))"; int numRecords = 1010; try (Connection conn = DriverManager.getConnection(getUrl())) { conn.createStatement().execute(ddl); Statement stmt = conn.createStatement(); for (int i = 0; i < numRecords ; i++) { - stmt.executeUpdate("UPSERT INTO TEST_TABLE (pk1, v1) VALUES (" + i + ",'value')"); + stmt.executeUpdate("UPSERT INTO " + tableName + " (pk1, v1) VALUES (" + i + ",'value')"); } conn.commit(); conn.setAutoCommit(autoCommit); - String delete = "DELETE FROM TEST_TABLE WHERE (pk1) <= (" + numRecords + ")" + (limit == null ? "" : (" limit " + limit)); + String delete = "DELETE FROM " + tableName + " WHERE (pk1) <= (" + numRecords + ")" + (limit == null ? "" : (" limit " + limit)); try (PreparedStatement pstmt = conn.prepareStatement(delete)) { int numberOfDeletes = pstmt.executeUpdate(); assertEquals(limit == null ? numRecords : limit, numberOfDeletes);
