PHOENIX-4185 Rewrite tests to disable DDL and DML for PercentileIT.java and ProductMetricsIT.java (Ethan Wang)
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cd203d1d Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cd203d1d Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cd203d1d Branch: refs/heads/4.x-HBase-1.1 Commit: cd203d1d55dd4b76781127d3b37e7c6a5035ec06 Parents: ca8bd4a Author: James Taylor <jamestay...@apache.org> Authored: Tue Sep 12 17:04:18 2017 -0700 Committer: James Taylor <jamestay...@apache.org> Committed: Tue Sep 12 17:09:00 2017 -0700 ---------------------------------------------------------------------- .gitignore | 2 + .../apache/phoenix/end2end/PercentileIT.java | 145 ++- .../phoenix/end2end/ProductMetricsIT.java | 947 +++++++++---------- 3 files changed, 512 insertions(+), 582 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/cd203d1d/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 803e8ea..33d40ea 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ # intellij stuff .idea/ *.iml +*.ipr +*.iws #maven stuffs target/ http://git-wip-us.apache.org/repos/asf/phoenix/blob/cd203d1d/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java index 2d0ead9..965fc2c 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/PercentileIT.java @@ -46,7 +46,6 @@ import java.sql.Date; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; -import java.sql.ResultSetMetaData; import java.sql.Statement; import java.sql.SQLException; import java.sql.Types; @@ -54,7 +53,6 @@ import java.util.Properties; import org.apache.phoenix.query.QueryConstants; import org.apache.phoenix.util.DateUtil; -import org.apache.phoenix.util.PhoenixRuntime; import org.apache.phoenix.util.PropertiesUtil; import org.apache.phoenix.util.TestUtil; import org.junit.Test; @@ -65,10 +63,9 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentile() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName; - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); Connection conn = DriverManager.getConnection(getUrl(), props); try { @@ -87,7 +84,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentileDesc() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM " + tableName; @@ -105,11 +102,11 @@ public class PercentileIT extends ParallelStatsDisabledIT { conn.close(); } } - + @Test public void testPercentileWithGroupby() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName + " GROUP BY A_STRING"; @@ -142,7 +139,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentileWithGroupbyAndOrderBy() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT A_STRING, PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) AS PC FROM " + tableName + " GROUP BY A_STRING ORDER BY PC"; @@ -173,51 +170,51 @@ public class PercentileIT extends ParallelStatsDisabledIT { } @Test - public void testPercentileDiscAsc() throws Exception { - String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); - - String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName; - - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - assertTrue(rs.next()); - int percentile_disc = rs.getInt(1); - assertEquals(9, percentile_disc); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - - @Test - public void testPercentileDiscDesc() throws Exception { - String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); - - String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM " + tableName; - - Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); - Connection conn = DriverManager.getConnection(getUrl(), props); - try { - PreparedStatement statement = conn.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - assertTrue(rs.next()); - int percentile_disc = rs.getInt(1); - assertEquals(1, percentile_disc); - assertFalse(rs.next()); - } finally { - conn.close(); - } - } - + public void testPercentileDiscAsc() throws Exception { + String tenantId = getOrganizationId(); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); + + String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName; + + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + int percentile_disc = rs.getInt(1); + assertEquals(9, percentile_disc); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + + @Test + public void testPercentileDiscDesc() throws Exception { + String tenantId = getOrganizationId(); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); + + String query = "SELECT PERCENTILE_DISC(0.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM " + tableName; + + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + Connection conn = DriverManager.getConnection(getUrl(), props); + try { + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + int percentile_disc = rs.getInt(1); + assertEquals(1, percentile_disc); + assertFalse(rs.next()); + } finally { + conn.close(); + } + } + @Test public void testPercentileDiscWithGroupby() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT A_STRING, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName + " GROUP BY A_STRING"; @@ -247,7 +244,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentileDiscWithGroupbyAndOrderBy() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT A_STRING, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName + " GROUP BY A_STRING ORDER BY A_STRING DESC"; @@ -277,7 +274,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentRank() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK(5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName; @@ -299,7 +296,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentRankWithNegativeNumeric() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK(-2) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " + tableName; @@ -321,7 +318,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentRankDesc() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM " + tableName; @@ -343,7 +340,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentRankDescOnVARCHARColumn() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK('ba') WITHIN GROUP (ORDER BY A_STRING DESC) FROM " + tableName; @@ -365,7 +362,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testPercentRankDescOnDECIMALColumn() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC) FROM " + tableName; @@ -387,7 +384,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { @Test public void testMultiplePercentRanksOnSelect() throws Exception { String tenantId = getOrganizationId(); - String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null, null); + String tableName = initATableValues(tenantId, null, getDefaultSplits(tenantId), null); String query = "SELECT PERCENT_RANK(2) WITHIN GROUP (ORDER BY x_decimal ASC), PERCENT_RANK(8.9) WITHIN GROUP (ORDER BY A_INTEGER DESC) FROM " + tableName; @@ -482,13 +479,13 @@ public class PercentileIT extends ParallelStatsDisabledIT { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); try (Connection conn = DriverManager.getConnection(getUrl(), props); - Statement stmt = conn.createStatement()) { + Statement stmt = conn.createStatement()) { // Remove all the records in the table assertFalse(stmt.execute("DELETE FROM " + tableName)); // Execute a query with PERCENTILE_CONT against the empty table String query = "SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY A_INTEGER ASC) FROM " - + tableName; + + tableName; ResultSet rs = stmt.executeQuery(query); assertNotNull(rs); assertTrue(rs.next()); @@ -504,7 +501,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { Date date = DateUtil.parseDate("2015-01-01 00:00:00"); try { String upsert = "UPSERT INTO " + INDEX_DATA_SCHEMA + QueryConstants.NAME_SEPARATOR + indexDataTableName - + " VALUES(?, ?, ?, ?, ?, ?)"; + + " VALUES(?, ?, ?, ?, ?, ?)"; PreparedStatement stmt = conn.prepareStatement(upsert); stmt.setString(1, "varchar1"); stmt.setString(2, "char1"); @@ -513,7 +510,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { stmt.setBigDecimal(5, new BigDecimal(1.0)); stmt.setDate(6, date); stmt.executeUpdate(); - + stmt.setString(1, "varchar2"); stmt.setString(2, "char2"); stmt.setInt(3, 2); @@ -521,7 +518,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { stmt.setBigDecimal(5, new BigDecimal(2.0)); stmt.setDate(6, date); stmt.executeUpdate(); - + stmt.setString(1, "varchar3"); stmt.setString(2, "char3"); stmt.setInt(3, 3); @@ -529,7 +526,7 @@ public class PercentileIT extends ParallelStatsDisabledIT { stmt.setBigDecimal(5, new BigDecimal(3.0)); stmt.setDate(6, date); stmt.executeUpdate(); - + conn.commit(); } finally { conn.close(); @@ -537,26 +534,18 @@ public class PercentileIT extends ParallelStatsDisabledIT { } private static String initATableValues(String tenantId1, String tenantId2, byte[][] splits, - Date date, Long ts) throws Exception { + Date date) throws Exception { String tableName = generateUniqueName(); - if (ts == null) { - ensureTableCreated(getUrl(), tableName, ATABLE_NAME, splits, null); - } else { - ensureTableCreated(getUrl(), tableName, ATABLE_NAME, splits, ts - 2, null); - } + ensureTableCreated(getUrl(), tableName, ATABLE_NAME, splits, null, null); - Properties props = new Properties(); - if (ts != null) { - props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, ts.toString()); - } - Connection conn = DriverManager.getConnection(getUrl(), props); + Connection conn = DriverManager.getConnection(getUrl()); try { // Insert all rows at ts PreparedStatement stmt = conn.prepareStatement("upsert into " + tableName + "(" - + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_STRING, " - + " B_STRING, " + " A_INTEGER, " + " A_DATE, " + " X_DECIMAL, " - + " X_LONG, " + " X_INTEGER," + " Y_INTEGER)" - + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + + " ORGANIZATION_ID, " + " ENTITY_ID, " + " A_STRING, " + + " B_STRING, " + " A_INTEGER, " + " A_DATE, " + " X_DECIMAL, " + + " X_LONG, " + " X_INTEGER," + " Y_INTEGER)" + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); if (tenantId1 != null) { stmt.setString(1, tenantId1); stmt.setString(2, ROW1);