http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java index ce073f6..16ad47f 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java @@ -32,6 +32,7 @@ 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.apache.phoenix.util.TestUtil.ATABLE_NAME; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -73,7 +74,7 @@ public class DerivedTableIT extends BaseClientManagedTimeIT { @Before public void initTable() throws Exception { ts = nextTimestamp(); - initATableValues(tenantId, getDefaultSplits(tenantId), null, ts); + initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId), null, ts, getUrl()); if (indexDDL != null && indexDDL.length > 0) { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java index 5f18a1c..38dfa8c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DisableLocalIndexIT.java @@ -43,9 +43,9 @@ import org.junit.Test; import com.google.common.collect.Maps; -public class DisableLocalIndexIT extends BaseHBaseManagedTimeIT { +public class DisableLocalIndexIT extends BaseHBaseManagedTimeTableReuseIT { @BeforeClass - @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) + @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class) public static void doSetup() throws Exception { Map<String,String> props = Maps.newHashMapWithExpectedSize(1); // Must update config before starting server @@ -57,7 +57,11 @@ public class DisableLocalIndexIT extends BaseHBaseManagedTimeIT { public void testDisabledLocalIndexes() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); conn.setAutoCommit(true); - String tableName = "DISABLE_LOCAL_INDEX_TEST"; + String baseName = generateRandomString(); + String tableName = baseName+ "_TABLE"; + String viewName = baseName + "_VIEW"; + String indexName1 = baseName + "_INDEX1"; + String indexName2 = baseName + "_INDEX2"; conn.createStatement().execute("CREATE TABLE " + tableName + " (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) MULTI_TENANT=true"); conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('t1','x')"); conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('t2','y')"); @@ -78,18 +82,18 @@ public class DisableLocalIndexIT extends BaseHBaseManagedTimeIT { props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, "t1"); Connection tsconn = DriverManager.getConnection(getUrl(), props); - tsconn.createStatement().execute("CREATE VIEW A.BAR(V1 VARCHAR) AS SELECT * FROM " + tableName); - tsconn.createStatement().execute("CREATE INDEX I1 ON A.BAR(V1)"); + tsconn.createStatement().execute("CREATE VIEW " + viewName + "(V1 VARCHAR) AS SELECT * FROM " + tableName); + tsconn.createStatement().execute("CREATE INDEX " + indexName1 + " ON " + viewName + "(V1)"); tsconn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(MetaDataUtil.VIEW_INDEX_TABLE_PREFIX + tableName)); try { - conn.createStatement().execute("CREATE LOCAL INDEX I2 ON " + tableName + "(k2)"); + conn.createStatement().execute("CREATE LOCAL INDEX " + indexName2 + " ON " + tableName + "(k2)"); fail("Should not allow creation of local index"); } catch (SQLException e) { assertEquals(SQLExceptionCode.UNALLOWED_LOCAL_INDEXES.getErrorCode(), e.getErrorCode()); } try { - tsconn.createStatement().execute("CREATE LOCAL INDEX I2 ON A.BAR(k2, v1)"); + tsconn.createStatement().execute("CREATE LOCAL INDEX " + indexName2 + " ON " + viewName + "(k2, v1)"); fail("Should not allow creation of local index"); } catch (SQLException e) { assertEquals(SQLExceptionCode.UNALLOWED_LOCAL_INDEXES.getErrorCode(), e.getErrorCode()); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java index 500998b..4484fc1 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java @@ -287,9 +287,9 @@ public class DistinctCountIT extends BaseClientManagedTimeIT { protected static void initATableValues(String tenantId1, String tenantId2, byte[][] splits, Date date, Long ts) throws Exception { if (ts == null) { - ensureTableCreated(getUrl(), ATABLE_NAME, splits); + ensureTableCreated(getUrl(), ATABLE_NAME, ATABLE_NAME, splits); } else { - ensureTableCreated(getUrl(), ATABLE_NAME, splits, ts-2); + ensureTableCreated(getUrl(), ATABLE_NAME, ATABLE_NAME, splits, ts-2); } Properties props = new Properties(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java index 31b0dd7..e30c474 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DynamicColumnIT.java @@ -59,31 +59,25 @@ import org.junit.Test; */ -public class DynamicColumnIT extends BaseHBaseManagedTimeIT { +public class DynamicColumnIT extends BaseHBaseManagedTimeTableReuseIT { private static final byte[] FAMILY_NAME_A = Bytes.toBytes(SchemaUtil.normalizeIdentifier("A")); private static final byte[] FAMILY_NAME_B = Bytes.toBytes(SchemaUtil.normalizeIdentifier("B")); + private static String tableName = "TESTTBL"; + @BeforeClass public static void doBeforeTestSetup() throws Exception { try (PhoenixConnection pconn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class)) { ConnectionQueryServices services = pconn.getQueryServices(); try (HBaseAdmin admin = services.getAdmin()) { - HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(HBASE_DYNAMIC_COLUMNS)); + HTableDescriptor htd = new HTableDescriptor(TableName.valueOf("TESTTBL")); htd.addFamily(new HColumnDescriptor(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES)); htd.addFamily(new HColumnDescriptor(FAMILY_NAME_A)); htd.addFamily(new HColumnDescriptor(FAMILY_NAME_B)); admin.createTable(htd); } - } - } - - @SuppressWarnings("deprecation") - @Before - public void createTable() throws Exception { - try (PhoenixConnection pconn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class)) { - ConnectionQueryServices services = pconn.getQueryServices(); - HTableInterface hTable = services.getTable(Bytes.toBytes(HBASE_DYNAMIC_COLUMNS)); - try { + + try (HTableInterface hTable = services.getTable(Bytes.toBytes(tableName))) { // Insert rows using standard HBase mechanism with standard HBase "types" List<Row> mutations = new ArrayList<Row>(); byte[] dv = Bytes.toBytes("DV"); @@ -93,7 +87,7 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { byte[] f2v1 = Bytes.toBytes("F2V1"); byte[] f2v2 = Bytes.toBytes("F2V2"); byte[] key = Bytes.toBytes("entry1"); - + Put put = new Put(key); put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, dv, Bytes.toBytes("default")); put.add(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, first, Bytes.toBytes("first")); @@ -102,15 +96,14 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { put.add(FAMILY_NAME_B, f2v1, Bytes.toBytes("f2value1")); put.add(FAMILY_NAME_B, f2v2, Bytes.toBytes("f2value2")); mutations.add(put); - + hTable.batch(mutations); - + // Create Phoenix table after HBase table was created through the native APIs // The timestamp of the table creation must be later than the timestamp of the data - ensureTableCreated(getUrl(), HBASE_DYNAMIC_COLUMNS); - } finally { - hTable.close(); + ensureTableCreated(getUrl(), tableName, HBASE_DYNAMIC_COLUMNS); } + } } @@ -119,7 +112,7 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { */ @Test public void testDynamicColums() throws Exception { - String query = "SELECT * FROM HBASE_DYNAMIC_COLUMNS (DV varchar)"; + String query = "SELECT * FROM " + tableName + " (DV varchar)"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -143,7 +136,7 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { */ @Test public void testDynamicColumsFamily() throws Exception { - String query = "SELECT * FROM HBASE_DYNAMIC_COLUMNS (DV varchar,B.F2V2 varchar)"; + String query = "SELECT * FROM " + tableName + " (DV varchar,B.F2V2 varchar)"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -169,7 +162,7 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { @Test public void testDynamicColumsSpecificQuery() throws Exception { - String query = "SELECT entry,F2V2 FROM HBASE_DYNAMIC_COLUMNS (DV varchar,B.F2V2 varchar)"; + String query = "SELECT entry,F2V2 FROM " + tableName + " (DV varchar,B.F2V2 varchar)"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -189,7 +182,7 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { */ @Test(expected = ColumnAlreadyExistsException.class) public void testAmbiguousStaticSelect() throws Exception { - String upsertquery = "Select * FROM HBASE_DYNAMIC_COLUMNS(A.F1V1 INTEGER)"; + String upsertquery = "Select * FROM " + tableName + "(A.F1V1 INTEGER)"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -205,7 +198,7 @@ public class DynamicColumnIT extends BaseHBaseManagedTimeIT { */ @Test(expected = ColumnFamilyNotFoundException.class) public void testFakeCFDynamicUpsert() throws Exception { - String upsertquery = "Select * FROM HBASE_DYNAMIC_COLUMNS(fakecf.DynCol VARCHAR)"; + String upsertquery = "Select * FROM " + tableName + "(fakecf.DynCol VARCHAR)"; Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java index ceafc5b..d32b900 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EncodeFunctionIT.java @@ -35,7 +35,7 @@ import org.junit.Test; import com.google.common.collect.Lists; -public class EncodeFunctionIT extends BaseHBaseManagedTimeIT { +public class EncodeFunctionIT extends BaseHBaseManagedTimeTableReuseIT { /** * Helper to test ENCODE function @@ -46,13 +46,13 @@ public class EncodeFunctionIT extends BaseHBaseManagedTimeIT { * name of column to query * @param sortOrder * sort order of the pk column - * @param expectedOutput + * @param expectedOutputList * expected output of ENCODE function */ - private void testEncodeHelper(Connection conn, String colName, List<String> expectedOutputList, String sortOrder) + private void testEncodeHelper(Connection conn, String tableName, String colName, List<String> expectedOutputList, String sortOrder) throws Exception { for (int id = 0; id < expectedOutputList.size(); ++id) { - String sql = String.format("SELECT ENCODE(%s, 'base62') FROM TEST_TABLE_%s WHERE id=?", colName, sortOrder); + String sql = String.format("SELECT ENCODE(%s, 'base62') FROM " + tableName + "_%s WHERE id=?", colName, sortOrder); PreparedStatement stmt = conn.prepareStatement(sql); stmt.setInt(1, id); @@ -74,9 +74,9 @@ public class EncodeFunctionIT extends BaseHBaseManagedTimeIT { * expected output of ENCODE function */ private void testEncode(Connection conn, List<Object> inputList, List<String> expectedOutputList) throws Exception { - TestUtil.initTables(conn, "BIGINT", inputList); - testEncodeHelper(conn, "pk", expectedOutputList, "ASC"); - testEncodeHelper(conn, "pk", expectedOutputList, "DESC"); + String tableName = TestUtil.initTables(conn, "BIGINT", inputList); + testEncodeHelper(conn, tableName, "pk", expectedOutputList, "ASC"); + testEncodeHelper(conn, tableName, "pk", expectedOutputList, "DESC"); } @Test @@ -89,45 +89,48 @@ public class EncodeFunctionIT extends BaseHBaseManagedTimeIT { @Test public void testEncodeNullInput() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - TestUtil.initTables(conn, "BIGINT", Collections.<Object> singletonList(0l)); - testEncodeHelper(conn, "kv", Collections.<String> singletonList(null), "ASC"); - testEncodeHelper(conn, "kv", Collections.<String> singletonList(null), "DESC"); + String tableName = TestUtil.initTables(conn, "BIGINT", Collections.<Object> singletonList(0l)); + testEncodeHelper(conn, tableName, "kv", Collections.<String> singletonList(null), "ASC"); + testEncodeHelper(conn, tableName, "kv", Collections.<String> singletonList(null), "DESC"); } @Test public void testUpperCaseEncodingType() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - String ddl = "CREATE TABLE TEST_TABLE ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + " ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; conn.createStatement().execute(ddl); - PreparedStatement ps = conn.prepareStatement("UPSERT INTO TEST_TABLE (pk) VALUES (?)"); + PreparedStatement ps = conn.prepareStatement("UPSERT INTO " + tableName + " (pk) VALUES (?)"); ps.setString(1, "1"); ps.execute(); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST_TABLE WHERE pk = ENCODE(1, 'BASE62')"); + ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName + " WHERE pk = ENCODE(1, 'BASE62')"); assertTrue(rs.next()); } @Test public void testNullEncodingType() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - String ddl = "CREATE TABLE TEST_TABLE ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + " ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; conn.createStatement().execute(ddl); - ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM TEST_TABLE WHERE pk = ENCODE(1, NULL)"); + ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName + " WHERE pk = ENCODE(1, NULL)"); assertFalse(rs.next()); } @Test public void testUnsupportedEncodingType() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - String ddl = "CREATE TABLE TEST_TABLE ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; + String tableName = generateRandomString(); + String ddl = "CREATE TABLE " + tableName + " ( pk VARCHAR(10) NOT NULL CONSTRAINT PK PRIMARY KEY (pk))"; conn.createStatement().execute(ddl); try { - conn.createStatement().executeQuery("SELECT * FROM TEST_TABLE WHERE pk = ENCODE(1, 'HEX')"); + conn.createStatement().executeQuery("SELECT * FROM " + tableName + " WHERE pk = ENCODE(1, 'HEX')"); fail(); } catch (SQLException e) { assertEquals(SQLExceptionCode.ILLEGAL_DATA.getErrorCode(), e.getErrorCode()); @@ -137,13 +140,14 @@ public class EncodeFunctionIT extends BaseHBaseManagedTimeIT { @Test public void testInvalidEncodingType() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); + String tableName = generateRandomString(); String ddl = - "CREATE TABLE test_table ( some_column BINARY(12) NOT NULL CONSTRAINT PK PRIMARY KEY (some_column))"; + "CREATE TABLE " + tableName + " ( some_column BINARY(12) NOT NULL CONSTRAINT PK PRIMARY KEY (some_column))"; conn.createStatement().execute(ddl); try { conn.createStatement().executeQuery( - "SELECT * FROM test_table WHERE some_column = ENCODE(1, 'invalidEncodingFormat')"); + "SELECT * FROM " + tableName + " WHERE some_column = ENCODE(1, 'invalidEncodingFormat')"); fail(); } catch (SQLException e) { } http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java index 4355036..d0a561b 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/EvaluationOfORIT.java @@ -33,8 +33,10 @@ import org.apache.phoenix.util.PropertiesUtil; import org.junit.Test; -public class EvaluationOfORIT extends BaseHBaseManagedTimeIT{ - + + +public class EvaluationOfORIT extends BaseHBaseManagedTimeTableReuseIT{ + @Test public void testFalseOrFalse() throws SQLException { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); @@ -48,15 +50,16 @@ public class EvaluationOfORIT extends BaseHBaseManagedTimeIT{ @Test public void testPKOrNotPKInOREvaluation() throws SQLException { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); + Connection conn = DriverManager.getConnection(getUrl(), props); + String tableName = generateRandomString(); conn.setAutoCommit(false); - String create = "CREATE TABLE DIE ( ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(50))"; + String create = "CREATE TABLE " + tableName + " ( ID INTEGER NOT NULL PRIMARY KEY,NAME VARCHAR(50))"; PreparedStatement createStmt = conn.prepareStatement(create); createStmt.execute(); PreparedStatement stmt = conn.prepareStatement( "upsert into " + - "DIE VALUES (?, ?)"); + tableName + " VALUES (?, ?)"); stmt.setInt(1, 1); stmt.setString(2, "Tester1"); @@ -163,7 +166,7 @@ public class EvaluationOfORIT extends BaseHBaseManagedTimeIT{ stmt.execute(); conn.commit(); - String select = "Select * from DIE where ID=6 or Name between 'Tester1' and 'Tester3'"; + String select = "Select * from " + tableName + " where ID=6 or Name between 'Tester1' and 'Tester3'"; ResultSet rs; rs = conn.createStatement().executeQuery(select); assertTrue(rs.next()); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java index 1b41bdd..41d3ee7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExecuteStatementsIT.java @@ -48,33 +48,34 @@ import org.apache.phoenix.util.PhoenixRuntime; import org.junit.Test; -public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { +public class ExecuteStatementsIT extends BaseHBaseManagedTimeTableReuseIT { @Test public void testExecuteStatements() throws Exception { String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId), getUrl()); + String tableName = initATableValues(tenantId, getDefaultSplits(tenantId), getUrl()); + String ptsdbTableName = generateRandomString(); String statements = - "create table if not exists " + ATABLE_NAME + // Shouldn't error out b/c of if not exists clause + "create table if not exists " + tableName + // Shouldn't error out b/c of if not exists clause " (organization_id char(15) not null, \n" + " entity_id char(15) not null,\n" + " a_string varchar(100),\n" + " b_string varchar(100)\n" + " CONSTRAINT pk PRIMARY KEY (organization_id,entity_id));\n" + - "create table " + PTSDB_NAME + + "create table " + ptsdbTableName + " (inst varchar null,\n" + " host varchar null,\n" + " date date not null,\n" + " val decimal\n" + " CONSTRAINT pk PRIMARY KEY (inst,host,date))\n" + " split on (?,?,?);\n" + - "alter table " + PTSDB_NAME + " add if not exists val decimal;\n" + // Shouldn't error out b/c of if not exists clause - "alter table " + PTSDB_NAME + " drop column if exists blah;\n" + // Shouldn't error out b/c of if exists clause + "alter table " + ptsdbTableName + " add if not exists val decimal;\n" + // Shouldn't error out b/c of if not exists clause + "alter table " + ptsdbTableName + " drop column if exists blah;\n" + // Shouldn't error out b/c of if exists clause "drop table if exists FOO.BAR;\n" + // Shouldn't error out b/c of if exists clause - "UPSERT INTO " + PTSDB_NAME + "(date, val, host) " + - " SELECT current_date(), x_integer+2, entity_id FROM ATABLE WHERE a_integer >= ?;" + - "UPSERT INTO " + PTSDB_NAME + "(date, val, inst)\n" + - " SELECT date+1, val*10, host FROM " + PTSDB_NAME + ";"; + "UPSERT INTO " + ptsdbTableName + "(date, val, host) " + + " SELECT current_date(), x_integer+2, entity_id FROM " + tableName + " WHERE a_integer >= ?;" + + "UPSERT INTO " + ptsdbTableName + "(date, val, inst)\n" + + " SELECT date+1, val*10, host FROM " + ptsdbTableName + ";"; Date now = new Date(System.currentTimeMillis()); Connection conn = DriverManager.getConnection(getUrl()); @@ -84,7 +85,7 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { assertEquals(7, nStatements); Date then = new Date(System.currentTimeMillis() + QueryConstants.MILLIS_IN_DAY); - String query = "SELECT host,inst, date,val FROM " + PTSDB_NAME + " where inst is not null"; + String query = "SELECT host,inst, date,val FROM " + ptsdbTableName + " where inst is not null"; PreparedStatement statement = conn.prepareStatement(query); ResultSet rs = statement.executeQuery(); @@ -119,7 +120,7 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { @Test public void testCharPadding() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); - String tableName = "foo"; + String tableName = generateRandomString(); String rowKey = "hello"; String testString = "world"; String query = "create table " + tableName + @@ -142,10 +143,11 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { statement.setString(3, testString); statement.execute(); conn.commit(); - - ensureTableCreated(getUrl(),BTABLE_NAME, null, nextTimestamp()-2); + + String btableName = generateRandomString(); + ensureTableCreated(getUrl(),btableName, BTABLE_NAME, nextTimestamp()-2); statement = conn.prepareStatement( - "upsert into BTABLE VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "upsert into " + btableName + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, "abc"); statement.setString(2, "xyz"); statement.setString(3, "x"); @@ -197,10 +199,10 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { // test upsert statement with padding String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId), getUrl()); + String atableName = initATableValues(tenantId, getDefaultSplits(tenantId), getUrl()); upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT A_INTEGER, A_STRING, B_STRING FROM ATABLE WHERE a_string = ?"; + "SELECT A_INTEGER, A_STRING, B_STRING FROM " + atableName + " WHERE a_string = ?"; statement = conn.prepareStatement(upsert); statement.setString(1, A_VALUE); @@ -249,7 +251,7 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { try { upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT x_integer, organization_id, b_string FROM ATABLE WHERE a_string = ?"; + "SELECT x_integer, organization_id, b_string FROM " + atableName + " WHERE a_string = ?"; statement = conn.prepareStatement(upsert); statement.setString(1, A_VALUE); @@ -263,7 +265,7 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { try { upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT y_integer, a_string, entity_id FROM ATABLE WHERE a_string = ?"; + "SELECT y_integer, a_string, entity_id FROM " + atableName + " WHERE a_string = ?"; statement = conn.prepareStatement(upsert); statement.setString(1, A_VALUE); @@ -276,7 +278,7 @@ public class ExecuteStatementsIT extends BaseHBaseManagedTimeIT { //where selecting from a CHAR(x) and upserting into a CHAR(y) where x<=y. upsert = "UPSERT INTO " + tableName + "(a_id, a_string, b_string) " + - "SELECT a_integer, e_string, a_id FROM BTABLE"; + "SELECT a_integer, e_string, a_id FROM " + btableName ; statement = conn.prepareStatement(upsert); rowsInserted = statement.executeUpdate(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java index a723c6b..88bf763 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExpFunctionEnd2EndIT.java @@ -34,21 +34,26 @@ import org.junit.Test; /** * End to end tests for {@link ExpFunction} */ -public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeIT { +public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT { private static final String KEY = "key"; private static final double ZERO = 1e-8; + private String signedTableName; + private String unsignedTableName; @Before public void initTable() throws Exception { Connection conn = null; PreparedStatement stmt = null; + signedTableName = generateRandomString(); + unsignedTableName = generateRandomString(); + try { conn = DriverManager.getConnection(getUrl()); String ddl; - ddl = "CREATE TABLE testSigned (k VARCHAR NOT NULL PRIMARY KEY, doub DOUBLE, fl FLOAT, inte INTEGER, lon BIGINT, smalli SMALLINT, tinyi TINYINT)"; + ddl = "CREATE TABLE " + signedTableName + " (k VARCHAR NOT NULL PRIMARY KEY, doub DOUBLE, fl FLOAT, inte INTEGER, lon BIGINT, smalli SMALLINT, tinyi TINYINT)"; conn.createStatement().execute(ddl); - ddl = "CREATE TABLE testUnsigned (k VARCHAR NOT NULL PRIMARY KEY, doub UNSIGNED_DOUBLE, fl UNSIGNED_FLOAT, inte UNSIGNED_INT, lon UNSIGNED_LONG, smalli UNSIGNED_SMALLINT, tinyi UNSIGNED_TINYINT)"; + ddl = "CREATE TABLE " + unsignedTableName + " (k VARCHAR NOT NULL PRIMARY KEY, doub UNSIGNED_DOUBLE, fl UNSIGNED_FLOAT, inte UNSIGNED_INT, lon UNSIGNED_LONG, smalli UNSIGNED_SMALLINT, tinyi UNSIGNED_TINYINT)"; conn.createStatement().execute(ddl); conn.commit(); } finally { @@ -57,7 +62,8 @@ public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeIT { } private void updateSignedTable(Connection conn, double data) throws Exception { - PreparedStatement stmt = conn.prepareStatement("UPSERT INTO testSigned VALUES (?, ?, ?, ?, ?, ?, ?)"); + + PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + signedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); @@ -71,7 +77,7 @@ public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeIT { } private void updateUnsignedTable(Connection conn, double data) throws Exception { - PreparedStatement stmt = conn.prepareStatement("UPSERT INTO testUnsigned VALUES (?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + unsignedTableName + " VALUES (?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, KEY); Double d = Double.valueOf(data); stmt.setDouble(2, d.doubleValue()); @@ -86,7 +92,7 @@ public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeIT { private void testSignedNumberSpec(Connection conn, double data) throws Exception { updateSignedTable(conn, data); - ResultSet rs = conn.createStatement().executeQuery("SELECT EXP(doub),EXP(fl),EXP(inte),EXP(lon),EXP(smalli),EXP(tinyi) FROM testSigned"); + ResultSet rs = conn.createStatement().executeQuery("SELECT EXP(doub),EXP(fl),EXP(inte),EXP(lon),EXP(smalli),EXP(tinyi) FROM " + signedTableName); assertTrue(rs.next()); Double d = Double.valueOf(data); assertTrue(Math.abs(rs.getDouble(1) - Math.exp(d.doubleValue())) < ZERO); @@ -100,7 +106,7 @@ public class ExpFunctionEnd2EndIT extends BaseHBaseManagedTimeIT { private void testUnsignedNumberSpec(Connection conn, double data) throws Exception { updateUnsignedTable(conn, data); - ResultSet rs = conn.createStatement().executeQuery("SELECT EXP(doub),EXP(fl),EXP(inte),EXP(lon),EXP(smalli),EXP(tinyi) FROM testUnsigned"); + ResultSet rs = conn.createStatement().executeQuery("SELECT EXP(doub),EXP(fl),EXP(inte),EXP(lon),EXP(smalli),EXP(tinyi) FROM " + unsignedTableName); assertTrue(rs.next()); Double d = Double.valueOf(data); assertTrue(Math.abs(rs.getDouble(1) - Math.exp(d.doubleValue())) < ZERO); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExtendedQueryExecIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExtendedQueryExecIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExtendedQueryExecIT.java index 377f6d6..f5c1df2 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExtendedQueryExecIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExtendedQueryExecIT.java @@ -22,6 +22,7 @@ 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 static org.apache.phoenix.util.TestUtil.ATABLE_NAME; import java.sql.Connection; import java.sql.Date; @@ -51,7 +52,7 @@ public class ExtendedQueryExecIT extends BaseClientManagedTimeIT { Date date = new Date(1); String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId),date, ts); + initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId),date, ts, getUrl()); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1)); @@ -74,7 +75,8 @@ public class ExtendedQueryExecIT extends BaseClientManagedTimeIT { public void testTypeMismatchToDateFunctionBind() throws Exception { long ts = nextTimestamp(); String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId),null, ts); + initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId),null, ts, getUrl()); + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -101,8 +103,7 @@ public class ExtendedQueryExecIT extends BaseClientManagedTimeIT { Date date = new Date(1); String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId),date, ts); - + initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId),date, ts, getUrl()); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1)); Connection conn = DriverManager.getConnection(getUrl(), props); @@ -147,8 +148,7 @@ public class ExtendedQueryExecIT extends BaseClientManagedTimeIT { Date date = new Date(1); String tenantId = getOrganizationId(); - initATableValues(tenantId, getDefaultSplits(tenantId),date, ts); - + initATableValues(ATABLE_NAME, tenantId, getDefaultSplits(tenantId),date, ts, getUrl()); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+1)); Connection conn = DriverManager.getConnection(getUrl(), props); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/FunkyNamesIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/FunkyNamesIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/FunkyNamesIT.java index 11f91cd..26e13eb 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/FunkyNamesIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/FunkyNamesIT.java @@ -39,7 +39,7 @@ import org.junit.Test; public class FunkyNamesIT extends BaseClientManagedTimeIT { protected static void initTableValues(byte[][] splits, long ts) throws Exception { - ensureTableCreated(getUrl(),FUNKY_NAME,splits, ts-2); + ensureTableCreated(getUrl(), FUNKY_NAME, FUNKY_NAME,splits, 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/GroupByCaseIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java index b0524da..86a1f64 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java @@ -19,6 +19,7 @@ package org.apache.phoenix.end2end; import static org.apache.phoenix.util.TestUtil.GROUPBYTEST_NAME; import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES; +import static org.apache.phoenix.util.TestUtil.getTableName; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -40,41 +41,25 @@ import org.apache.phoenix.util.QueryUtil; import org.junit.Test; -public class GroupByCaseIT extends BaseHBaseManagedTimeIT { - - private static String GROUPBY1 = "select " + - "case when uri LIKE 'Report%' then 'Reports' else 'Other' END category" + - ", avg(appcpu) from " + GROUPBYTEST_NAME + - " group by category"; - - private static String GROUPBY2 = "select " + - "case uri when 'Report%' then 'Reports' else 'Other' END category" + - ", avg(appcpu) from " + GROUPBYTEST_NAME + - " group by appcpu, category"; - - private static String GROUPBY3 = "select " + - "case uri when 'Report%' then 'Reports' else 'Other' END category" + - ", avg(appcpu) from " + GROUPBYTEST_NAME + - " group by avg(appcpu), category"; - +public class GroupByCaseIT extends BaseHBaseManagedTimeTableReuseIT { private static int id; - private static void initData(Connection conn) throws SQLException { - ensureTableCreated(getUrl(), GROUPBYTEST_NAME); - insertRow(conn, "Report1", 10); - insertRow(conn, "Report2", 10); - insertRow(conn, "Report3", 30); - insertRow(conn, "Report4", 30); - insertRow(conn, "SOQL1", 10); - insertRow(conn, "SOQL2", 10); - insertRow(conn, "SOQL3", 30); - insertRow(conn, "SOQL4", 30); + private static void initData(Connection conn, String tableName) throws SQLException { + ensureTableCreated(getUrl(), tableName, GROUPBYTEST_NAME); + insertRow(conn, tableName, "Report1", 10); + insertRow(conn, tableName, "Report2", 10); + insertRow(conn, tableName, "Report3", 30); + insertRow(conn, tableName, "Report4", 30); + insertRow(conn, tableName, "SOQL1", 10); + insertRow(conn, tableName, "SOQL2", 10); + insertRow(conn, tableName, "SOQL3", 30); + insertRow(conn, tableName, "SOQL4", 30); conn.commit(); conn.close(); } - private static void insertRow(Connection conn, String uri, int appcpu) throws SQLException { - PreparedStatement statement = conn.prepareStatement("UPSERT INTO " + GROUPBYTEST_NAME + "(id, uri, appcpu) values (?,?,?)"); + private static void insertRow(Connection conn, String tableName, String uri, int appcpu) throws SQLException { + PreparedStatement statement = conn.prepareStatement("UPSERT INTO " + tableName + "(id, uri, appcpu) values (?,?,?)"); statement.setString(1, "id" + id); statement.setString(2, uri); statement.setInt(3, appcpu); @@ -86,13 +71,14 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testExpressionInGroupBy() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - String ddl = " create table tgb_counter(tgb_id integer NOT NULL,utc_date_epoch integer NOT NULL,tgb_name varchar(40),ack_success_count integer" + + String tableName = generateRandomString(); + String ddl = " create table " + tableName + "(tgb_id integer NOT NULL,utc_date_epoch integer NOT NULL,tgb_name varchar(40),ack_success_count integer" + ",ack_success_one_ack_count integer, CONSTRAINT pk_tgb_counter PRIMARY KEY(tgb_id, utc_date_epoch))"; String query = "SELECT tgb_id, tgb_name, (utc_date_epoch/10)*10 AS utc_epoch_hour,SUM(ack_success_count + ack_success_one_ack_count) AS ack_tx_sum" + - " FROM tgb_counter GROUP BY tgb_id, tgb_name, utc_epoch_hour"; + " FROM " + tableName + " GROUP BY tgb_id, tgb_name, utc_epoch_hour"; createTestTable(getUrl(), ddl); - String dml = "UPSERT INTO tgb_counter VALUES(?,?,?,?,?)"; + String dml = "UPSERT INTO " + tableName + " VALUES(?,?,?,?,?)"; PreparedStatement stmt = conn.prepareStatement(dml); stmt.setInt(1, 1); stmt.setInt(2, 1000); @@ -128,16 +114,17 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testBooleanInGroupBy() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - String ddl = " create table bool_gb(id varchar primary key,v1 boolean, v2 integer, v3 integer)"; + String tableName = generateRandomString(); + String ddl = " create table " + tableName + "(id varchar primary key,v1 boolean, v2 integer, v3 integer)"; createTestTable(getUrl(), ddl); - PreparedStatement stmt = conn.prepareStatement("UPSERT INTO bool_gb(id,v2,v3) VALUES(?,?,?)"); + PreparedStatement stmt = conn.prepareStatement("UPSERT INTO " + tableName + "(id,v2,v3) VALUES(?,?,?)"); stmt.setString(1, "a"); stmt.setInt(2, 1); stmt.setInt(3, 1); stmt.execute(); stmt.close(); - stmt = conn.prepareStatement("UPSERT INTO bool_gb VALUES(?,?,?,?)"); + stmt = conn.prepareStatement("UPSERT INTO " + tableName + " VALUES(?,?,?,?)"); stmt.setString(1, "b"); stmt.setBoolean(2, false); stmt.setInt(3, 2); @@ -152,7 +139,7 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { String[] gbs = {"v1,v2,v3","v1,v3,v2","v2,v1,v3"}; for (String gb : gbs) { - ResultSet rs = conn.createStatement().executeQuery("SELECT v1, v2, v3 from bool_gb group by " + gb); + ResultSet rs = conn.createStatement().executeQuery("SELECT v1, v2, v3 from " + tableName + " group by " + gb); assertTrue(rs.next()); assertEquals(false,rs.getBoolean("v1")); assertTrue(rs.wasNull()); @@ -177,9 +164,10 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testScanUri() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - initData(conn); + String tableName = generateRandomString(); + initData(conn, tableName); Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("select uri from " + GROUPBYTEST_NAME); + ResultSet rs = stmt.executeQuery("select uri from " + tableName); assertTrue(rs.next()); assertEquals("Report1", rs.getString(1)); assertTrue(rs.next()); @@ -204,9 +192,10 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testCount() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - initData(conn); + String tableName = generateRandomString(); + initData(conn, tableName); Statement stmt = conn.createStatement(); - ResultSet rs = stmt.executeQuery("select count(1) from " + GROUPBYTEST_NAME); + ResultSet rs = stmt.executeQuery("select count(1) from " + tableName); assertTrue(rs.next()); assertEquals(8, rs.getInt(1)); assertFalse(rs.next()); @@ -217,12 +206,27 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testGroupByCase() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - initData(conn); - conn.createStatement().executeQuery(GROUPBY1); - conn.createStatement().executeQuery(GROUPBY2); + String tableName = generateRandomString(); + String groupBy1 = "select " + + "case when uri LIKE 'Report%' then 'Reports' else 'Other' END category" + + ", avg(appcpu) from " + tableName + + " group by category"; + + String groupBy2 = "select " + + "case uri when 'Report%' then 'Reports' else 'Other' END category" + + ", avg(appcpu) from " + tableName + + " group by appcpu, category"; + + String groupBy3 = "select " + + "case uri when 'Report%' then 'Reports' else 'Other' END category" + + ", avg(appcpu) from " + tableName + + " group by avg(appcpu), category"; + initData(conn, tableName); + conn.createStatement().executeQuery(groupBy1); + conn.createStatement().executeQuery(groupBy2); // TODO: validate query results try { - conn.createStatement().executeQuery(GROUPBY3); + conn.createStatement().executeQuery(groupBy3); fail(); } catch (SQLException e) { assertTrue(e.getMessage().contains("Aggregate expressions may not be used in GROUP BY")); @@ -235,7 +239,9 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testGroupByArray() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE test1(\n" + + + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + "(\n" + " a VARCHAR NOT NULL,\n" + " b VARCHAR,\n" + " c INTEGER,\n" + @@ -245,13 +251,13 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { " g BIGINT,\n" + " CONSTRAINT pk PRIMARY KEY(a)\n" + ")"); - conn.createStatement().execute("UPSERT INTO test1 VALUES('1', 'val', 100, 'a', ARRAY ['b'], 1, 2)"); - conn.createStatement().execute("UPSERT INTO test1 VALUES('2', 'val', 100, 'a', ARRAY ['b'], 3, 4)"); - conn.createStatement().execute("UPSERT INTO test1 VALUES('3', 'val', 100, 'a', ARRAY ['b','c'], 5, 6)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('1', 'val', 100, 'a', ARRAY ['b'], 1, 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('2', 'val', 100, 'a', ARRAY ['b'], 3, 4)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('3', 'val', 100, 'a', ARRAY ['b','c'], 5, 6)"); conn.commit(); ResultSet rs = conn.createStatement().executeQuery("SELECT c, SUM(f + g) AS sumone, d, e\n" + - "FROM test1\n" + + "FROM " + tableName + "\n" + "WHERE b = 'val'\n" + " AND a IN ('1','2','3')\n" + "GROUP BY c, d, e\n" + @@ -270,7 +276,9 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testGroupByOrderPreserving() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE T (ORGANIZATION_ID char(15) not null, \n" + + String tableName = generateRandomString(); + + conn.createStatement().execute("CREATE TABLE " + tableName + "(ORGANIZATION_ID char(15) not null, \n" + "JOURNEY_ID char(15) not null, \n" + "DATASOURCE SMALLINT not null, \n" + "MATCH_STATUS TINYINT not null, \n" + @@ -283,13 +291,13 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { " MATCH_STATUS,\n" + " EXTERNAL_DATASOURCE_KEY,\n" + " ENTITY_ID))"); - conn.createStatement().execute("UPSERT INTO T VALUES('000001111122222', '333334444455555', 0, 0, 'abc', '666667777788888')"); - conn.createStatement().execute("UPSERT INTO T VALUES('000001111122222', '333334444455555', 0, 0, 'abcd', '666667777788889')"); - conn.createStatement().execute("UPSERT INTO T VALUES('000001111122222', '333334444455555', 0, 0, 'abc', '666667777788899')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('000001111122222', '333334444455555', 0, 0, 'abc', '666667777788888')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('000001111122222', '333334444455555', 0, 0, 'abcd', '666667777788889')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('000001111122222', '333334444455555', 0, 0, 'abc', '666667777788899')"); conn.commit(); String query = "SELECT COUNT(1), EXTERNAL_DATASOURCE_KEY As DUP_COUNT\n" + - " FROM T \n" + + " FROM " + tableName + " \n" + " WHERE JOURNEY_ID='333334444455555' AND \n" + " DATASOURCE=0 AND MATCH_STATUS <= 1 and \n" + " ORGANIZATION_ID='000001111122222' \n" + @@ -303,7 +311,7 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { rs = conn.createStatement().executeQuery("EXPLAIN " + query); assertEquals( - "CLIENT PARALLEL 1-WAY RANGE SCAN OVER T ['000001111122222','333334444455555',0,*] - ['000001111122222','333334444455555',0,1]\n" + + "CLIENT PARALLEL 1-WAY RANGE SCAN OVER " + tableName + " ['000001111122222','333334444455555',0,*] - ['000001111122222','333334444455555',0,1]\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY [MATCH_STATUS, EXTERNAL_DATASOURCE_KEY]\n" + "CLIENT FILTER BY COUNT(1) > 1",QueryUtil.getExplainPlan(rs)); @@ -313,21 +321,22 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testGroupByOrderPreservingDescSort() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE GROUP_BY_DESC (k1 char(1) not null, k2 char(1) not null, constraint pk primary key (k1,k2)) split on ('ac','jc','nc')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 'a')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 'b')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 'c')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 'd')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 'a')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 'b')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 'c')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 'd')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 'a')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 'b')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 'c')"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 'd')"); + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + " (k1 char(1) not null, k2 char(1) not null, constraint pk primary key (k1,k2)) split on ('ac','jc','nc')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 'a')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 'b')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 'c')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 'd')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 'a')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 'b')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 'c')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 'd')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 'a')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 'b')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 'c')"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 'd')"); conn.commit(); - String query = "SELECT k1,count(*) FROM GROUP_BY_DESC GROUP BY k1 ORDER BY k1 DESC"; + String query = "SELECT k1,count(*) FROM " + tableName + " GROUP BY k1 ORDER BY k1 DESC"; ResultSet rs = conn.createStatement().executeQuery(query); assertTrue(rs.next()); assertEquals("n", rs.getString(1)); @@ -341,7 +350,7 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); assertEquals( - "CLIENT PARALLEL 1-WAY REVERSE FULL SCAN OVER GROUP_BY_DESC\n" + + "CLIENT PARALLEL 1-WAY REVERSE FULL SCAN OVER " + tableName + "\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY [K1]", QueryUtil.getExplainPlan(rs)); } @@ -350,26 +359,28 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testSumGroupByOrderPreservingDesc() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - PreparedStatement stmt = conn.prepareStatement("CREATE TABLE GROUP_BY_DESC (k1 char(1) not null, k2 integer not null, constraint pk primary key (k1,k2)) split on (?,?,?)"); + String tableName = generateRandomString(); + + PreparedStatement stmt = conn.prepareStatement("CREATE TABLE " + tableName + " (k1 char(1) not null, k2 integer not null, constraint pk primary key (k1,k2)) split on (?,?,?)"); stmt.setBytes(1, ByteUtil.concat(PChar.INSTANCE.toBytes("a"), PInteger.INSTANCE.toBytes(3))); stmt.setBytes(2, ByteUtil.concat(PChar.INSTANCE.toBytes("j"), PInteger.INSTANCE.toBytes(3))); stmt.setBytes(3, ByteUtil.concat(PChar.INSTANCE.toBytes("n"), PInteger.INSTANCE.toBytes(3))); stmt.execute(); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 1)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 2)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 3)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 4)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('b', 5)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 1)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 2)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 3)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 4)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 1)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 2)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 3)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 4)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 3)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 4)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('b', 5)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 3)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 4)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 3)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 4)"); conn.commit(); - String query = "SELECT k1,sum(k2) FROM GROUP_BY_DESC GROUP BY k1 ORDER BY k1 DESC"; + String query = "SELECT k1,sum(k2) FROM " + tableName + " GROUP BY k1 ORDER BY k1 DESC"; ResultSet rs = conn.createStatement().executeQuery(query); assertTrue(rs.next()); assertEquals("n", rs.getString(1)); @@ -386,7 +397,7 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); assertEquals( - "CLIENT PARALLEL 1-WAY REVERSE FULL SCAN OVER GROUP_BY_DESC\n" + + "CLIENT PARALLEL 1-WAY REVERSE FULL SCAN OVER " + tableName + "\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY [K1]", QueryUtil.getExplainPlan(rs)); } @@ -395,26 +406,28 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { public void testAvgGroupByOrderPreserving() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - PreparedStatement stmt = conn.prepareStatement("CREATE TABLE GROUP_BY_DESC (k1 char(1) not null, k2 integer not null, constraint pk primary key (k1,k2)) split on (?,?,?)"); + String tableName = generateRandomString(); + + PreparedStatement stmt = conn.prepareStatement("CREATE TABLE " + tableName + " (k1 char(1) not null, k2 integer not null, constraint pk primary key (k1,k2)) split on (?,?,?)"); stmt.setBytes(1, ByteUtil.concat(PChar.INSTANCE.toBytes("a"), PInteger.INSTANCE.toBytes(3))); stmt.setBytes(2, ByteUtil.concat(PChar.INSTANCE.toBytes("j"), PInteger.INSTANCE.toBytes(3))); stmt.setBytes(3, ByteUtil.concat(PChar.INSTANCE.toBytes("n"), PInteger.INSTANCE.toBytes(3))); stmt.execute(); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 1)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 2)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 3)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('a', 6)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('b', 5)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 1)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 2)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 3)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('j', 10)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 1)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 2)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 3)"); - conn.createStatement().execute("UPSERT INTO GROUP_BY_DESC VALUES('n', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 3)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('a', 6)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('b', 5)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 3)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('j', 10)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 1)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 2)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 3)"); + conn.createStatement().execute("UPSERT INTO " + tableName + " VALUES('n', 2)"); conn.commit(); - String query = "SELECT k1,avg(k2) FROM GROUP_BY_DESC GROUP BY k1"; + String query = "SELECT k1,avg(k2) FROM " + tableName + " GROUP BY k1"; ResultSet rs = conn.createStatement().executeQuery(query); assertTrue(rs.next()); assertEquals("a", rs.getString(1)); @@ -431,7 +444,7 @@ public class GroupByCaseIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); assertEquals( - "CLIENT PARALLEL 1-WAY FULL SCAN OVER GROUP_BY_DESC\n" + + "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName + "\n" + " SERVER FILTER BY FIRST KEY ONLY\n" + " SERVER AGGREGATE INTO ORDERED DISTINCT ROWS BY [K1]", QueryUtil.getExplainPlan(rs)); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java index c27db6b..943a376 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinMoreIT.java @@ -43,7 +43,7 @@ import org.junit.Test; import com.google.common.collect.Maps; -public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { +public class HashJoinMoreIT extends BaseHBaseManagedTimeTableReuseIT { private final String[] plans = new String[] { /* * testJoinWithKeyRangeOptimization() @@ -51,10 +51,10 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { * FROM TEMP_TABLE_COMPOSITE_PK lhs * JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col1 = rhs.col2 */ - "CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + "CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + "CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + - " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + " CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + " CLIENT MERGE SORT", /* * testJoinWithKeyRangeOptimization() @@ -62,10 +62,10 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { * FROM TEMP_TABLE_COMPOSITE_PK lhs * JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col2 */ - "CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + "CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + "CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + - " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + " CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + " CLIENT MERGE SORT\n" + " DYNAMIC SERVER FILTER BY LHS.COL0 IN (RHS.COL2)", /* @@ -74,10 +74,10 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { * FROM TEMP_TABLE_COMPOSITE_PK lhs * JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col1 = rhs.col2 */ - "CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + "CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + "CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + - " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + " CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + " CLIENT MERGE SORT\n" + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1) IN ((RHS.COL1, RHS.COL2))", /* @@ -86,16 +86,16 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { * FROM TEMP_TABLE_COMPOSITE_PK lhs * JOIN TEMP_TABLE_COMPOSITE_PK rhs ON lhs.col0 = rhs.col1 AND lhs.col2 = rhs.col3 - 1 AND lhs.col1 = rhs.col2 */ - "CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + "CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + "CLIENT MERGE SORT\n" + " PARALLEL INNER-JOIN TABLE 0\n" + - " CLIENT PARALLEL 4-WAY FULL SCAN OVER TEMP_TABLE_COMPOSITE_PK\n" + + " CLIENT PARALLEL 4-WAY FULL SCAN OVER %s\n" + " CLIENT MERGE SORT\n" + " DYNAMIC SERVER FILTER BY (LHS.COL0, LHS.COL1, LHS.COL2) IN ((RHS.COL1, RHS.COL2, TO_INTEGER((RHS.COL3 - 1))))", }; @BeforeClass - @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) + @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class) public static void doSetup() throws Exception { Map<String,String> props = Maps.newHashMapWithExpectedSize(3); // Forces server cache to be used @@ -117,8 +117,8 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { @Test public void testJoinOverSaltedTables() throws Exception { - String tempTableNoSalting = "TEMP_TABLE_NO_SALTING"; - String tempTableWithSalting = "TEMP_TABLE_WITH_SALTING"; + String tempTableNoSalting = generateRandomString(); + String tempTableWithSalting = generateRandomString(); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -255,8 +255,8 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { @Test public void testJoinOnDynamicColumns() throws Exception { - String tableA = "tableA"; - String tableB = "tableB"; + String tableA = generateRandomString(); + String tableB = generateRandomString(); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = null; PreparedStatement stmt = null; @@ -274,7 +274,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { stmt.execute(); stmt.close(); - String upsertA = "UPSERT INTO TABLEA (pkA, colA1, colA2) VALUES(?, ?, ?)"; + String upsertA = "UPSERT INTO " + tableA + " (pkA, colA1, colA2) VALUES(?, ?, ?)"; stmt = conn.prepareStatement(upsertA); int i = 0; for (i = 0; i < 5; i++) { @@ -286,19 +286,20 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { conn.commit(); stmt.close(); + String sequenceB = generateRandomString(); // upsert select dynamic columns in tableB - conn.createStatement().execute("CREATE SEQUENCE SEQB"); - String upsertBSelectA = "UPSERT INTO TABLEB (pkB, pkA INTEGER)" - + "SELECT NEXT VALUE FOR SEQB, pkA FROM TABLEA"; + conn.createStatement().execute("CREATE SEQUENCE " + sequenceB ); + String upsertBSelectA = "UPSERT INTO " + tableB + " (pkB, pkA INTEGER)" + + "SELECT NEXT VALUE FOR " + sequenceB + ", pkA FROM " + tableA ; stmt = conn.prepareStatement(upsertBSelectA); stmt.executeUpdate(); stmt.close(); conn.commit(); - conn.createStatement().execute("DROP SEQUENCE SEQB"); + conn.createStatement().execute("DROP SEQUENCE " + sequenceB ); // perform a join between tableB and tableA by joining on the dynamic column that we upserted in // tableB. This join should return all the rows from table A. - String joinSql = "SELECT A.pkA, A.COLA1, A.colA2 FROM TABLEB B(pkA INTEGER) JOIN TABLEA A ON a.pkA = b.pkA"; + String joinSql = "SELECT A.pkA, A.COLA1, A.colA2 FROM " + tableB + " B(pkA INTEGER) JOIN " + tableA + " A ON a.pkA = b.pkA"; stmt = conn.prepareStatement(joinSql); ResultSet rs = stmt.executeQuery(); i = 0; @@ -324,7 +325,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { @Test public void testJoinWithKeyRangeOptimization() throws Exception { - String tempTableWithCompositePK = "TEMP_TABLE_COMPOSITE_PK"; + String tempTableWithCompositePK = generateRandomString(); Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -375,7 +376,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); - assertEquals(plans[0], QueryUtil.getExplainPlan(rs)); + assertEquals(String.format(plans[0],tempTableWithCompositePK,tempTableWithCompositePK), QueryUtil.getExplainPlan(rs)); // Two parts of PK but only one leading part query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " @@ -396,7 +397,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); - assertEquals(plans[1], QueryUtil.getExplainPlan(rs)); + assertEquals(String.format(plans[1],tempTableWithCompositePK,tempTableWithCompositePK), QueryUtil.getExplainPlan(rs)); // Two leading parts of PK query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " @@ -426,7 +427,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); - assertEquals(plans[2], QueryUtil.getExplainPlan(rs)); + assertEquals(String.format(plans[2],tempTableWithCompositePK,tempTableWithCompositePK), QueryUtil.getExplainPlan(rs)); // All parts of PK query = "SELECT lhs.col0, lhs.col1, lhs.col2, lhs.col3, rhs.col0, rhs.col1, rhs.col2, rhs.col3 FROM " @@ -456,7 +457,7 @@ public class HashJoinMoreIT extends BaseHBaseManagedTimeIT { assertFalse(rs.next()); rs = conn.createStatement().executeQuery("EXPLAIN " + query); - assertEquals(plans[3], QueryUtil.getExplainPlan(rs)); + assertEquals(String.format(plans[3],tempTableWithCompositePK,tempTableWithCompositePK), QueryUtil.getExplainPlan(rs)); } finally { conn.close(); } http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java index 4aff12b..0038c3a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InListIT.java @@ -45,23 +45,24 @@ import com.google.common.base.Joiner; import com.google.common.collect.Lists; -public class InListIT extends BaseHBaseManagedTimeIT { +public class InListIT extends BaseHBaseManagedTimeTableReuseIT { @Test public void testLeadingPKWithTrailingRVC() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE in_test " + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + "( col1 VARCHAR NOT NULL," + " col2 VARCHAR NOT NULL, " + " id VARCHAR NOT NULL," + " CONSTRAINT pk PRIMARY KEY (col1, col2, id))"); - conn.createStatement().execute("upsert into in_test (col1, col2, id) values ('a', 'b', 'c')"); - conn.createStatement().execute("upsert into in_test (col1, col2, id) values ('a', 'b', 'd')"); + conn.createStatement().execute("upsert into " + tableName + " (col1, col2, id) values ('a', 'b', 'c')"); + conn.createStatement().execute("upsert into " + tableName + " (col1, col2, id) values ('a', 'b', 'd')"); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("select id from in_test WHERE col1 = 'a' and ((col2, id) IN (('b', 'c'),('b', 'e')))"); + ResultSet rs = conn.createStatement().executeQuery("select id from " + tableName + " WHERE col1 = 'a' and ((col2, id) IN (('b', 'c'),('b', 'e')))"); assertTrue(rs.next()); assertEquals("c", rs.getString(1)); assertFalse(rs.next()); @@ -73,13 +74,14 @@ public class InListIT extends BaseHBaseManagedTimeIT { public void testLeadingPKWithTrailingRVC2() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE in_test ( user VARCHAR, tenant_id VARCHAR(5) NOT NULL,tenant_type_id VARCHAR(3) NOT NULL, id INTEGER NOT NULL CONSTRAINT pk PRIMARY KEY (tenant_id, tenant_type_id, id))"); + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + " ( user VARCHAR, tenant_id VARCHAR(5) NOT NULL,tenant_type_id VARCHAR(3) NOT NULL, id INTEGER NOT NULL CONSTRAINT pk PRIMARY KEY (tenant_id, tenant_type_id, id))"); - conn.createStatement().execute("upsert into in_test (tenant_id, tenant_type_id, id, user) values ('a', 'a', 1, 'BonA')"); - conn.createStatement().execute("upsert into in_test (tenant_id, tenant_type_id, id, user) values ('a', 'a', 2, 'BonB')"); + conn.createStatement().execute("upsert into " + tableName + " (tenant_id, tenant_type_id, id, user) values ('a', 'a', 1, 'BonA')"); + conn.createStatement().execute("upsert into " + tableName + " (tenant_id, tenant_type_id, id, user) values ('a', 'a', 2, 'BonB')"); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("select id from in_test WHERE tenant_id = 'a' and tenant_type_id = 'a' and ((id, user) IN ((1, 'BonA'),(1, 'BonB')))"); + ResultSet rs = conn.createStatement().executeQuery("select id from " + tableName + " WHERE tenant_id = 'a' and tenant_type_id = 'a' and ((id, user) IN ((1, 'BonA'),(1, 'BonB')))"); assertTrue(rs.next()); assertEquals(1, rs.getInt(1)); assertFalse(rs.next()); @@ -142,8 +144,7 @@ public class InListIT extends BaseHBaseManagedTimeIT { * @return the table or view name that should be used to access the created table */ private static String initializeAndGetTable(Connection baseConn, Connection conn, boolean isMultiTenant, PDataType pkType, int saltBuckets) throws SQLException { - String tableName = "in_test" + pkType.getSqlTypeName() + saltBuckets + (isMultiTenant ? "_multi" : "_single"); - + String tableName = generateRandomString() + "in_test" + pkType.getSqlTypeName() + saltBuckets + (isMultiTenant ? "_multi" : "_single"); String tableDDL = createTableDDL(tableName, pkType, saltBuckets, isMultiTenant); baseConn.createStatement().execute(tableDDL); @@ -444,13 +445,14 @@ public class InListIT extends BaseHBaseManagedTimeIT { public void testWithFixedLengthKV() throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE in_test ( id INTEGER PRIMARY KEY, k CHAR(3))"); + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + " ( id INTEGER PRIMARY KEY, k CHAR(3))"); - conn.createStatement().execute("upsert into in_test values (1, 'aa')"); - conn.createStatement().execute("upsert into in_test values (2, 'bb')"); + conn.createStatement().execute("upsert into " + tableName + " values (1, 'aa')"); + conn.createStatement().execute("upsert into " + tableName + " values (2, 'bb')"); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("select k from in_test WHERE k IN ('aa','bb')"); + ResultSet rs = conn.createStatement().executeQuery("select k from " + tableName + " WHERE k IN ('aa','bb')"); assertTrue(rs.next()); assertEquals("aa", rs.getString(1)); assertTrue(rs.next()); @@ -463,13 +465,14 @@ public class InListIT extends BaseHBaseManagedTimeIT { private void testWithFixedLengthPK(SortOrder sortOrder) throws Exception { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); - conn.createStatement().execute("CREATE TABLE in_test ( k CHAR(3) PRIMARY KEY " + (sortOrder == SortOrder.DESC ? "DESC" : "") + ")"); + String tableName = generateRandomString(); + conn.createStatement().execute("CREATE TABLE " + tableName + " ( k CHAR(3) PRIMARY KEY " + (sortOrder == SortOrder.DESC ? "DESC" : "") + ")"); - conn.createStatement().execute("upsert into in_test (k) values ('aa')"); - conn.createStatement().execute("upsert into in_test (k) values ('bb')"); + conn.createStatement().execute("upsert into " + tableName + " (k) values ('aa')"); + conn.createStatement().execute("upsert into " + tableName + " (k) values ('bb')"); conn.commit(); - ResultSet rs = conn.createStatement().executeQuery("select k from in_test WHERE k IN ('aa','bb')"); + ResultSet rs = conn.createStatement().executeQuery("select k from " + tableName + " WHERE k IN ('aa','bb')"); assertTrue(rs.next()); assertEquals(sortOrder == SortOrder.ASC ? "aa" : "bb", rs.getString(1)); assertTrue(rs.next()); http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77d2492/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java index 232f76f..c6bfe9a 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/InMemoryOrderByIT.java @@ -32,7 +32,7 @@ public class InMemoryOrderByIT extends OrderByIT { } @BeforeClass - @Shadower(classBeingShadowed = BaseHBaseManagedTimeIT.class) + @Shadower(classBeingShadowed = BaseHBaseManagedTimeTableReuseIT.class) public static void doSetup() throws Exception { Map<String,String> props = Maps.newHashMapWithExpectedSize(1); props.put(QueryServices.SPOOL_THRESHOLD_BYTES_ATTRIB, Integer.toString(1024*1024));
