You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2016/09/17 07:06:59 UTC
[1/6] phoenix git commit: PHOENIX-3290 Move and/or combine as many
NeedsOwnCluster tests to bring down test run time
Repository: phoenix
Updated Branches:
refs/heads/master 4c8bda151 -> 14d16c853
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
deleted file mode 100644
index 4f0da4d..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/IndexOnOwnClusterIT.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end.index;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.HRegionInfo;
-import org.apache.hadoop.hbase.MetaTableAccessor;
-import org.apache.hadoop.hbase.TableName;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
-import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.end2end.BaseOwnClusterHBaseManagedTimeIT;
-import org.apache.phoenix.end2end.IndexToolIT;
-import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.ByteUtil;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.SchemaUtil;
-import org.apache.phoenix.util.TestUtil;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class IndexOnOwnClusterIT extends BaseOwnClusterHBaseManagedTimeIT {
-
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
- serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB,
- QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
- setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()),
- ReadOnlyProps.EMPTY_PROPS);
- }
-
- @Test
- public void testDeleteFromImmutable() throws Exception {
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
- conn.createStatement().execute("CREATE TABLE TEST_TABLE (\n" +
- " pk1 VARCHAR NOT NULL,\n" +
- " pk2 VARCHAR NOT NULL,\n" +
- " pk3 VARCHAR\n" +
- " CONSTRAINT PK PRIMARY KEY \n" +
- " (\n" +
- " pk1,\n" +
- " pk2,\n" +
- " pk3\n" +
- " )\n" +
- " ) IMMUTABLE_ROWS=true");
- conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '1', '1')");
- conn.createStatement().execute("upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '2', '2')");
- conn.commit();
- conn.createStatement().execute("CREATE INDEX TEST_INDEX ON TEST_TABLE (pk3, pk2) ASYNC");
-
- // this delete will be issued at a timestamp later than the above timestamp of the index table
- conn.createStatement().execute("delete from TEST_TABLE where pk1 = 'a'");
- conn.commit();
-
- // run the index MR job
- final IndexTool indexingTool = new IndexTool();
- indexingTool.setConf(new Configuration(getUtility().getConfiguration()));
- final String[] cmdArgs =
- IndexToolIT.getArgValues(null, "TEST_TABLE", "TEST_INDEX", true);
- int status = indexingTool.run(cmdArgs);
- assertEquals(0, status);
-
- // upsert two more rows
- conn.createStatement().execute(
- "upsert into TEST_TABLE (pk1, pk2, pk3) values ('a', '3', '3')");
- conn.createStatement().execute(
- "upsert into TEST_TABLE (pk1, pk2, pk3) values ('b', '4', '4')");
- conn.commit();
-
- // validate that delete markers were issued correctly and only ('a', '1', 'value1') was
- // deleted
- String query = "SELECT pk3 from TEST_TABLE ORDER BY pk3";
- ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
- String expectedPlan =
- "CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_INDEX\n"
- + " SERVER FILTER BY FIRST KEY ONLY";
- assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
- rs = conn.createStatement().executeQuery(query);
- assertTrue(rs.next());
- assertEquals("2", rs.getString(1));
- assertTrue(rs.next());
- assertEquals("3", rs.getString(1));
- assertTrue(rs.next());
- assertEquals("4", rs.getString(1));
- assertFalse(rs.next());
- }
- }
-
- private Connection getConnection() throws SQLException{
- Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
- props.put(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB,
- Boolean.FALSE.toString());
- props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB,
- Boolean.FALSE.toString());
- props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB,
- Boolean.TRUE.toString());
- return DriverManager.getConnection(getUrl(),props);
- }
-
- private void createBaseTable(String tableName, String splits) throws SQLException {
- Connection conn = getConnection();
- String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
- "k1 INTEGER NOT NULL,\n" +
- "k2 INTEGER NOT NULL,\n" +
- "k3 INTEGER,\n" +
- "v1 VARCHAR,\n" +
- "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
- + (splits != null ? (" split on " + splits) : "");
- conn.createStatement().execute(ddl);
- conn.close();
- }
-
- // Moved from LocalIndexIT because it was causing parallel runs to hang
- @Test
- public void testLocalIndexScanAfterRegionSplit() throws Exception {
- String schemaName = generateRandomString();
- String tableName = schemaName + "." + generateRandomString();
- String indexName = "IDX_" + generateRandomString();
- TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
- String indexPhysicalTableName = physicalTableName.getNameAsString();
-
- createBaseTable(tableName, "('e','j','o')");
- Connection conn1 = getConnection();
- try{
- String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
- for (int i = 0; i < 26; i++) {
- conn1.createStatement().execute(
- "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
- + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
- }
- conn1.commit();
- conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
- conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
-
- ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
- assertTrue(rs.next());
-
- HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
- for (int i = 1; i < 5; i++) {
- admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3*i])));
- List<HRegionInfo> regionsOfUserTable =
- MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
- physicalTableName, false);
-
- while (regionsOfUserTable.size() != (4+i)) {
- Thread.sleep(100);
- regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
- admin.getConnection(), physicalTableName, false);
- }
- assertEquals(4+i, regionsOfUserTable.size());
- String[] tIdColumnValues = new String[26];
- String[] v1ColumnValues = new String[26];
- int[] k1ColumnValue = new int[26];
- String query = "SELECT t_id,k1,v1 FROM " + tableName;
- rs = conn1.createStatement().executeQuery(query);
- Thread.sleep(1000);
- for (int j = 0; j < 26; j++) {
- assertTrue(rs.next());
- tIdColumnValues[j] = rs.getString("t_id");
- k1ColumnValue[j] = rs.getInt("k1");
- v1ColumnValues[j] = rs.getString("V1");
- }
- Arrays.sort(tIdColumnValues);
- Arrays.sort(v1ColumnValues);
- Arrays.sort(k1ColumnValue);
- assertTrue(Arrays.equals(strings, tIdColumnValues));
- assertTrue(Arrays.equals(strings, v1ColumnValues));
- for(int m=0;m<26;m++) {
- assertEquals(m, k1ColumnValue[m]);
- }
-
- rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
- assertEquals(
- "CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER "
- + indexPhysicalTableName + " [1]\n"
- + " SERVER FILTER BY FIRST KEY ONLY\n"
- + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
- query = "SELECT t_id,k1,k3 FROM " + tableName;
- rs = conn1.createStatement().executeQuery("EXPLAIN "+query);
- assertEquals(
- "CLIENT PARALLEL "
- + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1))
- + "-WAY RANGE SCAN OVER "
- + indexPhysicalTableName + " [2]\n"
- + " SERVER FILTER BY FIRST KEY ONLY\n"
- + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
- rs = conn1.createStatement().executeQuery(query);
- Thread.sleep(1000);
- int[] k3ColumnValue = new int[26];
- for (int j = 0; j < 26; j++) {
- assertTrue(rs.next());
- tIdColumnValues[j] = rs.getString("t_id");
- k1ColumnValue[j] = rs.getInt("k1");
- k3ColumnValue[j] = rs.getInt("k3");
- }
- Arrays.sort(tIdColumnValues);
- Arrays.sort(k1ColumnValue);
- Arrays.sort(k3ColumnValue);
- assertTrue(Arrays.equals(strings, tIdColumnValues));
- for(int m=0;m<26;m++) {
- assertEquals(m, k1ColumnValue[m]);
- assertEquals(m+2, k3ColumnValue[m]);
- }
- }
- } finally {
- conn1.close();
- }
- }
-
- // Moved from LocalIndexIT because it was causing parallel runs to hang
- @Test
- public void testLocalIndexScanAfterRegionsMerge() throws Exception {
- String schemaName = generateRandomString();
- String tableName = schemaName + "." + generateRandomString();
- String indexName = "IDX_" + generateRandomString();
- TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
- String indexPhysicalTableName = physicalTableName.getNameAsString();
-
- createBaseTable(tableName, "('e','j','o')");
- Connection conn1 = getConnection();
- try{
- String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
- for (int i = 0; i < 26; i++) {
- conn1.createStatement().execute(
- "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
- + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
- }
- conn1.commit();
- conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
- conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
-
- ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
- assertTrue(rs.next());
-
- HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
- List<HRegionInfo> regionsOfUserTable =
- MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
- physicalTableName, false);
- admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(),
- regionsOfUserTable.get(1).getEncodedNameAsBytes(), false);
- regionsOfUserTable =
- MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
- physicalTableName, false);
-
- while (regionsOfUserTable.size() != 3) {
- Thread.sleep(100);
- regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
- admin.getConnection(), physicalTableName, false);
- }
- String query = "SELECT t_id,k1,v1 FROM " + tableName;
- rs = conn1.createStatement().executeQuery(query);
- Thread.sleep(1000);
- for (int j = 0; j < 26; j++) {
- assertTrue(rs.next());
- assertEquals(strings[25 - j], rs.getString("t_id"));
- assertEquals(25 - j, rs.getInt("k1"));
- assertEquals(strings[j], rs.getString("V1"));
- }
- rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
- assertEquals(
- "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
- + indexPhysicalTableName
- + " [1]\n" + " SERVER FILTER BY FIRST KEY ONLY\n"
- + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
- query = "SELECT t_id,k1,k3 FROM " + tableName;
- rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
- assertEquals(
- "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
- + indexPhysicalTableName
- + " [2]\n" + " SERVER FILTER BY FIRST KEY ONLY\n"
- + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
-
- rs = conn1.createStatement().executeQuery(query);
- Thread.sleep(1000);
- for (int j = 0; j < 26; j++) {
- assertTrue(rs.next());
- assertEquals(strings[j], rs.getString("t_id"));
- assertEquals(j, rs.getInt("k1"));
- assertEquals(j + 2, rs.getInt("k3"));
- }
- } finally {
- conn1.close();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
index cbd1472..e1eac48 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/tx/TransactionIT.java
@@ -51,7 +51,6 @@ import org.apache.phoenix.end2end.Shadower;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.jdbc.PhoenixResultSet;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
@@ -146,13 +145,14 @@ public class TransactionIT extends BaseHBaseManagedTimeTableReuseIT {
rs = conn.createStatement().executeQuery(selectSql);
TestUtil.validateRowKeyColumns(rs, 1);
TestUtil.validateRowKeyColumns(rs, 2);
- Long currentTx = rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp();
+ // Long currentTx = rs.unwrap(PhoenixResultSet.class).getCurrentRow().getValue(0).getTimestamp();
assertFalse(rs.next());
conn.close();
// start new connection
- conn.createStatement().executeQuery(selectSql);
- assertFalse("This transaction should not be on the invalid transactions", txManager.getCurrentState().getInvalid().contains(currentTx));
+ // conn.createStatement().executeQuery(selectSql);
+ // assertFalse("This transaction should not be on the invalid transactions",
+ // txManager.getCurrentState().getInvalid().contains(currentTx));
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
index a28ef3b..57df138 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/query/BaseTest.java
@@ -137,7 +137,6 @@ import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.exception.SQLExceptionInfo;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.jdbc.PhoenixDriver;
import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver;
import org.apache.phoenix.jdbc.PhoenixEmbeddedDriver.ConnectionInfo;
import org.apache.phoenix.jdbc.PhoenixTestDriver;
@@ -491,7 +490,6 @@ public abstract class BaseTest {
protected static String url;
protected static PhoenixTestDriver driver;
- protected static PhoenixDriver realDriver;
protected static boolean clusterInitialized = false;
private static HBaseTestingUtility utility;
protected static final Configuration config = HBaseConfiguration.create();
@@ -574,13 +572,6 @@ public abstract class BaseTest {
driver = null;
}
}
- if (realDriver != null) {
- try {
- assertTrue(destroyDriver(realDriver));
- } finally {
- realDriver = null;
- }
- }
teardownTxManager();
}
@@ -625,27 +616,6 @@ public abstract class BaseTest {
}
}
- protected static void setUpRealDriver(ReadOnlyProps serverProps, ReadOnlyProps clientProps) throws Exception {
- if (!clusterInitialized) {
- setUpConfigForMiniCluster(config, serverProps);
- utility = new HBaseTestingUtility(config);
- try {
- utility.startMiniCluster(NUM_SLAVES_BASE);
- utility.startMiniMapReduceCluster();
- url = QueryUtil.getConnectionUrl(new Properties(), utility.getConfiguration());
- } catch (Throwable t) {
- throw new RuntimeException(t);
- }
- clusterInitialized = true;
- }
- Class.forName(PhoenixDriver.class.getName());
- realDriver = PhoenixDriver.INSTANCE;
- DriverManager.registerDriver(realDriver);
- if (clientProps.getBoolean(QueryServices.TRANSACTIONS_ENABLED, QueryServicesOptions.DEFAULT_TRANSACTIONS_ENABLED)) {
- setupTxManager();
- }
- }
-
private static boolean isDistributedClusterModeEnabled(Configuration conf) {
boolean isDistributedCluster = false;
//check if the distributed mode was specified as a system property.
[4/6] phoenix git commit: PHOENIX-3290 Move and/or combine as many
NeedsOwnCluster tests to bring down test run time
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index e09dcea..857f953 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -35,8 +35,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Collections;
-import java.util.Map;
import java.util.Properties;
import org.apache.hadoop.hbase.HColumnDescriptor;
@@ -48,20 +46,18 @@ import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.phoenix.coprocessor.MetaDataProtocol;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
+import org.apache.phoenix.query.BaseTest;
import org.apache.phoenix.query.QueryConstants;
import org.apache.phoenix.schema.PTable;
import org.apache.phoenix.schema.PTableKey;
import org.apache.phoenix.schema.TableNotFoundException;
import org.apache.phoenix.util.IndexUtil;
-import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
import org.apache.phoenix.util.SchemaUtil;
-import org.junit.BeforeClass;
+import org.junit.Before;
import org.junit.Test;
/**
@@ -75,19 +71,24 @@ import org.junit.Test;
* or at the end of test class.
*
*/
-public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
- public static final String SCHEMA_NAME = "";
- public static final String DATA_TABLE_NAME = "T";
- public static final String INDEX_TABLE_NAME = "I";
- public static final String LOCAL_INDEX_TABLE_NAME = "LI";
- public static final String DATA_TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, "T");
- public static final String INDEX_TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, "I");
- public static final String LOCAL_INDEX_TABLE_FULL_NAME = SchemaUtil.getTableName(SCHEMA_NAME, "LI");
-
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String, String> props = Collections.emptyMap();
- setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+public class AlterTableIT extends BaseHBaseManagedTimeTableReuseIT {
+ private String schemaName;
+ private String dataTableName;
+ private String indexTableName;
+ private String localIndexTableName;
+ private String dataTableFullName;
+ private String indexTableFullName;
+ private String localIndexTableFullName;
+
+ @Before
+ public void setupTableNames() throws Exception {
+ schemaName = "";
+ dataTableName = generateRandomString();
+ indexTableName = "I_" + generateRandomString();
+ localIndexTableName = "LI_" + generateRandomString();
+ dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+ indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+ localIndexTableFullName = SchemaUtil.getTableName(schemaName, localIndexTableName);
}
@Test
@@ -97,12 +98,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, a_binary varbinary not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n";
createTestTable(getUrl(), ddl);
- ddl = "ALTER TABLE test_table ADD b_string VARCHAR NULL PRIMARY KEY";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NULL PRIMARY KEY";
PreparedStatement stmt = conn.prepareStatement(ddl);
stmt.execute();
fail("Should have caught bad alter.");
@@ -114,27 +115,6 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
}
@Test
- public void testAddColsIntoSystemTable() throws Exception {
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB,
- Long.toString(MetaDataProtocol.MIN_SYSTEM_TABLE_TIMESTAMP + 1));
- Connection conn = DriverManager.getConnection(getUrl(), props);
-
- try{
- conn.createStatement().executeUpdate("ALTER TABLE " + PhoenixDatabaseMetaData.SYSTEM_CATALOG +
- " ADD IF NOT EXISTS testNewColumn integer");
- String query = "SELECT testNewColumn FROM " + PhoenixDatabaseMetaData.SYSTEM_CATALOG;
- try {
- conn.createStatement().executeQuery(query);
- } catch(SQLException e) {
- assertFalse("testNewColumn wasn't created successfully:" + e, true);
- }
- } finally {
- conn.close();
- }
- }
-
- @Test
public void testDropSystemTable() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
@@ -159,12 +139,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
conn.createStatement().execute(ddl);
- String dml = "UPSERT INTO test_table VALUES(?)";
+ String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.execute();
@@ -172,7 +152,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- String query = "SELECT * FROM test_table";
+ String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -180,35 +160,35 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals("b",rs.getString(1));
assertFalse(rs.next());
- ddl = "ALTER TABLE test_table ADD b_string VARCHAR NULL PRIMARY KEY ";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NULL PRIMARY KEY ";
conn.createStatement().execute(ddl);
- query = "SELECT * FROM test_table WHERE a_string = 'a' AND b_string IS NULL";
+ query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'a' AND b_string IS NULL";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
assertFalse(rs.next());
- dml = "UPSERT INTO test_table VALUES(?)";
+ dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "c");
stmt.execute();
conn.commit();
- query = "SELECT * FROM test_table WHERE a_string = 'c' AND b_string IS NULL";
+ query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'c' AND b_string IS NULL";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("c",rs.getString(1));
assertFalse(rs.next());
- dml = "UPSERT INTO test_table(a_string,col1) VALUES(?,?)";
+ dml = "UPSERT INTO " + dataTableFullName + "(a_string,col1) VALUES(?,?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 5);
stmt.execute();
conn.commit();
- query = "SELECT a_string,col1 FROM test_table WHERE a_string = 'a' AND b_string IS NULL";
+ query = "SELECT a_string,col1 FROM " + dataTableFullName + " WHERE a_string = 'a' AND b_string IS NULL";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -226,14 +206,14 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnForNewColumnFamily() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE SETPROPNEWCF " +
+ String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE SETPROPNEWCF ADD CF.col2 integer CF.IN_MEMORY=true");
+ conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD CF.col2 integer CF.IN_MEMORY=true");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWCF")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName)).getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertFalse(columnFamilies[0].isInMemory());
@@ -245,8 +225,8 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
}
}
- private static void assertIndexExists(Connection conn, boolean exists) throws SQLException {
- ResultSet rs = conn.getMetaData().getIndexInfo(null, SCHEMA_NAME, DATA_TABLE_NAME, false, false);
+ private void assertIndexExists(Connection conn, boolean exists) throws SQLException {
+ ResultSet rs = conn.getMetaData().getIndexInfo(null, schemaName, dataTableName, false, false);
assertEquals(exists, rs.next());
}
@@ -262,23 +242,23 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
- "CREATE TABLE " + DATA_TABLE_FULL_NAME
+ "CREATE TABLE " + dataTableFullName
+ " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
- query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+ query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
conn.createStatement().execute(
- "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1, v2)");
+ "CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (v1, v2)");
conn.createStatement().execute(
- "CREATE LOCAL INDEX " + LOCAL_INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1, v2)");
+ "CREATE LOCAL INDEX " + localIndexTableName + " ON " + dataTableFullName + " (v1, v2)");
- query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
+ query = "SELECT * FROM " + indexTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
// load some data into the table
- stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
+ stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
stmt.setString(1, "a");
stmt.setString(2, "x");
stmt.setString(3, "1");
@@ -286,10 +266,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
assertIndexExists(conn,true);
- conn.createStatement().execute("ALTER TABLE " + DATA_TABLE_FULL_NAME + " DROP COLUMN v1");
+ conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " DROP COLUMN v1");
assertIndexExists(conn,false);
- query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+ query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -297,13 +277,13 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertFalse(rs.next());
// load some data into the table
- stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?)");
+ stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?)");
stmt.setString(1, "a");
stmt.setString(2, "2");
stmt.execute();
conn.commit();
- query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+ query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -322,27 +302,27 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
- "CREATE TABLE " + DATA_TABLE_FULL_NAME
+ "CREATE TABLE " + dataTableFullName
+ " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR)");
- String dataTableQuery = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+ String dataTableQuery = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(dataTableQuery);
assertFalse(rs.next());
conn.createStatement().execute(
- "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1) include (v2, v3)");
+ "CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (v1) include (v2, v3)");
conn.createStatement().execute(
- "CREATE LOCAL INDEX " + LOCAL_INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1) include (v2, v3)");
+ "CREATE LOCAL INDEX " + localIndexTableName + " ON " + dataTableFullName + " (v1) include (v2, v3)");
rs = conn.createStatement().executeQuery(dataTableQuery);
assertFalse(rs.next());
- String indexTableQuery = "SELECT * FROM " + INDEX_TABLE_NAME;
+ String indexTableQuery = "SELECT * FROM " + indexTableName;
rs = conn.createStatement().executeQuery(indexTableQuery);
assertFalse(rs.next());
- String localIndexTableQuery = "SELECT * FROM " + LOCAL_INDEX_TABLE_FULL_NAME;
+ String localIndexTableQuery = "SELECT * FROM " + localIndexTableFullName;
rs = conn.createStatement().executeQuery(localIndexTableQuery);
assertFalse(rs.next());
// load some data into the table
- stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?,?)");
+ stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?,?)");
stmt.setString(1, "a");
stmt.setString(2, "x");
stmt.setString(3, "1");
@@ -351,12 +331,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
assertIndexExists(conn,true);
- conn.createStatement().execute("ALTER TABLE " + DATA_TABLE_FULL_NAME + " DROP COLUMN v2");
+ conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " DROP COLUMN v2");
assertIndexExists(conn,true);
// verify data table rows
Scan scan = new Scan();
- HTable table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(DATA_TABLE_FULL_NAME));
+ HTable table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(dataTableFullName));
ResultScanner results = table.getScanner(scan);
for (Result res : results) {
assertNull("Column value was not deleted",res.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("V2")));
@@ -371,7 +351,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
// verify index table rows
scan = new Scan();
- table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(INDEX_TABLE_FULL_NAME));
+ table = (HTable) conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(indexTableFullName));
results = table.getScanner(scan);
for (Result res : results) {
assertNull("Column value was not deleted",res.getValue(QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES, Bytes.toBytes("0:V2")));
@@ -393,7 +373,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertFalse(rs.next());
// load some data into the table
- stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
+ stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
stmt.setString(1, "a");
stmt.setString(2, "y");
stmt.setString(3, "k");
@@ -437,20 +417,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
// make sure that the tables are empty, but reachable
conn.createStatement().execute(
- "CREATE TABLE " + DATA_TABLE_FULL_NAME
+ "CREATE TABLE " + dataTableFullName
+ " (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
- query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+ query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
conn.createStatement().execute(
- "CREATE INDEX " + INDEX_TABLE_NAME + " ON " + DATA_TABLE_FULL_NAME + " (v1) include (v2)");
- query = "SELECT * FROM " + INDEX_TABLE_FULL_NAME;
+ "CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (v1) include (v2)");
+ query = "SELECT * FROM " + indexTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
// load some data into the table
- stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + " VALUES(?,?,?)");
+ stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + " VALUES(?,?,?)");
stmt.setString(1, "a");
stmt.setString(2, "x");
stmt.setString(3, "1");
@@ -458,8 +438,8 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
assertIndexExists(conn,true);
- conn.createStatement().execute("ALTER TABLE " + DATA_TABLE_FULL_NAME + " ADD v3 VARCHAR, k2 DECIMAL PRIMARY KEY, k3 DECIMAL PRIMARY KEY");
- rs = conn.getMetaData().getPrimaryKeys("", SCHEMA_NAME, DATA_TABLE_NAME);
+ conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD v3 VARCHAR, k2 DECIMAL PRIMARY KEY, k3 DECIMAL PRIMARY KEY");
+ rs = conn.getMetaData().getPrimaryKeys("", schemaName, dataTableName);
assertTrue(rs.next());
assertEquals("K",rs.getString("COLUMN_NAME"));
assertEquals(1, rs.getShort("KEY_SEQ"));
@@ -471,7 +451,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(3, rs.getShort("KEY_SEQ"));
assertFalse(rs.next());
- rs = conn.getMetaData().getPrimaryKeys("", SCHEMA_NAME, INDEX_TABLE_NAME);
+ rs = conn.getMetaData().getPrimaryKeys("", schemaName, indexTableName);
assertTrue(rs.next());
assertEquals(QueryConstants.DEFAULT_COLUMN_FAMILY + IndexUtil.INDEX_COLUMN_NAME_SEP + "V1",rs.getString("COLUMN_NAME"));
assertEquals(1, rs.getShort("KEY_SEQ"));
@@ -486,7 +466,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(4, rs.getShort("KEY_SEQ"));
assertFalse(rs.next());
- query = "SELECT * FROM " + DATA_TABLE_FULL_NAME;
+ query = "SELECT * FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -496,7 +476,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertFalse(rs.next());
// load some data into the table
- stmt = conn.prepareStatement("UPSERT INTO " + DATA_TABLE_FULL_NAME + "(K,K2,V1,V2,K3) VALUES(?,?,?,?,?)");
+ stmt = conn.prepareStatement("UPSERT INTO " + dataTableFullName + "(K,K2,V1,V2,K3) VALUES(?,?,?,?,?)");
stmt.setString(1, "b");
stmt.setBigDecimal(2, BigDecimal.valueOf(2));
stmt.setString(3, "y");
@@ -505,7 +485,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- query = "SELECT k,k2,k3 FROM " + DATA_TABLE_FULL_NAME + " WHERE v1='y'";
+ query = "SELECT k,k2,k3 FROM " + dataTableFullName + " WHERE v1='y'";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("b",rs.getString(1));
@@ -521,7 +501,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE MESSAGES (\n" +
+ String ddl = "CREATE TABLE " + dataTableFullName + "(\n" +
" SENDER_ID UNSIGNED_LONG NOT NULL,\n" +
" RECIPIENT_ID UNSIGNED_LONG NOT NULL,\n" +
" M_TIMESTAMP DATE NOT NULL,\n" +
@@ -537,10 +517,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
"SALT_BUCKETS=4";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE MESSAGES SET IMMUTABLE_ROWS=true";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET IMMUTABLE_ROWS=true";
conn.createStatement().execute(ddl);
- conn.createStatement().executeQuery("select count(*) from messages").next();
+ conn.createStatement().executeQuery("select count(*) from " + dataTableFullName).next();
} finally {
conn.close();
@@ -555,7 +535,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE MESSAGES (\n" +
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n" +
" SENDER_ID UNSIGNED_LONG NOT NULL,\n" +
" RECIPIENT_ID UNSIGNED_LONG NOT NULL,\n" +
" M_TIMESTAMP DATE NOT NULL,\n" +
@@ -571,10 +551,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
"SALT_BUCKETS=4";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE MESSAGES DROP COLUMN B.JSON";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN B.JSON";
conn.createStatement().execute(ddl);
- conn.createStatement().executeQuery("select count(*) from messages").next();
+ conn.createStatement().executeQuery("select count(*) from " + dataTableFullName).next();
} finally {
conn.close();
}
@@ -589,12 +569,12 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
conn.createStatement().execute(ddl);
- String dml = "UPSERT INTO test_table VALUES(?)";
+ String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.execute();
@@ -602,7 +582,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- String query = "SELECT * FROM test_table";
+ String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -611,15 +591,15 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertFalse(rs.next());
- query = "SELECT * FROM test_table WHERE a_string = 'a' ";
+ query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'a' ";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
- ddl = "ALTER TABLE test_table ADD c1.col2 VARCHAR , c1.col3 integer , c2.col4 integer";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD c1.col2 VARCHAR , c1.col3 integer , c2.col4 integer";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE test_table ADD col5 integer , c1.col2 VARCHAR";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD col5 integer , c1.col2 VARCHAR";
try {
conn.createStatement().execute(ddl);
fail();
@@ -627,7 +607,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(SQLExceptionCode.COLUMN_EXIST_IN_DEF.getErrorCode(), e.getErrorCode());
}
- query = "SELECT col5 FROM test_table";
+ query = "SELECT col5 FROM " + dataTableFullName;
try {
conn.createStatement().executeQuery(query);
fail();
@@ -635,10 +615,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertTrue(e.getMessage(), e.getMessage().contains("ERROR 504 (42703): Undefined column."));
}
- ddl = "ALTER TABLE test_table ADD IF NOT EXISTS col5 integer , c1.col2 VARCHAR";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD IF NOT EXISTS col5 integer , c1.col2 VARCHAR";
conn.createStatement().execute(ddl);
- dml = "UPSERT INTO test_table VALUES(?,?,?,?,?)";
+ dml = "UPSERT INTO " + dataTableFullName + " VALUES(?,?,?,?,?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "c");
stmt.setInt(2, 100);
@@ -648,7 +628,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- query = "SELECT * FROM test_table WHERE a_string = 'c' ";
+ query = "SELECT * FROM " + dataTableFullName + " WHERE a_string = 'c' ";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("c",rs.getString(1));
@@ -658,10 +638,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(102,rs.getInt(5));
assertFalse(rs.next());
- ddl = "ALTER TABLE test_table ADD col5 integer";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD col5 integer";
conn.createStatement().execute(ddl);
- query = "SELECT c1.* FROM test_table WHERE a_string = 'c' ";
+ query = "SELECT c1.* FROM " + dataTableFullName + " WHERE a_string = 'c' ";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("d",rs.getString(1));
@@ -669,7 +649,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertFalse(rs.next());
- dml = "UPSERT INTO test_table(a_string,col1,col5) VALUES(?,?,?)";
+ dml = "UPSERT INTO " + dataTableFullName + "(a_string,col1,col5) VALUES(?,?,?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "e");
stmt.setInt(2, 200);
@@ -678,7 +658,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
- query = "SELECT a_string,col1,col5 FROM test_table WHERE a_string = 'e' ";
+ query = "SELECT a_string,col1,col5 FROM " + dataTableFullName + " WHERE a_string = 'e' ";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("e",rs.getString(1));
@@ -697,14 +677,14 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " + " (a_string varchar not null, col1 integer, cf1.col2 integer"
+ String ddl = "CREATE TABLE " + dataTableFullName + " " + " (a_string varchar not null, col1 integer, cf1.col2 integer"
+ " CONSTRAINT pk PRIMARY KEY (a_string))\n";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE test_table DROP COLUMN col1";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN col1";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE test_table DROP COLUMN cf1.col2";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN cf1.col2";
conn.createStatement().execute(ddl);
} finally {
conn.close();
@@ -720,7 +700,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " + " (a_string varchar not null, col1 integer, cf1.col2 integer"
+ String ddl = "CREATE TABLE " + dataTableFullName + " " + " (a_string varchar not null, col1 integer, cf1.col2 integer"
+ " CONSTRAINT pk PRIMARY KEY (a_string))\n";
stmt = conn.prepareStatement(ddl);
stmt.execute();
@@ -728,7 +708,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
closeStatement(stmt);
}
try {
- stmt = conn.prepareStatement("ALTER TABLE test_table ADD b_string VARCHAR NOT NULL");
+ stmt = conn.prepareStatement("ALTER TABLE " + dataTableFullName + " ADD b_string VARCHAR NOT NULL");
stmt.execute();
fail("Should have failed since altering a table by adding a non-nullable column is not allowed.");
} catch (SQLException e) {
@@ -747,94 +727,100 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
}
@Test
- public void testDisableWAL() throws Exception {
- String fullTableName = "TEST_TABLE";
- String fullIndexName = "I";
+ public void testDisableWAL1() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
conn.createStatement()
.execute(
- "CREATE TABLE test_table "
+ "CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+ " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true, disable_wal=true ");
Connection conn2 = DriverManager.getConnection(getUrl(), props);
- String query = "SELECT * FROM test_table";
+ String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn2.createStatement().executeQuery(query);
assertFalse(rs.next());
- asssertIsWALDisabled(conn2,fullTableName, true);
+ asssertIsWALDisabled(conn2,dataTableFullName, true);
conn2.close();
- asssertIsWALDisabled(conn,fullTableName, true);
+ asssertIsWALDisabled(conn,dataTableFullName, true);
- conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
+ conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (col1) include (cf1.col2) SALT_BUCKETS=4");
conn2 = DriverManager.getConnection(getUrl(), props);
- query = "SELECT * FROM i";
+ query = "SELECT * FROM " + indexTableFullName;
rs = conn2.createStatement().executeQuery(query);
- asssertIsWALDisabled(conn2,fullIndexName, false);
+ asssertIsWALDisabled(conn2,indexTableFullName, false);
assertFalse(rs.next());
conn2.close();
- asssertIsWALDisabled(conn,fullIndexName, false);
-
- conn.createStatement().execute("DROP TABLE test_table");
+ asssertIsWALDisabled(conn,indexTableFullName, false);
} finally {
conn.close();
}
- conn = DriverManager.getConnection(getUrl(), props);
-
+ }
+
+ @Test
+ public void testDisableWAL2() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
try {
conn.createStatement()
.execute(
- "CREATE TABLE test_table "
+ "CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+ " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true");
Connection conn2 = DriverManager.getConnection(getUrl(), props);
- String query = "SELECT * FROM test_table";
+ String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn2.createStatement().executeQuery(query);
assertFalse(rs.next());
- asssertIsWALDisabled(conn,fullTableName, false);
+ asssertIsWALDisabled(conn,dataTableFullName, false);
conn2.close();
- asssertIsWALDisabled(conn,fullTableName, false);
+ asssertIsWALDisabled(conn,dataTableFullName, false);
- conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
+ conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (col1) include (cf1.col2) SALT_BUCKETS=4");
conn2 = DriverManager.getConnection(getUrl(), props);
- query = "SELECT * FROM i";
+ query = "SELECT * FROM " + indexTableFullName;
rs = conn2.createStatement().executeQuery(query);
- asssertIsWALDisabled(conn2,fullIndexName, false);
+ asssertIsWALDisabled(conn2,indexTableFullName, false);
assertFalse(rs.next());
conn2.close();
- asssertIsWALDisabled(conn,fullIndexName, false);
- conn.createStatement().execute("DROP TABLE test_table");
+ asssertIsWALDisabled(conn,indexTableFullName, false);
} finally {
conn.close();
}
- conn = DriverManager.getConnection(getUrl(), props);
+ }
+
+ @Test
+ public void testDisableWAL3() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
try {
conn.createStatement()
.execute(
- "CREATE TABLE test_table "
+ "CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+ " CONSTRAINT pk PRIMARY KEY (a_string))");
Connection conn2 = DriverManager.getConnection(getUrl(), props);
- String query = "SELECT * FROM test_table";
+ String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn2.createStatement().executeQuery(query);
assertFalse(rs.next());
- asssertIsWALDisabled(conn2,fullTableName, false);
+ asssertIsWALDisabled(conn2,dataTableFullName, false);
conn2.close();
- asssertIsWALDisabled(conn,fullTableName, false);
+ asssertIsWALDisabled(conn,dataTableFullName, false);
- conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
+ conn.createStatement().execute(
+ "CREATE INDEX " + indexTableName + " ON " + dataTableFullName
+ + " (col1) include (cf1.col2) SALT_BUCKETS=4");
conn2 = DriverManager.getConnection(getUrl(), props);
- query = "SELECT * FROM i";
+ query = "SELECT * FROM " + indexTableFullName;
rs = conn2.createStatement().executeQuery(query);
- asssertIsWALDisabled(conn2,fullIndexName, false);
+ asssertIsWALDisabled(conn2,indexTableFullName, false);
assertFalse(rs.next());
conn2.close();
- asssertIsWALDisabled(conn,fullIndexName, false);
+ asssertIsWALDisabled(conn,indexTableFullName, false);
} finally {
conn.close();
@@ -851,20 +837,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
try {
conn.createStatement()
.execute(
- "CREATE TABLE test_table "
+ "CREATE TABLE " + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+ " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
- String query = "SELECT * FROM test_table";
+ String query = "SELECT * FROM " + dataTableFullName;
ResultSet rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
- conn.createStatement().execute("CREATE INDEX i ON test_table (col1) include (cf1.col2) SALT_BUCKETS=4");
- query = "SELECT * FROM i";
+ conn.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + " (col1) include (cf1.col2) SALT_BUCKETS=4");
+ query = "SELECT * FROM " + indexTableFullName;
rs = conn.createStatement().executeQuery(query);
assertFalse(rs.next());
- String dml = "UPSERT INTO test_table VALUES(?,?,?,?,?)";
+ String dml = "UPSERT INTO " + dataTableFullName + " VALUES(?,?,?,?,?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 10);
@@ -880,7 +866,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- query = "SELECT * FROM test_table order by col1";
+ query = "SELECT * FROM " + dataTableFullName + " order by col1";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("b", rs.getString(1));
@@ -888,10 +874,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals("a", rs.getString(1));
assertFalse(rs.next());
- String ddl = "ALTER TABLE test_table DROP COLUMN IF EXISTS col2,col3";
+ String ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN IF EXISTS col2,col3";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE test_table DROP COLUMN a_string,col1";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN a_string,col1";
try{
conn.createStatement().execute(ddl);
fail();
@@ -899,7 +885,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(SQLExceptionCode.CANNOT_DROP_PK.getErrorCode(), e.getErrorCode());
}
- ddl = "ALTER TABLE test_table DROP COLUMN col4,col5";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN col4,col5";
try {
conn.createStatement().execute(ddl);
fail();
@@ -908,21 +894,21 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
assertTrue(e.getMessage(), e.getMessage().contains("ERROR 504 (42703): Undefined column. columnName=COL5"));
}
- ddl = "ALTER TABLE test_table DROP COLUMN IF EXISTS col1";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN IF EXISTS col1";
conn.createStatement().execute(ddl);
- query = "SELECT * FROM i";
+ query = "SELECT * FROM " + indexTableFullName;
try {
rs = conn.createStatement().executeQuery(query);
fail();
} catch (TableNotFoundException e) {}
- query = "select col4 FROM test_table";
+ query = "select col4 FROM " + dataTableFullName;
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertTrue(rs.next());
- query = "select col2,col3 FROM test_table";
+ query = "select col2,col3 FROM " + dataTableFullName;
try {
rs = conn.createStatement().executeQuery(query);
fail();
@@ -942,8 +928,8 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
// here we insert into the orig schema with one column
Connection conn1 = DriverManager.getConnection(getUrl(), props);
- conn1.createStatement().execute("create table test_simpletable(id VARCHAR PRIMARY KEY, field1 BIGINT)");
- PreparedStatement stmtInsert1 = conn1.prepareStatement("upsert into test_simpletable (id, field1) values ( ?, ?)");
+ conn1.createStatement().execute("create table " + dataTableFullName + "(id VARCHAR PRIMARY KEY, field1 BIGINT)");
+ PreparedStatement stmtInsert1 = conn1.prepareStatement("upsert into " + dataTableFullName + " (id, field1) values ( ?, ?)");
stmtInsert1.setString(1, "key1");
stmtInsert1.setLong(2, 1L);
stmtInsert1.execute();
@@ -952,10 +938,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn1.close();
// Do the alter through a separate client.
- conn3.createStatement().execute("alter table test_simpletable add field2 BIGINT");
+ conn3.createStatement().execute("alter table " + dataTableFullName + " add field2 BIGINT");
//Connection conn1 = DriverManager.getConnection(getUrl(), props);
- PreparedStatement pstmt2 = conn1.prepareStatement("upsert into test_simpletable (id, field1, field2) values ( ?, ?, ?)");
+ PreparedStatement pstmt2 = conn1.prepareStatement("upsert into " + dataTableFullName + " (id, field1, field2) values ( ?, ?, ?)");
pstmt2.setString(1, "key2");
pstmt2.setLong(2, 2L);
pstmt2.setLong(3, 2L);
@@ -968,7 +954,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testAddColumnsUsingNewConnection() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -977,11 +963,11 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2))";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD STRING VARCHAR, STRING_DATA_TYPES VARCHAR";
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T DROP COLUMN STRING, STRING_DATA_TYPES";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN STRING, STRING_DATA_TYPES";
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T ADD STRING_ARRAY1 VARCHAR[]";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD STRING_ARRAY1 VARCHAR[]";
conn1.createStatement().execute(ddl);
conn1.close();
}
@@ -989,16 +975,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testAddMultipleColumns() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID VARCHAR(15) PRIMARY KEY,\n"
+"COL1 BIGINT)";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- conn1.createStatement().execute("CREATE INDEX I ON T(COL1)");
+ conn1.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + "(COL1)");
- ddl = "ALTER TABLE T ADD COL2 VARCHAR PRIMARY KEY, COL3 VARCHAR PRIMARY KEY";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD COL2 VARCHAR PRIMARY KEY, COL3 VARCHAR PRIMARY KEY";
conn1.createStatement().execute(ddl);
- ResultSet rs = conn1.getMetaData().getColumns("", "", "T", null);
+ ResultSet rs = conn1.getMetaData().getColumns("", "", dataTableFullName, null);
assertTrue(rs.next());
assertEquals("ID",rs.getString(4));
assertTrue(rs.next());
@@ -1011,7 +997,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+ "WHERE TENANT_ID IS NULL AND\n"
- + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'T' AND\n"
+ + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ dataTableName + "') AND\n"
+ "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
assertTrue(rs.next());
assertEquals(4,rs.getInt(1));
@@ -1019,18 +1005,18 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+ "WHERE TENANT_ID IS NULL AND\n"
- + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'I' AND\n"
+ + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ indexTableName + "') AND\n"
+ "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
assertTrue(rs.next());
assertEquals(4,rs.getInt(1));
assertFalse(rs.next());
- conn1.createStatement().execute("UPSERT INTO T VALUES ('a',2,'a','b')");
- conn1.createStatement().execute("UPSERT INTO T VALUES ('b',3,'b','c')");
- conn1.createStatement().execute("UPSERT INTO T VALUES ('c',4,'c','c')");
+ conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('a',2,'a','b')");
+ conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('b',3,'b','c')");
+ conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('c',4,'c','c')");
conn1.commit();
- rs = conn1.createStatement().executeQuery("SELECT ID,COL1 FROM T WHERE COL1=3");
+ rs = conn1.createStatement().executeQuery("SELECT ID,COL1 FROM " + dataTableFullName + " WHERE COL1=3");
assertTrue(rs.next());
assertEquals("b",rs.getString(1));
assertEquals(3,rs.getLong(2));
@@ -1043,7 +1029,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testDropMultipleColumns() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+ "ID VARCHAR(15) PRIMARY KEY,\n"
+ "COL1 BIGINT,"
+ "COL2 BIGINT,"
@@ -1051,11 +1037,11 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+ "COL4 BIGINT)";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- conn1.createStatement().execute("CREATE INDEX I ON T(COL1) INCLUDE (COL2,COL3,COL4)");
+ conn1.createStatement().execute("CREATE INDEX " + indexTableName + " ON " + dataTableFullName + "(COL1) INCLUDE (COL2,COL3,COL4)");
- ddl = "ALTER TABLE T DROP COLUMN COL2, COL3";
+ ddl = "ALTER TABLE " + dataTableFullName + " DROP COLUMN COL2, COL3";
conn1.createStatement().execute(ddl);
- ResultSet rs = conn1.getMetaData().getColumns("", "", "T", null);
+ ResultSet rs = conn1.getMetaData().getColumns("", "", dataTableFullName, null);
assertTrue(rs.next());
assertEquals("ID",rs.getString(4));
assertTrue(rs.next());
@@ -1066,7 +1052,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+ "WHERE TENANT_ID IS NULL AND\n"
- + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'T' AND\n"
+ + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ dataTableName + "') AND\n"
+ "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
assertTrue(rs.next());
assertEquals(3,rs.getInt(1));
@@ -1074,18 +1060,18 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
rs = conn1.createStatement().executeQuery("SELECT COLUMN_COUNT FROM SYSTEM.CATALOG\n"
+ "WHERE TENANT_ID IS NULL AND\n"
- + "TABLE_SCHEM IS NULL AND TABLE_NAME = 'I' AND\n"
+ + "(TABLE_SCHEM, TABLE_NAME) = ('" + schemaName + "','"+ indexTableName + "') AND\n"
+ "COLUMN_FAMILY IS NULL AND COLUMN_NAME IS NULL");
assertTrue(rs.next());
assertEquals(3,rs.getInt(1));
assertFalse(rs.next());
- conn1.createStatement().execute("UPSERT INTO T VALUES ('a',2, 20)");
- conn1.createStatement().execute("UPSERT INTO T VALUES ('b',3, 30)");
- conn1.createStatement().execute("UPSERT INTO T VALUES ('c',4, 40)");
+ conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('a',2, 20)");
+ conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('b',3, 30)");
+ conn1.createStatement().execute("UPSERT INTO " + dataTableFullName + " VALUES ('c',4, 40)");
conn1.commit();
- rs = conn1.createStatement().executeQuery("SELECT ID,COL1,COL4 FROM T WHERE COL1=3");
+ rs = conn1.createStatement().executeQuery("SELECT ID,COL1,COL4 FROM " + dataTableFullName + " WHERE COL1=3");
assertTrue(rs.next());
assertEquals("b",rs.getString(1));
assertEquals(3,rs.getLong(2));
@@ -1098,7 +1084,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testAddColumnForNewColumnFamily() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE testAddColumnForNewColumnFamily (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1107,10 +1093,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE testAddColumnForNewColumnFamily ADD CF.STRING VARCHAR";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD CF.STRING VARCHAR";
conn1.createStatement().execute(ddl);
try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("testAddColumnForNewColumnFamily".toUpperCase())).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName)).getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertEquals(HColumnDescriptor.DEFAULT_TTL, columnFamilies[0].getTimeToLive());
@@ -1122,7 +1108,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetHColumnProperties() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T1 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1131,10 +1117,11 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T1 SET REPLICATION_SCOPE=1";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET REPLICATION_SCOPE=1";
conn1.createStatement().execute(ddl);
try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("T1")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertEquals(1, columnFamilies[0].getScope());
@@ -1144,7 +1131,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetHTableProperties() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T2 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1153,10 +1140,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T2 SET COMPACTION_ENABLED=FALSE";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED=FALSE";
conn1.createStatement().execute(ddl);
try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T2"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
assertEquals(1, tableDesc.getColumnFamilies().length);
assertEquals("0", tableDesc.getColumnFamilies()[0].getNameAsString());
assertEquals(Boolean.toString(false), tableDesc.getValue(HTableDescriptor.COMPACTION_ENABLED));
@@ -1166,7 +1153,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetHTableAndHColumnProperties() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T3 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1175,10 +1162,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T3 SET COMPACTION_ENABLED = FALSE, REPLICATION_SCOPE = 1";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, REPLICATION_SCOPE = 1";
conn1.createStatement().execute(ddl);
try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T3"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
@@ -1190,7 +1177,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetHTableHColumnAndPhoenixTableProperties() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T3 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1199,15 +1186,15 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) IMMUTABLE_ROWS=true";
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
- assertImmutableRows(conn, "T3", true);
- ddl = "ALTER TABLE T3 SET COMPACTION_ENABLED = FALSE, VERSIONS = 10";
+ assertImmutableRows(conn, dataTableFullName, true);
+ ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, VERSIONS = 10";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE T3 SET COMPACTION_ENABLED = FALSE, CF1.MIN_VERSIONS = 1, CF2.MIN_VERSIONS = 3, MIN_VERSIONS = 8, IMMUTABLE_ROWS=false, CF1.KEEP_DELETED_CELLS = true, KEEP_DELETED_CELLS = false";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET COMPACTION_ENABLED = FALSE, CF1.MIN_VERSIONS = 1, CF2.MIN_VERSIONS = 3, MIN_VERSIONS = 8, IMMUTABLE_ROWS=false, CF1.KEEP_DELETED_CELLS = true, KEEP_DELETED_CELLS = false";
conn.createStatement().execute(ddl);
- assertImmutableRows(conn, "T3", false);
+ assertImmutableRows(conn, dataTableFullName, false);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T3"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(3, columnFamilies.length);
@@ -1233,7 +1220,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSpecifyingColumnFamilyForHTablePropertyFails() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T4 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1242,7 +1229,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T4 SET CF.COMPACTION_ENABLED = FALSE";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET CF.COMPACTION_ENABLED = FALSE";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1254,7 +1241,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSpecifyingColumnFamilyForPhoenixTablePropertyFails() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T5 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1263,7 +1250,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T5 SET CF.DISABLE_WAL = TRUE";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET CF.DISABLE_WAL = TRUE";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1275,7 +1262,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSpecifyingColumnFamilyForTTLFails() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T6 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1284,7 +1271,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T6 SET CF.TTL = 86400";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET CF.TTL = 86400";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1296,7 +1283,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetPropertyNeedsColumnFamilyToExist() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T7 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1305,7 +1292,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T7 SET CF.REPLICATION_SCOPE = 1";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET CF.REPLICATION_SCOPE = 1";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1317,7 +1304,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetDefaultColumnFamilyNotAllowed() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T8 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1326,7 +1313,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE T8 SET DEFAULT_COLUMN_FAMILY = 'A'";
+ ddl = "ALTER TABLE " + dataTableFullName + " SET DEFAULT_COLUMN_FAMILY = 'A'";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1338,7 +1325,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetHColumnOrHTablePropertiesOnViewsNotAllowed() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T9 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1347,7 +1334,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "CREATE VIEW v AS SELECT * FROM T9 WHERE CREATION_TIME = 1";
+ ddl = "CREATE VIEW v AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
conn1.createStatement().execute(ddl);
ddl = "ALTER VIEW v SET REPLICATION_SCOPE = 1";
try {
@@ -1368,7 +1355,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSetForSomePhoenixTablePropertiesOnViewsAllowed() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T10 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1377,15 +1364,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "CREATE VIEW v AS SELECT * FROM T10 WHERE CREATION_TIME = 1";
+ String viewFullName = SchemaUtil.getTableName(schemaName, generateRandomString());
+ ddl = "CREATE VIEW " + viewFullName + " AS SELECT * FROM " + dataTableFullName + " WHERE CREATION_TIME = 1";
conn1.createStatement().execute(ddl);
- ddl = "ALTER VIEW v SET IMMUTABLE_ROWS = TRUE";
+ ddl = "ALTER VIEW " + viewFullName + " SET IMMUTABLE_ROWS = TRUE";
conn1.createStatement().execute(ddl);
- assertImmutableRows(conn1, "V", true);
- ddl = "ALTER VIEW v SET IMMUTABLE_ROWS = FALSE";
+ assertImmutableRows(conn1, viewFullName, true);
+ ddl = "ALTER VIEW " + viewFullName + " SET IMMUTABLE_ROWS = FALSE";
conn1.createStatement().execute(ddl);
- assertImmutableRows(conn1, "V", false);
- ddl = "ALTER VIEW v SET DISABLE_WAL = TRUE";
+ assertImmutableRows(conn1, viewFullName, false);
+ ddl = "ALTER VIEW " + viewFullName + " SET DISABLE_WAL = TRUE";
try {
conn1.createStatement().execute(ddl);
fail();
@@ -1397,7 +1385,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSettingPropertiesWhenTableHasDefaultColFamilySpecified() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE T11 (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1406,12 +1394,13 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) IMMUTABLE_ROWS=true, DEFAULT_COLUMN_FAMILY = 'XYZ'";
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.createStatement().execute(ddl);
- assertImmutableRows(conn, "T11", true);
- ddl = "ALTER TABLE T11 SET COMPACTION_ENABLED = FALSE, CF.REPLICATION_SCOPE=1, IMMUTABLE_ROWS = TRUE, TTL=1000";
+ assertImmutableRows(conn, dataTableFullName, true);
+ ddl = "ALTER TABLE " + dataTableFullName
+ + " SET COMPACTION_ENABLED = FALSE, CF.REPLICATION_SCOPE=1, IMMUTABLE_ROWS = TRUE, TTL=1000";
conn.createStatement().execute(ddl);
- assertImmutableRows(conn, "T11", true);
+ assertImmutableRows(conn, dataTableFullName, true);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("T11"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("CF", columnFamilies[0].getNameAsString());
@@ -1427,7 +1416,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testNewColumnFamilyInheritsTTLOfEmptyCF() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- String ddl = "CREATE TABLE NEWCFTTLTEST (\n"
+ String ddl = "CREATE TABLE " + dataTableFullName + " (\n"
+"ID1 VARCHAR(15) NOT NULL,\n"
+"ID2 VARCHAR(15) NOT NULL,\n"
+"CREATED_DATE DATE,\n"
@@ -1436,10 +1425,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+"CONSTRAINT PK PRIMARY KEY (ID1, ID2)) SALT_BUCKETS = 8, TTL = 1000";
Connection conn1 = DriverManager.getConnection(getUrl(), props);
conn1.createStatement().execute(ddl);
- ddl = "ALTER TABLE NEWCFTTLTEST ADD CF.STRING VARCHAR";
+ ddl = "ALTER TABLE " + dataTableFullName + " ADD CF.STRING VARCHAR";
conn1.createStatement().execute(ddl);
try (HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("NEWCFTTLTEST"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
@@ -1458,14 +1447,17 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnForExistingColumnFamily() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE SETPROPEXISTINGCF " +
+ String ddl = "CREATE TABLE " + dataTableFullName
+ +
" (a_string varchar not null, col1 integer, CF.col2 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE SETPROPEXISTINGCF ADD CF.col3 integer CF.IN_MEMORY=true");
+ conn.createStatement().execute(
+ "ALTER TABLE " + dataTableFullName + " ADD CF.col3 integer CF.IN_MEMORY=true");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPEXISTINGCF")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertFalse(columnFamilies[0].isInMemory());
@@ -1481,14 +1473,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnForNewAndExistingColumnFamily() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE SETPROPNEWEXISTCF " +
+ String ddl = "CREATE TABLE " + dataTableFullName + " "
+ +
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE SETPROPNEWEXISTCF ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false ");
+ conn.createStatement()
+ .execute(
+ "ALTER TABLE "
+ + dataTableFullName
+ + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false ");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWEXISTCF")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(3, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertTrue(columnFamilies[0].isInMemory());
@@ -1509,14 +1507,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnWhenTableHasExplicitDefaultColumnFamily() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE SETPROPNEWEXISTDEFCOLFAM " +
+ String ddl = "CREATE TABLE " + dataTableFullName + " "
+ +
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE SETPROPNEWEXISTDEFCOLFAM ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false, XYZ.REPLICATION_SCOPE=1 ");
+ conn.createStatement()
+ .execute(
+ "ALTER TABLE "
+ + dataTableFullName
+ + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer IN_MEMORY=true, CF1.REPLICATION_SCOPE=1, CF2.IN_MEMORY=false, XYZ.REPLICATION_SCOPE=1 ");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPNEWEXISTDEFCOLFAM")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(3, columnFamilies.length);
assertEquals("CF1", columnFamilies[0].getNameAsString());
assertTrue(columnFamilies[0].isInMemory());
@@ -1537,13 +1541,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnFailsForColumnFamilyNotPresentInAddCol() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE ADDCOLNOTPRESENT " +
+ String ddl = "CREATE TABLE " + dataTableFullName + " "
+ +
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
try {
conn.createStatement().execute(ddl);
try {
- conn.createStatement().execute("ALTER TABLE ADDCOLNOTPRESENT ADD col4 integer CF1.REPLICATION_SCOPE=1, XYZ.IN_MEMORY=true ");
+ conn.createStatement().execute(
+ "ALTER TABLE " + dataTableFullName
+ + " ADD col4 integer CF1.REPLICATION_SCOPE=1, XYZ.IN_MEMORY=true ");
fail();
} catch(SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_SET_PROPERTY_FOR_COLUMN_NOT_ADDED.getErrorCode(), e.getErrorCode());
@@ -1557,14 +1564,20 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnForDifferentColumnFamilies() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE XYZ.SETPROPDIFFCFSTABLE " +
+ String ddl = "CREATE TABLE " + dataTableFullName
+ +
" (a_string varchar not null, col1 integer, CF1.col2 integer, CF2.col3 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE XYZ.SETPROPDIFFCFSTABLE ADD col4 integer, CF1.col5 integer, CF2.col6 integer, CF3.col7 integer CF1.REPLICATION_SCOPE=1, CF1.IN_MEMORY=false, IN_MEMORY=true ");
+ conn.createStatement()
+ .execute(
+ "ALTER TABLE "
+ + dataTableFullName
+ + " ADD col4 integer, CF1.col5 integer, CF2.col6 integer, CF3.col7 integer CF1.REPLICATION_SCOPE=1, CF1.IN_MEMORY=false, IN_MEMORY=true ");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(SchemaUtil.getTableName("XYZ", "SETPROPDIFFCFSTABLE"))).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(4, columnFamilies.length);
assertEquals("CF1", columnFamilies[0].getNameAsString());
assertFalse(columnFamilies[0].isInMemory());
@@ -1588,15 +1601,19 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
public void testSetPropertyAndAddColumnUsingDefaultColumnFamilySpecifier() throws Exception {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE SETPROPDEFCF " +
+ String ddl = "CREATE TABLE " + dataTableFullName
+ +
" (a_string varchar not null, col1 integer, CF1.col2 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string)) DEFAULT_COLUMN_FAMILY = 'XYZ'\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE SETPROPDEFCF ADD col4 integer XYZ.REPLICATION_SCOPE=1 ");
- conn.createStatement().execute("ALTER TABLE SETPROPDEFCF ADD XYZ.col5 integer IN_MEMORY=true ");
+ conn.createStatement().execute(
+ "ALTER TABLE " + dataTableFullName + " ADD col4 integer XYZ.REPLICATION_SCOPE=1 ");
+ conn.createStatement()
+ .execute("ALTER TABLE " + dataTableFullName + " ADD XYZ.col5 integer IN_MEMORY=true ");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("SETPROPDEFCF")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(2, columnFamilies.length);
assertEquals("CF1", columnFamilies[0].getNameAsString());
assertFalse(columnFamilies[0].isInMemory());
@@ -1615,14 +1632,15 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
- String ddl = "CREATE TABLE TT " +
+ String ddl = "CREATE TABLE " + dataTableFullName +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
try {
conn.createStatement().execute(ddl);
- conn.createStatement().execute("ALTER TABLE TT ADD col2 integer IN_MEMORY=true");
+ conn.createStatement().execute("ALTER TABLE " + dataTableFullName + " ADD col2 integer IN_MEMORY=true");
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes("TT")).getColumnFamilies();
+ HColumnDescriptor[] columnFamilies = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName))
+ .getColumnFamilies();
assertEquals(1, columnFamilies.length);
assertEquals("0", columnFamilies[0].getNameAsString());
assertTrue(columnFamilies[0].isInMemory());
@@ -1641,15 +1659,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
try {
conn.createStatement()
.execute(
- "CREATE TABLE mixed_add_table "
+ "CREATE TABLE "
+ + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+ " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
- String ddl = "Alter table mixed_add_table add cf3.col5 integer, cf4.col6 integer in_memory=true";
+ String ddl = "Alter table " + dataTableFullName + " add cf3.col5 integer, cf4.col6 integer in_memory=true";
conn.createStatement().execute(ddl);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("MIXED_ADD_TABLE"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
assertTrue(tableDesc.isCompactionEnabled());
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(5, columnFamilies.length);
@@ -1678,15 +1697,16 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
try {
conn.createStatement()
.execute(
- "CREATE TABLE exist_table "
+ "CREATE TABLE "
+ + dataTableFullName
+ " (a_string varchar not null, col1 integer, cf1.col2 integer, col3 integer , cf2.col4 integer "
+ " CONSTRAINT pk PRIMARY KEY (a_string)) immutable_rows=true , SALT_BUCKETS=3 ");
- String ddl = "Alter table exist_table add cf1.col5 integer in_memory=true";
+ String ddl = "Alter table " + dataTableFullName + " add cf1.col5 integer in_memory=true";
conn.createStatement().execute(ddl);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("EXIST_TABLE"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
assertTrue(tableDesc.isCompactionEnabled());
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(3, columnFamilies.length);
@@ -1709,9 +1729,10 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE exist_test (pk char(2) not null primary key, col1 integer, b.col1 integer) SPLIT ON ('EA','EZ')";
+ String ddl = "CREATE TABLE " + dataTableFullName
+ + " (pk char(2) not null primary key, col1 integer, b.col1 integer) SPLIT ON ('EA','EZ')";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE exist_test add b.col2 varchar ttl=30";
+ ddl = "ALTER TABLE " + dataTableFullName + " add b.col2 varchar ttl=30";
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
@@ -1728,16 +1749,17 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE ttl_test (pk char(2) not null primary key) TTL=100 SPLIT ON ('EA','EZ')";
+ String ddl = "CREATE TABLE " + dataTableFullName
+ + " (pk char(2) not null primary key) TTL=100 SPLIT ON ('EA','EZ')";
conn.createStatement().execute(ddl);
- ddl = "ALTER TABLE ttl_test add col1 varchar ttl=30";
+ ddl = "ALTER TABLE " + dataTableFullName + " add col1 varchar ttl=30";
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_SET_TABLE_PROPERTY_ADD_COLUMN.getErrorCode(), e.getErrorCode());
}
try {
- String ddl = "ALTER TABLE ttl_test add col1 varchar a.ttl=30";
+ String ddl = "ALTER TABLE " + dataTableFullName + " add col1 varchar a.ttl=30";
conn.createStatement().execute(ddl);
fail();
} catch (SQLException e) {
@@ -1753,7 +1775,7 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "create table IF NOT EXISTS ttl_test2 ("
+ String ddl = "create table " + dataTableFullName + " ("
+ " id char(1) NOT NULL,"
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
@@ -1761,17 +1783,17 @@ public class AlterTableIT extends BaseOwnClusterHBaseManagedTimeIT {
+ " ) TTL=86400, SALT_BUCKETS = 4, DEFAULT_COLUMN_FAMILY='XYZ'";
conn.createStatement().execute(ddl);
try (HBaseAdmin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
- HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes("TTL_TEST2"));
+ HTableDescriptor tableDesc = admin.getTableDescriptor(Bytes.toBytes(dataTableFullName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals(1, columnFamilies.lengt
<TRUNCATED>
[6/6] phoenix git commit: PHOENIX-3291 Do not throw return value of
Throwables#propagate call
Posted by ja...@apache.org.
PHOENIX-3291 Do not throw return value of Throwables#propagate call
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/553a5871
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/553a5871
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/553a5871
Branch: refs/heads/master
Commit: 553a5871e3c8e2277cebd9f2561b1f2899d1e6d5
Parents: 4c8bda1
Author: James Taylor <ja...@apache.org>
Authored: Fri Sep 16 21:25:00 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Sep 17 00:07:28 2016 -0700
----------------------------------------------------------------------
.../main/java/org/apache/phoenix/jdbc/PhoenixStatement.java | 6 ++++--
.../apache/phoenix/mapreduce/FormatToBytesWritableMapper.java | 3 ++-
.../org/apache/phoenix/query/ConnectionQueryServicesImpl.java | 2 +-
.../main/java/org/apache/phoenix/util/CSVCommonsLoader.java | 2 +-
.../java/org/apache/phoenix/util/PhoenixContextExecutor.java | 6 +++---
5 files changed, 11 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index 0c154e2..0fbc81a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -314,7 +314,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
}, PhoenixContextExecutor.inContext());
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, SQLException.class);
- throw Throwables.propagate(e);
+ Throwables.propagate(e);
+ throw new IllegalStateException(); // Can't happen as Throwables.propagate() always throws
}
}
@@ -367,7 +368,8 @@ public class PhoenixStatement implements Statement, SQLCloseable {
Tracing.withTracing(connection, this.toString()));
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, SQLException.class);
- throw Throwables.propagate(e);
+ Throwables.propagate(e);
+ throw new IllegalStateException(); // Can't happen as Throwables.propagate() always throws
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
index cacbce7..b12326a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
@@ -28,6 +28,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
+
import javax.annotation.Nullable;
import org.apache.hadoop.conf.Configuration;
@@ -379,7 +380,7 @@ public abstract class FormatToBytesWritableMapper<RECORD> extends Mapper<LongWri
LOG.error("Error on record " + record, throwable);
context.getCounter(COUNTER_GROUP_NAME, "Errors on records").increment(1L);
if (!ignoreRecordErrors) {
- throw Throwables.propagate(throwable);
+ Throwables.propagate(throwable);
}
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 767a600..1aa9b88 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -2786,7 +2786,7 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
});
} catch (Exception e) {
Throwables.propagateIfInstanceOf(e, SQLException.class);
- throw Throwables.propagate(e);
+ Throwables.propagate(e);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
index cdd9d7b..23f123e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/CSVCommonsLoader.java
@@ -292,7 +292,7 @@ public class CSVCommonsLoader {
public void errorOnRecord(CSVRecord csvRecord, Throwable throwable) {
LOG.error("Error upserting record " + csvRecord, throwable.getMessage());
if (strict) {
- throw Throwables.propagate(throwable);
+ Throwables.propagate(throwable);
}
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/553a5871/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
index 2da3249..cd12261 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixContextExecutor.java
@@ -21,8 +21,6 @@ import java.util.concurrent.Callable;
import org.apache.phoenix.call.CallWrapper;
-import com.google.common.base.Throwables;
-
/**
* Executes {@code Callable}s using a context classloader that is set up to load classes from
* Phoenix.
@@ -91,8 +89,10 @@ public class PhoenixContextExecutor {
public static <T> T callWithoutPropagation(Callable<T> target) {
try {
return call(target);
+ } catch (RuntimeException e) {
+ throw e;
} catch (Exception e) {
- throw Throwables.propagate(e);
+ throw new RuntimeException(e);
}
}
[5/6] phoenix git commit: PHOENIX-3290 Move and/or combine as many
NeedsOwnCluster tests to bring down test run time
Posted by ja...@apache.org.
PHOENIX-3290 Move and/or combine as many NeedsOwnCluster tests to bring down test run time
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/14d16c85
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/14d16c85
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/14d16c85
Branch: refs/heads/master
Commit: 14d16c8534f8807680b345bcb1b47fa4d03e522c
Parents: 553a587
Author: James Taylor <ja...@apache.org>
Authored: Sat Sep 17 00:05:06 2016 -0700
Committer: James Taylor <ja...@apache.org>
Committed: Sat Sep 17 00:07:28 2016 -0700
----------------------------------------------------------------------
.../apache/phoenix/end2end/AlterTableIT.java | 705 ++++++++++---------
.../org/apache/phoenix/end2end/BaseViewIT.java | 1 -
.../phoenix/end2end/CsvBulkLoadToolIT.java | 6 +-
.../apache/phoenix/end2end/IndexExtendedIT.java | 578 +++++++++++++++
.../org/apache/phoenix/end2end/IndexToolIT.java | 257 -------
.../org/apache/phoenix/end2end/KeyOnlyIT.java | 5 +-
.../phoenix/end2end/MultiCfQueryExecIT.java | 1 -
.../phoenix/end2end/MutableIndexToolIT.java | 129 ----
.../phoenix/end2end/RoundFloorCeilFuncIT.java | 683 ++++++++++++++++++
.../RoundFloorCeilFunctionsEnd2EndIT.java | 686 ------------------
.../phoenix/end2end/TransactionalViewIT.java | 5 +-
.../org/apache/phoenix/end2end/UnionAllIT.java | 288 ++++----
.../index/ImmutableIndexWithStatsIT.java | 5 +-
.../end2end/index/IndexOnOwnClusterIT.java | 324 ---------
.../org/apache/phoenix/tx/TransactionIT.java | 8 +-
.../java/org/apache/phoenix/query/BaseTest.java | 30 -
16 files changed, 1802 insertions(+), 1909 deletions(-)
----------------------------------------------------------------------
[3/6] phoenix git commit: PHOENIX-3290 Move and/or combine as many
NeedsOwnCluster tests to bring down test run time
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
index d9a59a9..a3c36fa 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseViewIT.java
@@ -69,7 +69,6 @@ public abstract class BaseViewIT extends BaseOwnClusterHBaseManagedTimeIT {
public static void doSetup() throws Exception {
Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Integer.toString(20));
- props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(1024));
props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
index 8968555..4971fc3 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
@@ -40,7 +40,9 @@ import org.apache.phoenix.mapreduce.CsvBulkLoadTool;
import org.apache.phoenix.query.QueryServices;
import org.apache.phoenix.query.QueryServicesOptions;
import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.TestUtil;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -57,8 +59,8 @@ public class CsvBulkLoadToolIT extends BaseOwnClusterHBaseManagedTimeIT {
serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
clientProps.put(QueryServices.TRANSACTIONS_ENABLED, "true");
- setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
- zkQuorum = "localhost:" + getUtility().getZkCluster().getClientPort();
+ setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
+ zkQuorum = TestUtil.LOCALHOST + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + getUtility().getZkCluster().getClientPort();
conn = DriverManager.getConnection(getUrl());
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
new file mode 100644
index 0000000..b23e342
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexExtendedIT.java
@@ -0,0 +1,578 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.MetaTableAccessor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.mapreduce.index.IndexTool;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.ByteUtil;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+/**
+ * Tests for the {@link IndexTool}
+ */
+@RunWith(Parameterized.class)
+public class IndexExtendedIT extends BaseOwnClusterHBaseManagedTimeIT {
+ private final boolean localIndex;
+ private final boolean transactional;
+ private final boolean directApi;
+ private final String tableDDLOptions;
+ private final boolean mutable;
+
+ public IndexExtendedIT(boolean transactional, boolean mutable, boolean localIndex, boolean directApi) {
+ this.localIndex = localIndex;
+ this.transactional = transactional;
+ this.directApi = directApi;
+ this.mutable = mutable;
+ StringBuilder optionBuilder = new StringBuilder();
+ if (!mutable) {
+ optionBuilder.append(" IMMUTABLE_ROWS=true ");
+ }
+ if (transactional) {
+ if (!(optionBuilder.length()==0)) {
+ optionBuilder.append(",");
+ }
+ optionBuilder.append(" TRANSACTIONAL=true ");
+ }
+ optionBuilder.append(" SPLIT ON(1,2)");
+ this.tableDDLOptions = optionBuilder.toString();
+ }
+
+ @BeforeClass
+ public static void doSetup() throws Exception {
+ Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
+ serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
+ Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
+ clientProps.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
+ setUpTestDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet()
+ .iterator()));
+ }
+
+ @Parameters(name="transactional = {0} , mutable = {1} , localIndex = {2}, directApi = {3}")
+ public static Collection<Boolean[]> data() {
+ return Arrays.asList(new Boolean[][] {
+ { false, false, false, false }, { false, false, false, true }, { false, false, true, false }, { false, false, true, true },
+ { false, true, false, false }, { false, true, false, true }, { false, true, true, false }, { false, true, true, true },
+ { true, false, false, false }, { true, false, false, true }, { true, false, true, false }, { true, false, true, true },
+ { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, { true, true, true, true }
+ });
+ }
+
+ /**
+ * This test is to assert that updates that happen to rows of a mutable table after an index is created in ASYNC mode and before
+ * the MR job runs, do show up in the index table .
+ * @throws Exception
+ */
+ @Test
+ public void testMutableIndexWithUpdates() throws Exception {
+ if (!mutable || transactional) {
+ return;
+ }
+ String schemaName = generateRandomString();
+ String dataTableName = generateRandomString();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+ String indexTableName = generateRandomString();
+ String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ Statement stmt = conn.createStatement();
+ try {
+ stmt.execute(String.format("CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER)",dataTableFullName));
+ String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)",dataTableFullName);
+ PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
+
+ int id = 1;
+ // insert two rows
+ IndexExtendedIT.upsertRow(stmt1, id++);
+ IndexExtendedIT.upsertRow(stmt1, id++);
+ conn.commit();
+
+ stmt.execute(String.format("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX %s ON %s (UPPER(NAME)) ASYNC ", indexTableName,dataTableFullName));
+
+ //update a row
+ stmt1.setInt(1, 1);
+ stmt1.setString(2, "uname" + String.valueOf(10));
+ stmt1.setInt(3, 95050 + 1);
+ stmt1.executeUpdate();
+ conn.commit();
+
+ //verify rows are fetched from data table.
+ String selectSql = String.format("SELECT ID FROM %s WHERE UPPER(NAME) ='UNAME2'",dataTableFullName);
+ ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+ String actualExplainPlan = QueryUtil.getExplainPlan(rs);
+
+ //assert we are pulling from data table.
+ assertEquals(String.format("CLIENT PARALLEL 1-WAY FULL SCAN OVER %s\n" +
+ " SERVER FILTER BY UPPER(NAME) = 'UNAME2'",dataTableFullName),actualExplainPlan);
+
+ rs = stmt1.executeQuery(selectSql);
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+ assertFalse(rs.next());
+
+ //run the index MR job.
+ runIndexTool(schemaName, dataTableName, indexTableName);
+
+ //assert we are pulling from index table.
+ rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+ actualExplainPlan = QueryUtil.getExplainPlan(rs);
+ // TODO: why is it a 1-WAY parallel scan only for !transactional && mutable && localIndex
+ assertExplainPlan(actualExplainPlan, dataTableFullName, indexTableFullName);
+
+ rs = stmt.executeQuery(selectSql);
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ private void runIndexTool(String schemaName, String dataTableName, String indexTableName) throws Exception {
+ IndexTool indexingTool = new IndexTool();
+ Configuration conf = new Configuration(getUtility().getConfiguration());
+ conf.set(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
+ indexingTool.setConf(conf);
+ final String[] cmdArgs = getArgValues(schemaName, dataTableName, indexTableName);
+ int status = indexingTool.run(cmdArgs);
+ assertEquals(0, status);
+ }
+
+ @Test
+ public void testSecondaryIndex() throws Exception {
+ String schemaName = generateRandomString();
+ String dataTableName = generateRandomString();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+ String indexTableName = generateRandomString();
+ String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ String stmString1 = "CREATE TABLE " + dataTableFullName + " (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER) " + tableDDLOptions;
+ conn.createStatement().execute(stmString1);
+ String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)", dataTableFullName);
+ PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
+
+ // insert two rows
+ upsertRow(stmt1, 1);
+ upsertRow(stmt1, 2);
+ conn.commit();
+
+ if (transactional) {
+ // insert two rows in another connection without committing so that they are not visible to other transactions
+ try (Connection conn2 = DriverManager.getConnection(getUrl(), props)) {
+ conn2.setAutoCommit(false);
+ PreparedStatement stmt2 = conn2.prepareStatement(upsertQuery);
+ upsertRow(stmt2, 5);
+ upsertRow(stmt2, 6);
+ ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) from "+dataTableFullName);
+ assertTrue(rs.next());
+ assertEquals("Unexpected row count ", 2, rs.getInt(1));
+ assertFalse(rs.next());
+ rs = conn2.createStatement().executeQuery("SELECT count(*) from "+dataTableFullName);
+ assertTrue(rs.next());
+ assertEquals("Unexpected row count ", 4, rs.getInt(1));
+ assertFalse(rs.next());
+ }
+ }
+
+ String stmtString2 = String.format("CREATE %s INDEX %s ON %s (LPAD(UPPER(NAME),8,'x')||'_xyz') ASYNC ", (localIndex ? "LOCAL" : ""), indexTableName, dataTableFullName);
+ conn.createStatement().execute(stmtString2);
+
+ //verify rows are fetched from data table.
+ String selectSql = String.format("SELECT ID FROM %s WHERE LPAD(UPPER(NAME),8,'x')||'_xyz' = 'xxUNAME2_xyz'", dataTableFullName);
+ ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+ String actualExplainPlan = QueryUtil.getExplainPlan(rs);
+
+ //assert we are pulling from data table.
+ assertEquals(
+ String.format("CLIENT PARALLEL 1-WAY FULL SCAN OVER %s\n"
+ + " SERVER FILTER BY (LPAD(UPPER(NAME), 8, 'x') || '_xyz') = 'xxUNAME2_xyz'", dataTableFullName), actualExplainPlan);
+
+ rs = stmt1.executeQuery(selectSql);
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+ assertFalse(rs.next());
+ conn.commit();
+
+ //run the index MR job.
+ runIndexTool(schemaName, dataTableName, indexTableName);
+
+ // insert two more rows
+ upsertRow(stmt1, 3);
+ upsertRow(stmt1, 4);
+ conn.commit();
+
+ //assert we are pulling from index table.
+ rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
+ actualExplainPlan = QueryUtil.getExplainPlan(rs);
+ assertExplainPlan(actualExplainPlan, dataTableFullName, indexTableFullName);
+
+ rs = conn.createStatement().executeQuery(selectSql);
+ assertTrue(rs.next());
+ assertEquals(2, rs.getInt(1));
+ assertFalse(rs.next());
+ } finally {
+ conn.close();
+ }
+ }
+
+ private void assertExplainPlan(final String actualExplainPlan, String dataTableFullName, String indexTableFullName) {
+ String expectedExplainPlan;
+ if(localIndex) {
+ expectedExplainPlan = String.format(" RANGE SCAN OVER %s [1,",
+ dataTableFullName);
+ } else {
+ expectedExplainPlan = String.format(" RANGE SCAN OVER %s",
+ indexTableFullName);
+ }
+ assertTrue(actualExplainPlan + "\n expected to contain \n" + expectedExplainPlan, actualExplainPlan.contains(expectedExplainPlan));
+ }
+
+ private String[] getArgValues(String schemaName, String dataTable, String indxTable) {
+ final List<String> args = Lists.newArrayList();
+ if (schemaName!=null) {
+ args.add("-s");
+ args.add(schemaName);
+ }
+ args.add("-dt");
+ args.add(dataTable);
+ args.add("-it");
+ args.add(indxTable);
+ if(directApi) {
+ args.add("-direct");
+ // Need to run this job in foreground for the test to be deterministic
+ args.add("-runfg");
+ }
+
+ args.add("-op");
+ args.add("/tmp/"+UUID.randomUUID().toString());
+ return args.toArray(new String[0]);
+ }
+
+ private static void upsertRow(PreparedStatement stmt, int i) throws SQLException {
+ // insert row
+ stmt.setInt(1, i);
+ stmt.setString(2, "uname" + String.valueOf(i));
+ stmt.setInt(3, 95050 + i);
+ stmt.executeUpdate();
+ }
+
+ @Test
+ public void testDeleteFromImmutable() throws Exception {
+ if (transactional || mutable) {
+ return;
+ }
+ if (localIndex) { // TODO: remove this return once PHOENIX-3292 is fixed
+ return;
+ }
+ String schemaName = generateRandomString();
+ String dataTableName = generateRandomString();
+ String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+ String indexTableName = generateRandomString();
+ String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ conn.createStatement().execute("CREATE TABLE " + dataTableFullName + " (\n" +
+ " pk1 VARCHAR NOT NULL,\n" +
+ " pk2 VARCHAR NOT NULL,\n" +
+ " pk3 VARCHAR\n" +
+ " CONSTRAINT PK PRIMARY KEY \n" +
+ " (\n" +
+ " pk1,\n" +
+ " pk2,\n" +
+ " pk3\n" +
+ " )\n" +
+ " ) IMMUTABLE_ROWS=true");
+ conn.createStatement().execute("upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('a', '1', '1')");
+ conn.createStatement().execute("upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('b', '2', '2')");
+ conn.commit();
+ conn.createStatement().execute("CREATE " + (localIndex ? "LOCAL" : "") + " INDEX " + indexTableName + " ON " + dataTableFullName + " (pk3, pk2) ASYNC");
+
+ // this delete will be issued at a timestamp later than the above timestamp of the index table
+ conn.createStatement().execute("delete from " + dataTableFullName + " where pk1 = 'a'");
+ conn.commit();
+
+ //run the index MR job.
+ runIndexTool(schemaName, dataTableName, indexTableName);
+
+ // upsert two more rows
+ conn.createStatement().execute(
+ "upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('a', '3', '3')");
+ conn.createStatement().execute(
+ "upsert into " + dataTableFullName + " (pk1, pk2, pk3) values ('b', '4', '4')");
+ conn.commit();
+
+ // validate that delete markers were issued correctly and only ('a', '1', 'value1') was
+ // deleted
+ String query = "SELECT pk3 from " + dataTableFullName + " ORDER BY pk3";
+ ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + query);
+ String expectedPlan =
+ "CLIENT PARALLEL 1-WAY FULL SCAN OVER " + indexTableFullName + "\n"
+ + " SERVER FILTER BY FIRST KEY ONLY";
+ assertEquals("Wrong plan ", expectedPlan, QueryUtil.getExplainPlan(rs));
+ rs = conn.createStatement().executeQuery(query);
+ assertTrue(rs.next());
+ assertEquals("2", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("3", rs.getString(1));
+ assertTrue(rs.next());
+ assertEquals("4", rs.getString(1));
+ assertFalse(rs.next());
+ }
+ }
+
+ private Connection getConnectionForLocalIndexTest() throws SQLException{
+ Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
+ props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, Boolean.TRUE.toString());
+ return DriverManager.getConnection(getUrl(),props);
+ }
+
+ private void createBaseTable(String tableName, String splits) throws SQLException {
+ Connection conn = getConnectionForLocalIndexTest();
+ String ddl = "CREATE TABLE " + tableName + " (t_id VARCHAR NOT NULL,\n" +
+ "k1 INTEGER NOT NULL,\n" +
+ "k2 INTEGER NOT NULL,\n" +
+ "k3 INTEGER,\n" +
+ "v1 VARCHAR,\n" +
+ "CONSTRAINT pk PRIMARY KEY (t_id, k1, k2))\n"
+ + (splits != null ? (" split on " + splits) : "");
+ conn.createStatement().execute(ddl);
+ conn.close();
+ }
+
+ // Moved from LocalIndexIT because it was causing parallel runs to hang
+ @Test
+ public void testLocalIndexScanAfterRegionSplit() throws Exception {
+ // This test just needs be run once
+ if (!localIndex || transactional || mutable || directApi) {
+ return;
+ }
+ String schemaName = generateRandomString();
+ String tableName = schemaName + "." + generateRandomString();
+ String indexName = "IDX_" + generateRandomString();
+ TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
+ String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+ createBaseTable(tableName, "('e','j','o')");
+ Connection conn1 = getConnectionForLocalIndexTest();
+ try{
+ String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
+ for (int i = 0; i < 26; i++) {
+ conn1.createStatement().execute(
+ "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
+ + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
+ }
+ conn1.commit();
+ conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
+ conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
+
+ ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
+ assertTrue(rs.next());
+
+ HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+ for (int i = 1; i < 5; i++) {
+ admin.split(physicalTableName, ByteUtil.concat(Bytes.toBytes(strings[3*i])));
+ List<HRegionInfo> regionsOfUserTable =
+ MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+ physicalTableName, false);
+
+ while (regionsOfUserTable.size() != (4+i)) {
+ Thread.sleep(100);
+ regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
+ admin.getConnection(), physicalTableName, false);
+ }
+ assertEquals(4+i, regionsOfUserTable.size());
+ String[] tIdColumnValues = new String[26];
+ String[] v1ColumnValues = new String[26];
+ int[] k1ColumnValue = new int[26];
+ String query = "SELECT t_id,k1,v1 FROM " + tableName;
+ rs = conn1.createStatement().executeQuery(query);
+ Thread.sleep(1000);
+ for (int j = 0; j < 26; j++) {
+ assertTrue(rs.next());
+ tIdColumnValues[j] = rs.getString("t_id");
+ k1ColumnValue[j] = rs.getInt("k1");
+ v1ColumnValues[j] = rs.getString("V1");
+ }
+ Arrays.sort(tIdColumnValues);
+ Arrays.sort(v1ColumnValues);
+ Arrays.sort(k1ColumnValue);
+ assertTrue(Arrays.equals(strings, tIdColumnValues));
+ assertTrue(Arrays.equals(strings, v1ColumnValues));
+ for(int m=0;m<26;m++) {
+ assertEquals(m, k1ColumnValue[m]);
+ }
+
+ rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+ assertEquals(
+ "CLIENT PARALLEL " + (4 + i) + "-WAY RANGE SCAN OVER "
+ + indexPhysicalTableName + " [1]\n"
+ + " SERVER FILTER BY FIRST KEY ONLY\n"
+ + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+ query = "SELECT t_id,k1,k3 FROM " + tableName;
+ rs = conn1.createStatement().executeQuery("EXPLAIN "+query);
+ assertEquals(
+ "CLIENT PARALLEL "
+ + ((strings[3 * i].compareTo("j") < 0) ? (4 + i) : (4 + i - 1))
+ + "-WAY RANGE SCAN OVER "
+ + indexPhysicalTableName + " [2]\n"
+ + " SERVER FILTER BY FIRST KEY ONLY\n"
+ + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+ rs = conn1.createStatement().executeQuery(query);
+ Thread.sleep(1000);
+ int[] k3ColumnValue = new int[26];
+ for (int j = 0; j < 26; j++) {
+ assertTrue(rs.next());
+ tIdColumnValues[j] = rs.getString("t_id");
+ k1ColumnValue[j] = rs.getInt("k1");
+ k3ColumnValue[j] = rs.getInt("k3");
+ }
+ Arrays.sort(tIdColumnValues);
+ Arrays.sort(k1ColumnValue);
+ Arrays.sort(k3ColumnValue);
+ assertTrue(Arrays.equals(strings, tIdColumnValues));
+ for(int m=0;m<26;m++) {
+ assertEquals(m, k1ColumnValue[m]);
+ assertEquals(m+2, k3ColumnValue[m]);
+ }
+ }
+ } finally {
+ conn1.close();
+ }
+ }
+
+ // Moved from LocalIndexIT because it was causing parallel runs to hang
+ @Test
+ public void testLocalIndexScanAfterRegionsMerge() throws Exception {
+ // This test just needs be run once
+ if (!localIndex || transactional || mutable || directApi) {
+ return;
+ }
+ String schemaName = generateRandomString();
+ String tableName = schemaName + "." + generateRandomString();
+ String indexName = "IDX_" + generateRandomString();
+ TableName physicalTableName = SchemaUtil.getPhysicalTableName(tableName.getBytes(), false);
+ String indexPhysicalTableName = physicalTableName.getNameAsString();
+
+ createBaseTable(tableName, "('e','j','o')");
+ Connection conn1 = getConnectionForLocalIndexTest();
+ try{
+ String[] strings = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
+ for (int i = 0; i < 26; i++) {
+ conn1.createStatement().execute(
+ "UPSERT INTO " + tableName + " values('"+strings[i]+"'," + i + ","
+ + (i + 1) + "," + (i + 2) + ",'" + strings[25 - i] + "')");
+ }
+ conn1.commit();
+ conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + " ON " + tableName + "(v1)");
+ conn1.createStatement().execute("CREATE LOCAL INDEX " + indexName + "_2 ON " + tableName + "(k3)");
+
+ ResultSet rs = conn1.createStatement().executeQuery("SELECT * FROM " + tableName);
+ assertTrue(rs.next());
+
+ HBaseAdmin admin = conn1.unwrap(PhoenixConnection.class).getQueryServices().getAdmin();
+ List<HRegionInfo> regionsOfUserTable =
+ MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+ physicalTableName, false);
+ admin.mergeRegions(regionsOfUserTable.get(0).getEncodedNameAsBytes(),
+ regionsOfUserTable.get(1).getEncodedNameAsBytes(), false);
+ regionsOfUserTable =
+ MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(), admin.getConnection(),
+ physicalTableName, false);
+
+ while (regionsOfUserTable.size() != 3) {
+ Thread.sleep(100);
+ regionsOfUserTable = MetaTableAccessor.getTableRegions(getUtility().getZooKeeperWatcher(),
+ admin.getConnection(), physicalTableName, false);
+ }
+ String query = "SELECT t_id,k1,v1 FROM " + tableName;
+ rs = conn1.createStatement().executeQuery(query);
+ Thread.sleep(1000);
+ for (int j = 0; j < 26; j++) {
+ assertTrue(rs.next());
+ assertEquals(strings[25 - j], rs.getString("t_id"));
+ assertEquals(25 - j, rs.getInt("k1"));
+ assertEquals(strings[j], rs.getString("V1"));
+ }
+ rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+ assertEquals(
+ "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
+ + indexPhysicalTableName
+ + " [1]\n" + " SERVER FILTER BY FIRST KEY ONLY\n"
+ + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+ query = "SELECT t_id,k1,k3 FROM " + tableName;
+ rs = conn1.createStatement().executeQuery("EXPLAIN " + query);
+ assertEquals(
+ "CLIENT PARALLEL " + 3 + "-WAY RANGE SCAN OVER "
+ + indexPhysicalTableName
+ + " [2]\n" + " SERVER FILTER BY FIRST KEY ONLY\n"
+ + "CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
+
+ rs = conn1.createStatement().executeQuery(query);
+ Thread.sleep(1000);
+ for (int j = 0; j < 26; j++) {
+ assertTrue(rs.next());
+ assertEquals(strings[j], rs.getString("t_id"));
+ assertEquals(j, rs.getInt("k1"));
+ assertEquals(j + 2, rs.getInt("k3"));
+ }
+ } finally {
+ conn1.close();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
deleted file mode 100644
index 16db876..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.apache.phoenix.util.SchemaUtil;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
-/**
- * Tests for the {@link IndexTool}
- */
-@RunWith(Parameterized.class)
-public class IndexToolIT extends BaseOwnClusterHBaseManagedTimeIT {
-
- private final String schemaName;
- private final String dataTable;
-
- private final boolean localIndex;
- private final boolean transactional;
- private final boolean directApi;
- private final String tableDDLOptions;
-
- public IndexToolIT(boolean transactional, boolean localIndex, boolean mutable, boolean directApi) {
- this.schemaName = "S";
- this.dataTable = "T" + (transactional ? "_TXN" : "");
- this.localIndex = localIndex;
- this.transactional = transactional;
- this.directApi = directApi;
- StringBuilder optionBuilder = new StringBuilder();
- if (!mutable)
- optionBuilder.append(" IMMUTABLE_ROWS=true ");
- if (transactional) {
- if (!(optionBuilder.length()==0))
- optionBuilder.append(",");
- optionBuilder.append(" TRANSACTIONAL=true ");
- }
- optionBuilder.append(" SPLIT ON(1,2)");
- this.tableDDLOptions = optionBuilder.toString();
- }
-
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
- serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
- Map<String, String> clientProps = Maps.newHashMapWithExpectedSize(1);
- clientProps.put(QueryServices.TRANSACTIONS_ENABLED, "true");
- setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), new ReadOnlyProps(clientProps.entrySet().iterator()));
- }
-
- @Parameters(name="transactional = {0} , mutable = {1} , localIndex = {2}, directApi = {3}")
- public static Collection<Boolean[]> data() {
- return Arrays.asList(new Boolean[][] {
- { false, false, false, false }, { false, false, false, true }, { false, false, true, false }, { false, false, true, true },
- { false, true, false, false }, { false, true, false, true }, { false, true, true, false }, { false, true, true, true },
- { true, false, false, false }, { true, false, false, true }, { true, false, true, false }, { true, false, true, true },
- { true, true, false, false }, { true, true, false, true }, { true, true, true, false }, { true, true, true, true }
- });
- }
-
- @Test
- public void testSecondaryIndex() throws Exception {
- final String fullTableName = SchemaUtil.getTableName(schemaName, dataTable);
- final String indxTable = String.format("%s_%s", dataTable, "INDX");
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
- props.setProperty(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB, Boolean.FALSE.toString());
- Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement();
- try {
-
- stmt.execute(String.format("CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER) %s", fullTableName, tableDDLOptions));
- String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)", fullTableName);
- PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
-
- // insert two rows
- upsertRow(stmt1, 1);
- upsertRow(stmt1, 2);
- conn.commit();
-
- if (transactional) {
- // insert two rows in another connection without committing so that they are not visible to other transactions
- try (Connection conn2 = DriverManager.getConnection(getUrl(), props)) {
- conn2.setAutoCommit(false);
- PreparedStatement stmt2 = conn2.prepareStatement(upsertQuery);
- upsertRow(stmt2, 5);
- upsertRow(stmt2, 6);
- ResultSet rs = conn.createStatement().executeQuery("SELECT count(*) from "+fullTableName);
- assertTrue(rs.next());
- assertEquals("Unexpected row count ", 2, rs.getInt(1));
- assertFalse(rs.next());
- rs = conn2.createStatement().executeQuery("SELECT count(*) from "+fullTableName);
- assertTrue(rs.next());
- assertEquals("Unexpected row count ", 4, rs.getInt(1));
- assertFalse(rs.next());
- }
- }
-
- stmt.execute(String.format("CREATE %s INDEX %s ON %s (LPAD(UPPER(NAME),8,'x')||'_xyz') ASYNC ", (localIndex ? "LOCAL" : ""), indxTable, fullTableName));
-
- //verify rows are fetched from data table.
- String selectSql = String.format("SELECT LPAD(UPPER(NAME),8,'x')||'_xyz',ID FROM %s", fullTableName);
- ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
- String actualExplainPlan = QueryUtil.getExplainPlan(rs);
-
- //assert we are pulling from data table.
- assertEquals(String.format("CLIENT 3-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER %s", fullTableName), actualExplainPlan);
-
- rs = stmt1.executeQuery(selectSql);
- assertTrue(rs.next());
- assertEquals("xxUNAME1_xyz", rs.getString(1));
- assertTrue(rs.next());
- assertEquals("xxUNAME2_xyz", rs.getString(1));
- assertFalse(rs.next());
- conn.commit();
-
- //run the index MR job.
- final IndexTool indexingTool = new IndexTool();
- Configuration conf = new Configuration(getUtility().getConfiguration());
- conf.set(QueryServices.TRANSACTIONS_ENABLED, Boolean.TRUE.toString());
- indexingTool.setConf(conf);
-
- final String[] cmdArgs = getArgValues(schemaName, dataTable, indxTable, directApi);
- int status = indexingTool.run(cmdArgs);
- assertEquals(0, status);
-
- // insert two more rows
- upsertRow(stmt1, 3);
- upsertRow(stmt1, 4);
- conn.commit();
-
- rs = stmt1.executeQuery("SELECT LPAD(UPPER(NAME),8,'x')||'_xyz',ID FROM "+fullTableName);
-
- //assert we are pulling from index table.
- rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
- actualExplainPlan = QueryUtil.getExplainPlan(rs);
- assertExplainPlan(actualExplainPlan, schemaName, dataTable, indxTable, localIndex);
-
- rs = stmt.executeQuery(selectSql);
- assertTrue(rs.next());
- assertEquals("xxUNAME1_xyz", rs.getString(1));
- assertEquals(1, rs.getInt(2));
-
- assertTrue(rs.next());
- assertEquals("xxUNAME2_xyz", rs.getString(1));
- assertEquals(2, rs.getInt(2));
-
- assertTrue(rs.next());
- assertEquals("xxUNAME3_xyz", rs.getString(1));
- assertEquals(3, rs.getInt(2));
-
- assertTrue(rs.next());
- assertEquals("xxUNAME4_xyz", rs.getString(1));
- assertEquals(4, rs.getInt(2));
-
- assertFalse(rs.next());
-
- conn.createStatement().execute(String.format("DROP INDEX %s ON %s",indxTable , fullTableName));
- } finally {
- conn.close();
- }
- }
-
- public static void assertExplainPlan(final String actualExplainPlan, String schemaName, String dataTable,
- String indxTable, boolean isLocal) {
-
- String expectedExplainPlan = "";
- if(isLocal) {
- final String localIndexName = SchemaUtil.getTableName(schemaName, dataTable);
- expectedExplainPlan = String.format("CLIENT 3-CHUNK PARALLEL 3-WAY ROUND ROBIN RANGE SCAN OVER %s [1]"
- + "\n SERVER FILTER BY FIRST KEY ONLY", localIndexName);
- } else {
- expectedExplainPlan = String.format("CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER %s"
- + "\n SERVER FILTER BY FIRST KEY ONLY",SchemaUtil.getTableName(schemaName, indxTable));
- }
- assertEquals(expectedExplainPlan,actualExplainPlan);
- }
-
- public static String[] getArgValues(String schemaName, String dataTable, String indxTable) {
- return getArgValues(schemaName, dataTable, indxTable, false);
- }
-
- public static String[] getArgValues(String schemaName, String dataTable, String indxTable, boolean directApi) {
- final List<String> args = Lists.newArrayList();
- if (schemaName!=null) {
- args.add("-s");
- args.add(schemaName);
- }
- args.add("-dt");
- args.add(dataTable);
- args.add("-it");
- args.add(indxTable);
- if(directApi) {
- args.add("-direct");
- // Need to run this job in foreground for the test to be deterministic
- args.add("-runfg");
- }
-
- args.add("-op");
- args.add("/tmp/"+UUID.randomUUID().toString());
- return args.toArray(new String[0]);
- }
-
- public static void upsertRow(PreparedStatement stmt, int i) throws SQLException {
- // insert row
- stmt.setInt(1, i);
- stmt.setString(2, "uname" + String.valueOf(i));
- stmt.setInt(3, 95050 + i);
- stmt.executeUpdate();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
index 4497c49..50e0709 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/KeyOnlyIT.java
@@ -52,8 +52,7 @@ public class KeyOnlyIT extends BaseOwnClusterClientManagedTimeIT {
public static void doSetup() throws Exception {
Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
// Must update config before starting server
- props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(50));
- props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(100));
+ props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
@@ -81,7 +80,7 @@ public class KeyOnlyIT extends BaseOwnClusterClientManagedTimeIT {
assertEquals(4, rs.getInt(2));
assertFalse(rs.next());
List<KeyRange> splits = getAllSplits(conn5, "KEYONLY");
- assertEquals(2, splits.size());
+ assertEquals(3, splits.size());
conn5.close();
props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts+60));
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
index 15fc01d..b9d27ca 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MultiCfQueryExecIT.java
@@ -52,7 +52,6 @@ public class MultiCfQueryExecIT extends BaseOwnClusterClientManagedTimeIT {
Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
// Must update config before starting server
props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(20));
- props.put(QueryServices.QUEUE_SIZE_ATTRIB, Long.toString(200));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java
deleted file mode 100644
index c335ff8..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MutableIndexToolIT.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.phoenix.mapreduce.index.IndexTool;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.query.QueryServicesOptions;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import com.google.common.collect.Maps;
-
-public class MutableIndexToolIT extends BaseOwnClusterHBaseManagedTimeIT {
-
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String, String> serverProps = Maps.newHashMapWithExpectedSize(1);
- serverProps.put(QueryServices.EXTRA_JDBC_ARGUMENTS_ATTRIB, QueryServicesOptions.DEFAULT_EXTRA_JDBC_ARGUMENTS);
- setUpRealDriver(new ReadOnlyProps(serverProps.entrySet().iterator()), ReadOnlyProps.EMPTY_PROPS);
- }
-
- /**
- * This test is to assert that updates that happen to rows of a mutable table after an index is created in ASYNC mode and before
- * the MR job runs, do show up in the index table .
- * @throws Exception
- */
- @Test
- public void testMutableIndexWithUpdates() throws Exception {
-
- final String dataTable = "DATA_TABLE5";
- final String indxTable = String.format("%s_%s",dataTable,"INDX");
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(QueryServices.EXPLAIN_ROW_COUNT_ATTRIB, Boolean.FALSE.toString());
- Connection conn = DriverManager.getConnection(getUrl(), props);
- Statement stmt = conn.createStatement();
- try {
-
- stmt.execute(String.format("CREATE TABLE %s (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR, ZIP INTEGER)",dataTable));
- String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, ?)",dataTable);
- PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
-
- int id = 1;
- // insert two rows
- IndexToolIT.upsertRow(stmt1, id++);
- IndexToolIT.upsertRow(stmt1, id++);
- conn.commit();
-
- stmt.execute(String.format("CREATE INDEX %s ON %s (UPPER(NAME)) ASYNC ", indxTable,dataTable));
-
- //update a row
- stmt1.setInt(1, 1);
- stmt1.setString(2, "uname" + String.valueOf(10));
- stmt1.setInt(3, 95050 + 1);
- stmt1.executeUpdate();
- conn.commit();
-
- //verify rows are fetched from data table.
- String selectSql = String.format("SELECT UPPER(NAME),ID FROM %s",dataTable);
- ResultSet rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
- String actualExplainPlan = QueryUtil.getExplainPlan(rs);
-
- //assert we are pulling from data table.
- assertEquals(String.format("CLIENT 1-CHUNK PARALLEL 1-WAY ROUND ROBIN FULL SCAN OVER %s",dataTable),actualExplainPlan);
-
- rs = stmt1.executeQuery(selectSql);
- assertTrue(rs.next());
- assertEquals("UNAME10", rs.getString(1));
- assertTrue(rs.next());
- assertEquals("UNAME2", rs.getString(1));
-
- //run the index MR job.
- final IndexTool indexingTool = new IndexTool();
- indexingTool.setConf(new Configuration(getUtility().getConfiguration()));
-
- final String[] cmdArgs = IndexToolIT.getArgValues(null, dataTable,indxTable);
- int status = indexingTool.run(cmdArgs);
- assertEquals(0, status);
-
- //assert we are pulling from index table.
- rs = conn.createStatement().executeQuery("EXPLAIN " + selectSql);
- actualExplainPlan = QueryUtil.getExplainPlan(rs);
- IndexToolIT.assertExplainPlan(actualExplainPlan,null,dataTable,indxTable,false);
-
- rs = stmt.executeQuery(selectSql);
- assertTrue(rs.next());
- assertEquals("UNAME10", rs.getString(1));
- assertEquals(1, rs.getInt(2));
-
- assertTrue(rs.next());
- assertEquals("UNAME2", rs.getString(1));
- assertEquals(2, rs.getInt(2));
- conn.createStatement().execute(String.format("DROP INDEX %s ON %s",indxTable , dataTable));
- } finally {
- conn.close();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
new file mode 100644
index 0000000..a5251a9
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFuncIT.java
@@ -0,0 +1,683 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.sql.Connection;
+import java.sql.Date;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.util.Properties;
+
+import org.apache.phoenix.expression.function.CeilFunction;
+import org.apache.phoenix.expression.function.FloorFunction;
+import org.apache.phoenix.expression.function.RoundFunction;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.DateUtil;
+import org.apache.phoenix.util.PhoenixRuntime;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.primitives.Doubles;
+import com.google.common.primitives.Floats;
+
+/**
+ *
+ * End to end tests for {@link RoundFunction}, {@link FloorFunction}, {@link CeilFunction}
+ *
+ */
+public class RoundFloorCeilFuncIT extends BaseHBaseManagedTimeTableReuseIT {
+ private static final long millisPart = 660;
+ private static final int nanosPart = 500100;
+ private static final BigDecimal decimalUpserted = BigDecimal.valueOf(1.264);
+ private static final double doubleUpserted = 1.264d;
+ private static final double unsignedDoubleUpserted = 1.264d;
+ private static final float floatUpserted = 1.264f;
+ private static final float unsignedFloatUpserted = 1.264f;
+
+ private String tableName;
+
+ @Before
+ public void initTable() throws Exception {
+ tableName = generateRandomString();
+ String testString = "abc";
+ Connection conn = null;
+ PreparedStatement stmt = null;
+ try {
+ conn = DriverManager.getConnection(getUrl());
+ String ddl = "CREATE TABLE IF NOT EXISTS " + tableName
+ + " (s VARCHAR NOT NULL PRIMARY KEY, dt DATE, t TIME, ts TIMESTAMP, dec DECIMAL, doub DOUBLE, undoub UNSIGNED_DOUBLE, fl FLOAT, unfl UNSIGNED_FLOAT)";
+ conn.createStatement().execute(ddl);
+
+ Date dateUpserted = DateUtil.parseDate("2012-01-01 14:25:28");
+ dateUpserted = new Date(dateUpserted.getTime() + millisPart); // this makes the dateUpserted equivalent to 2012-01-01 14:25:28.660
+ long millis = dateUpserted.getTime();
+
+ Time timeUpserted = new Time(millis);
+ Timestamp tsUpserted = DateUtil.getTimestamp(millis, nanosPart);
+
+ stmt = conn.prepareStatement(
+ "UPSERT INTO " + tableName + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ stmt.setString(1, testString);
+ stmt.setDate(2, dateUpserted);
+ stmt.setTime(3, timeUpserted);
+ stmt.setTimestamp(4, tsUpserted);
+ stmt.setBigDecimal(5, decimalUpserted);
+ stmt.setDouble(6, doubleUpserted);
+ stmt.setDouble(7, unsignedDoubleUpserted);
+ stmt.setFloat(8, floatUpserted);
+ stmt.setFloat(9, unsignedFloatUpserted);
+ stmt.executeUpdate();
+ conn.commit();
+ } finally {
+ closeStmtAndConn(stmt, conn);
+ }
+ }
+
+ @Test
+ public void testRoundingUpDate() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(dt, 'day'), ROUND(dt, 'hour', 1), ROUND(dt, 'minute', 1), ROUND(dt, 'second', 1), "
+ + " ROUND(dt,'week'), ROUND(dt,'month') , ROUND(dt,'year') FROM " + tableName);
+ assertTrue(rs.next());
+ Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+ assertEquals(expectedDate, rs.getDate(1));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
+ assertEquals(expectedDate, rs.getDate(2));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
+ assertEquals(expectedDate, rs.getDate(3));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
+ assertEquals(expectedDate, rs.getDate(4));
+ expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+ assertEquals(expectedDate, rs.getDate(5));
+ expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(6));
+ expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(7));
+ }
+
+ @Test
+ public void testRoundingUpDateInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE ROUND(dt, 'day') = to_date('2012-01-02 00:00:00')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testFloorDate() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(dt, 'day', 1), FLOOR(dt, 'hour', 1), FLOOR(dt, 'minute', 1), FLOOR(dt, 'second', 1),"
+ + " FLOOR(dt,'week'), FLOOR(dt,'month'), FLOOR(dt,'year') FROM " + tableName);
+ assertTrue(rs.next());
+ Date expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(1));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
+ assertEquals(expectedDate, rs.getDate(2));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
+ assertEquals(expectedDate, rs.getDate(3));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:25:28");
+ assertEquals(expectedDate, rs.getDate(4));
+ expectedDate = DateUtil.parseDate("2011-12-26 00:00:00");
+ assertEquals(expectedDate, rs.getDate(5));
+ expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(6));
+ expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(7));
+ }
+
+ @Test
+ public void testFloorDateInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE FLOOR(dt, 'hour') = to_date('2012-01-01 14:00:00')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testCeilDate() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(dt, 'day', 1), CEIL(dt, 'hour', 1), CEIL(dt, 'minute', 1), CEIL(dt, 'second', 1), "
+ + " CEIL(dt,'week') , CEIL(dt,'month') , CEIL(dt,'year') FROM " + tableName);
+ assertTrue(rs.next());
+ //Date upserted is 2012-01-01 14:25:28.660. So we will end up bumping up in every case.
+ Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+ assertEquals(expectedDate, rs.getDate(1));
+ expectedDate = DateUtil.parseDate("2012-01-01 15:00:00");
+ assertEquals(expectedDate, rs.getDate(2));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:26:00");
+ assertEquals(expectedDate, rs.getDate(3));
+ expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
+ assertEquals(expectedDate, rs.getDate(4));
+ expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
+ System.out.println(String.format(" the expected time is [%s] and the actual time is [%s]",expectedDate.getTime(),rs.getDate(5).getTime()));
+ assertEquals(expectedDate, rs.getDate(5));
+ expectedDate = DateUtil.parseDate("2012-02-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(6));
+ expectedDate = DateUtil.parseDate("2013-01-01 00:00:00");
+ assertEquals(expectedDate, rs.getDate(7));
+ }
+
+ @Test
+ public void testCeilDateInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE CEIL(dt, 'second') = to_date('2012-01-01 14:25:29')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testRoundingUpTimestamp() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT ROUND(ts, 'day'), ROUND(ts, 'hour', 1), ROUND(ts, 'minute', 1), ROUND(ts, 'second', 1), ROUND(ts, 'millisecond', 1) FROM "
+ + tableName);
+ assertTrue(rs.next());
+ Timestamp expectedTimestamp;
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(2));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(3));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(4));
+
+ // Rounding of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date.
+ // That is, it should be evaluated as "2012-01-01 14:25:28.661".
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
+ assertEquals(expectedTimestamp, rs.getTimestamp(5));
+ }
+
+ @Test
+ public void testRoundingUpTimestampInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE ROUND(ts, 'second') = to_date('2012-01-01 14:25:29')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testFloorTimestamp() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(ts, 'day'), FLOOR(ts, 'hour', 1), FLOOR(ts, 'minute', 1), FLOOR(ts, 'second', 1), "
+ + " FLOOR(ts, 'millisecond', 1) , FLOOR(ts,'week') , FLOOR(ts,'month') FROM "
+ + tableName);
+ assertTrue(rs.next());
+ Timestamp expectedTimestamp;
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(2));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(3));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(4));
+
+ // FLOOR of "2012-01-01 14:25:28.660" + nanosPart will end up removing the nanos part.
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart);
+ assertEquals(expectedTimestamp, rs.getTimestamp(5));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(6));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(7));
+ }
+
+ @Test
+ public void testFloorTimestampInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE FLOOR(ts, 'second') = to_date('2012-01-01 14:25:28')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testWeekFloorTimestampInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE FLOOR(ts, 'week') = to_date('2011-12-26 00:00:00')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testCeilTimestamp() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(ts, 'day'), CEIL(ts, 'hour', 1), CEIL(ts, 'minute', 1), CEIL(ts, 'second', 1), CEIL(ts, 'millisecond', 1),"
+ + " CEIL(ts,'week'), CEIL(ts,'month') , CEIL(ts,'year') FROM " + tableName);
+ assertTrue(rs.next());
+ Timestamp expectedTimestamp;
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(1));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(2));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(3));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(4));
+
+ // CEIL of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date.
+ // That is, it should be evaluated as "2012-01-01 14:25:28.661".
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
+ assertEquals(expectedTimestamp, rs.getTimestamp(5));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(6));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(7));
+ expectedTimestamp = new Timestamp(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
+ assertEquals(expectedTimestamp, rs.getTimestamp(8));
+ }
+
+ @Test
+ public void testCeilTimestampInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + tableName
+ + " WHERE CEIL(ts, 'second') = to_date('2012-01-01 14:25:29')");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testRoundingUpTime() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(t, 'day', 1), ROUND(t, 'hour', 1), ROUND(t, 'minute', 1), ROUND(t, 'second', 1),"
+ + " ROUND(t,'week') , ROUND(t,'month') , ROUND(t,'year') FROM " + tableName);
+ assertTrue(rs.next());
+ Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(1));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(2));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+ assertEquals(expectedTime, rs.getTime(3));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+ assertEquals(expectedTime, rs.getTime(4));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(5));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(6));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(7));
+ }
+
+ @Test
+ public void testFloorTime() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(t, 'day', 1), FLOOR(t, 'hour', 1), FLOOR(t, 'minute', 1), FLOOR(t, 'second', 1), "
+ + " FLOOR(t, 'week'), FLOOR(t, 'month'), FLOOR(t, 'year') FROM " + tableName);
+ assertTrue(rs.next());
+ Time expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(1));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(2));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
+ assertEquals(expectedTime, rs.getTime(3));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
+ assertEquals(expectedTime, rs.getTime(4));
+ expectedTime = new Time(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(5));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(6));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(7));
+ }
+
+ @Test
+ public void testCeilTime() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(t, 'day', 1), CEIL(t, 'hour', 1), CEIL(t, 'minute', 1), CEIL(t, 'second', 1),"
+ + " CEIL(t,'week') , CEIL(t,'month') , CEIL(t,'year') FROM " + tableName);
+ assertTrue(rs.next());
+ Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(1));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(2));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
+ assertEquals(expectedTime, rs.getTime(3));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
+ assertEquals(expectedTime, rs.getTime(4));
+ expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(5));
+ expectedTime = new Time(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(6));
+ expectedTime = new Time(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
+ assertEquals(expectedTime, rs.getTime(7));
+ }
+
+ @Test
+ public void testRoundingUpDecimal() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT ROUND(dec), ROUND(dec, 1), ROUND(dec, 2), ROUND(dec, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ BigDecimal expectedBd = BigDecimal.valueOf(1);
+ assertEquals(expectedBd, rs.getBigDecimal(1));
+ expectedBd = BigDecimal.valueOf(1.3);
+ assertEquals(expectedBd, rs.getBigDecimal(2));
+ expectedBd = BigDecimal.valueOf(1.26);
+ assertEquals(expectedBd, rs.getBigDecimal(3));
+ expectedBd = BigDecimal.valueOf(1.264);
+ assertEquals(expectedBd, rs.getBigDecimal(4));
+ }
+
+ @Test
+ public void testRoundingUpDecimalInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT * FROM " + tableName + " WHERE ROUND(dec, 2) = 1.26");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testFloorDecimal() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT FLOOR(dec), FLOOR(dec, 1), FLOOR(dec, 2), FLOOR(dec, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ BigDecimal expectedBd = BigDecimal.valueOf(1);
+ assertEquals(expectedBd, rs.getBigDecimal(1));
+ expectedBd = BigDecimal.valueOf(1.2);
+ assertEquals(expectedBd, rs.getBigDecimal(2));
+ expectedBd = BigDecimal.valueOf(1.26);
+ assertEquals(expectedBd, rs.getBigDecimal(3));
+ expectedBd = BigDecimal.valueOf(1.264);
+ assertEquals(expectedBd, rs.getBigDecimal(4));
+ }
+
+ @Test
+ public void testFloorDecimalInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT * FROM " + tableName + " WHERE FLOOR(dec, 2) = 1.26");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testCeilDecimal() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT CEIL(dec), CEIL(dec, 1), CEIL(dec, 2), CEIL(dec, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ BigDecimal expectedBd = BigDecimal.valueOf(2);
+ assertEquals(expectedBd, rs.getBigDecimal(1));
+ expectedBd = BigDecimal.valueOf(1.3);
+ assertEquals(expectedBd, rs.getBigDecimal(2));
+ expectedBd = BigDecimal.valueOf(1.27);
+ assertEquals(expectedBd, rs.getBigDecimal(3));
+ expectedBd = BigDecimal.valueOf(1.264);
+ assertEquals(expectedBd, rs.getBigDecimal(4));
+ }
+
+ @Test
+ public void testCeilDecimalInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT * FROM " + tableName + " WHERE CEIL(dec, 2) = 1.27");
+ assertTrue(rs.next());
+ }
+ @Test
+ public void testRoundingUpDouble() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT ROUND(doub), ROUND(doub, 1), ROUND(doub, 2), ROUND(doub, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
+ assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
+ assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
+ assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
+ }
+
+ @Test
+ public void testRoundingUpDoubleInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT * FROM " + tableName + " WHERE ROUND(dec, 2) = 1.26");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testCeilDouble() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT CEIL(doub), CEIL(doub, 1), CEIL(doub, 2), CEIL(doub, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(0, Doubles.compare(2, rs.getDouble(1)));
+ assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
+ assertEquals(0, Doubles.compare(1.27, rs.getDouble(3)));
+ assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
+ }
+
+ @Test
+ public void testCeilDoubleInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT * FROM " + tableName + " WHERE CEIL(doub, 2) = 1.27");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testFloorDouble() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT FLOOR(doub), FLOOR(doub, 1), FLOOR(doub, 2), FLOOR(doub, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
+ assertEquals(0, Doubles.compare(1.2, rs.getDouble(2)));
+ assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
+ assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
+ }
+
+ @Test
+ public void testFloorDoubleInWhere() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT * FROM " + tableName + " WHERE FLOOR(doub, 2) = 1.26");
+ assertTrue(rs.next());
+ }
+
+ @Test
+ public void testRoundFloat() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT ROUND(fl), ROUND(fl, 1), ROUND(fl, 2), ROUND(fl, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(0, Floats.compare(1, rs.getFloat(1)));
+ assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
+ assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
+ assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
+ }
+
+ @Test
+ public void testRoundUnsignedFloat() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT ROUND(unfl), ROUND(unfl, 1), ROUND(unfl, 2), ROUND(unfl, 3) FROM " + tableName);
+ assertTrue(rs.next());
+ assertEquals(0, Floats.compare(1, rs.getFloat(1)));
+ assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
+ assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
+ assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
+ }
+
+ @Test
+ public void testRoundUnsignedDouble() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT ROUND(undoub), ROUND(undoub, 1), ROUND(undoub, 2), ROUND(undoub, 3) FROM "
+ + tableName);
+ assertTrue(rs.next());
+ assertEquals(0, Floats.compare(1, rs.getFloat(1)));
+ assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
+ assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
+ assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
+ }
+
+ @Test
+ public void testTimestampAggregateFunctions() throws Exception {
+ String dateString = "2015-03-08 09:09:11.665";
+ Properties props = new Properties();
+ props.setProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB, "GMT+1");
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ try {
+ conn.prepareStatement(
+ "create table TIME_AGG_TABLE("
+ + "ID unsigned_int NOT NULL, "
+ + "THE_DATE TIMESTAMP, "
+ + "constraint PK primary key (ID))").execute();
+ PreparedStatement stmt = conn.prepareStatement("upsert into "
+ + "TIME_AGG_TABLE(" + " ID, " + " THE_DATE)"
+ + "VALUES (?, ?)");
+ stmt.setInt(1, 1);
+ stmt.setTimestamp(2, DateUtil.parseTimestamp(dateString));
+ stmt.execute();
+ conn.commit();
+
+ ResultSet rs = conn.prepareStatement(
+ "SELECT THE_DATE ,TRUNC(THE_DATE,'DAY') AS day_from_dt "
+ + ",TRUNC(THE_DATE,'HOUR') AS hour_from_dt "
+ + ",TRUNC(THE_DATE,'MINUTE') AS min_from_dt "
+ + ",TRUNC(THE_DATE,'SECOND') AS sec_from_dt "
+ + ",TRUNC(THE_DATE,'MILLISECOND') AS mil_from_dt "
+ + "FROM TIME_AGG_TABLE").executeQuery();
+ assertTrue(rs.next());
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("THE_DATE"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
+ rs.getTimestamp("day_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
+ rs.getTimestamp("hour_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
+ rs.getTimestamp("min_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
+ rs.getTimestamp("sec_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("mil_from_dt"));
+ rs.close();
+
+ rs = conn.prepareStatement(
+ "SELECT THE_DATE ,ROUND(THE_DATE,'DAY') AS day_from_dt "
+ + ",ROUND(THE_DATE,'HOUR') AS hour_from_dt "
+ + ",ROUND(THE_DATE,'MINUTE') AS min_from_dt "
+ + ",ROUND(THE_DATE,'SECOND') AS sec_from_dt "
+ + ",ROUND(THE_DATE,'MILLISECOND') AS mil_from_dt "
+ + "FROM TIME_AGG_TABLE").executeQuery();
+ assertTrue(rs.next());
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("THE_DATE"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
+ rs.getTimestamp("day_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
+ rs.getTimestamp("hour_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
+ rs.getTimestamp("min_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
+ rs.getTimestamp("sec_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("mil_from_dt"));
+ rs.close();
+
+ rs = conn.prepareStatement(
+ "SELECT THE_DATE ,FLOOR(THE_DATE,'DAY') AS day_from_dt "
+ + ",FLOOR(THE_DATE,'HOUR') AS hour_from_dt "
+ + ",FLOOR(THE_DATE,'MINUTE') AS min_from_dt "
+ + ",FLOOR(THE_DATE,'SECOND') AS sec_from_dt "
+ + ",FLOOR(THE_DATE,'MILLISECOND') AS mil_from_dt "
+ + "FROM TIME_AGG_TABLE").executeQuery();
+ assertTrue(rs.next());
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("THE_DATE"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
+ rs.getTimestamp("day_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
+ rs.getTimestamp("hour_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
+ rs.getTimestamp("min_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
+ rs.getTimestamp("sec_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("mil_from_dt"));
+ rs.close();
+
+ rs = conn.prepareStatement(
+ "SELECT THE_DATE ,CEIL(THE_DATE,'DAY') AS day_from_dt "
+ + ",CEIL(THE_DATE,'HOUR') AS hour_from_dt "
+ + ",CEIL(THE_DATE,'MINUTE') AS min_from_dt "
+ + ",CEIL(THE_DATE,'SECOND') AS sec_from_dt "
+ + ",CEIL(THE_DATE,'MILLISECOND') AS mil_from_dt "
+ + "FROM TIME_AGG_TABLE").executeQuery();
+ assertTrue(rs.next());
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("THE_DATE"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-09 00:00:00.0"),
+ rs.getTimestamp("day_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 10:00:00.0"),
+ rs.getTimestamp("hour_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:10:00.0"),
+ rs.getTimestamp("min_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
+ rs.getTimestamp("sec_from_dt"));
+ assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
+ rs.getTimestamp("mil_from_dt"));
+ rs.close();
+ } finally {
+ conn.close();
+ }
+ }
+
+ @Test
+ public void testRoundOffFunction() throws SQLException {
+ long ts = nextTimestamp();
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
+ Connection conn = DriverManager.getConnection(getUrl(), props);
+ String ddl = "create table round_test(k bigint primary key)";
+ conn.createStatement().execute(ddl);
+ conn.close();
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
+ conn = DriverManager.getConnection(getUrl(), props);
+ PreparedStatement stmt = conn.prepareStatement("upsert into round_test values(1380603308885)");
+ stmt.execute();
+ conn.commit();
+ conn.close();
+
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+ conn = DriverManager.getConnection(getUrl(), props);
+ ResultSet rs;
+ stmt = conn.prepareStatement("select round(k/1000000,0) from round_test");
+ rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(1380603, rs.getLong(1));
+
+ props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
+ conn = DriverManager.getConnection(getUrl(), props);
+ stmt = conn.prepareStatement("select round(k/1000000,0) x from round_test group by x");
+ rs = stmt.executeQuery();
+ assertTrue(rs.next());
+ assertEquals(1380603, rs.getLong(1));
+ }
+
+}
[2/6] phoenix git commit: PHOENIX-3290 Move and/or combine as many
NeedsOwnCluster tests to bring down test run time
Posted by ja...@apache.org.
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java
deleted file mode 100644
index c365934..0000000
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RoundFloorCeilFunctionsEnd2EndIT.java
+++ /dev/null
@@ -1,686 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.phoenix.end2end;
-
-import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
-import static org.apache.phoenix.util.TestUtil.closeStmtAndConn;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.math.BigDecimal;
-import java.sql.Connection;
-import java.sql.Date;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Time;
-import java.sql.Timestamp;
-import java.util.Properties;
-
-import org.apache.phoenix.expression.function.CeilFunction;
-import org.apache.phoenix.expression.function.FloorFunction;
-import org.apache.phoenix.expression.function.RoundFunction;
-import org.apache.phoenix.query.QueryServices;
-import org.apache.phoenix.util.DateUtil;
-import org.apache.phoenix.util.PhoenixRuntime;
-import org.apache.phoenix.util.PropertiesUtil;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.primitives.Doubles;
-import com.google.common.primitives.Floats;
-
-/**
- *
- * End to end tests for {@link RoundFunction}, {@link FloorFunction}, {@link CeilFunction}
- *
- *
- * @since 3.0.0
- */
-
-
-public class RoundFloorCeilFunctionsEnd2EndIT extends BaseHBaseManagedTimeTableReuseIT {
-
- private static final String TABLE_NAME = generateRandomString();
- private static long millisPart = 660;
- private static int nanosPart = 500100;
- private static BigDecimal decimalUpserted = BigDecimal.valueOf(1.264);
- private static double doubleUpserted = 1.264d;
- private static double unsignedDoubleUpserted = 1.264d;
- private static float floatUpserted = 1.264f;
- private static float unsignedFloatUpserted = 1.264f;
-
- @Before
- public void initTable() throws Exception {
- String testString = "abc";
- Connection conn = null;
- PreparedStatement stmt = null;
- try {
- conn = DriverManager.getConnection(getUrl());
- String ddl = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME
- + " (s VARCHAR NOT NULL PRIMARY KEY, dt DATE, t TIME, ts TIMESTAMP, dec DECIMAL, doub DOUBLE, undoub UNSIGNED_DOUBLE, fl FLOAT, unfl UNSIGNED_FLOAT)";
- conn.createStatement().execute(ddl);
-
- Date dateUpserted = DateUtil.parseDate("2012-01-01 14:25:28");
- dateUpserted = new Date(dateUpserted.getTime() + millisPart); // this makes the dateUpserted equivalent to 2012-01-01 14:25:28.660
- long millis = dateUpserted.getTime();
-
- Time timeUpserted = new Time(millis);
- Timestamp tsUpserted = DateUtil.getTimestamp(millis, nanosPart);
-
- stmt = conn.prepareStatement(
- "UPSERT INTO " + TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
- stmt.setString(1, testString);
- stmt.setDate(2, dateUpserted);
- stmt.setTime(3, timeUpserted);
- stmt.setTimestamp(4, tsUpserted);
- stmt.setBigDecimal(5, decimalUpserted);
- stmt.setDouble(6, doubleUpserted);
- stmt.setDouble(7, unsignedDoubleUpserted);
- stmt.setFloat(8, floatUpserted);
- stmt.setFloat(9, unsignedFloatUpserted);
- stmt.executeUpdate();
- conn.commit();
- } finally {
- closeStmtAndConn(stmt, conn);
- }
- }
-
- @Test
- public void testRoundingUpDate() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(dt, 'day'), ROUND(dt, 'hour', 1), ROUND(dt, 'minute', 1), ROUND(dt, 'second', 1), "
- + " ROUND(dt,'week'), ROUND(dt,'month') , ROUND(dt,'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
- assertEquals(expectedDate, rs.getDate(1));
- expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
- assertEquals(expectedDate, rs.getDate(2));
- expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
- assertEquals(expectedDate, rs.getDate(3));
- expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
- assertEquals(expectedDate, rs.getDate(4));
- expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
- assertEquals(expectedDate, rs.getDate(5));
- expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(6));
- expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(7));
- }
-
- @Test
- public void testRoundingUpDateInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE ROUND(dt, 'day') = to_date('2012-01-02 00:00:00')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testFloorDate() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(dt, 'day', 1), FLOOR(dt, 'hour', 1), FLOOR(dt, 'minute', 1), FLOOR(dt, 'second', 1),"
- + " FLOOR(dt,'week'), FLOOR(dt,'month'), FLOOR(dt,'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- Date expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(1));
- expectedDate = DateUtil.parseDate("2012-01-01 14:00:00");
- assertEquals(expectedDate, rs.getDate(2));
- expectedDate = DateUtil.parseDate("2012-01-01 14:25:00");
- assertEquals(expectedDate, rs.getDate(3));
- expectedDate = DateUtil.parseDate("2012-01-01 14:25:28");
- assertEquals(expectedDate, rs.getDate(4));
- expectedDate = DateUtil.parseDate("2011-12-26 00:00:00");
- assertEquals(expectedDate, rs.getDate(5));
- expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(6));
- expectedDate = DateUtil.parseDate("2012-01-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(7));
- }
-
- @Test
- public void testFloorDateInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE FLOOR(dt, 'hour') = to_date('2012-01-01 14:00:00')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testCeilDate() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(dt, 'day', 1), CEIL(dt, 'hour', 1), CEIL(dt, 'minute', 1), CEIL(dt, 'second', 1), "
- + " CEIL(dt,'week') , CEIL(dt,'month') , CEIL(dt,'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- //Date upserted is 2012-01-01 14:25:28.660. So we will end up bumping up in every case.
- Date expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
- assertEquals(expectedDate, rs.getDate(1));
- expectedDate = DateUtil.parseDate("2012-01-01 15:00:00");
- assertEquals(expectedDate, rs.getDate(2));
- expectedDate = DateUtil.parseDate("2012-01-01 14:26:00");
- assertEquals(expectedDate, rs.getDate(3));
- expectedDate = DateUtil.parseDate("2012-01-01 14:25:29");
- assertEquals(expectedDate, rs.getDate(4));
- expectedDate = DateUtil.parseDate("2012-01-02 00:00:00");
- System.out.println(String.format(" the expected time is [%s] and the actual time is [%s]",expectedDate.getTime(),rs.getDate(5).getTime()));
- assertEquals(expectedDate, rs.getDate(5));
- expectedDate = DateUtil.parseDate("2012-02-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(6));
- expectedDate = DateUtil.parseDate("2013-01-01 00:00:00");
- assertEquals(expectedDate, rs.getDate(7));
- }
-
- @Test
- public void testCeilDateInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE CEIL(dt, 'second') = to_date('2012-01-01 14:25:29')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testRoundingUpTimestamp() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT ROUND(ts, 'day'), ROUND(ts, 'hour', 1), ROUND(ts, 'minute', 1), ROUND(ts, 'second', 1), ROUND(ts, 'millisecond', 1) FROM "
- + TABLE_NAME);
- assertTrue(rs.next());
- Timestamp expectedTimestamp;
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(2));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(3));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(4));
-
- // Rounding of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date.
- // That is, it should be evaluated as "2012-01-01 14:25:28.661".
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
- assertEquals(expectedTimestamp, rs.getTimestamp(5));
- }
-
- @Test
- public void testRoundingUpTimestampInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE ROUND(ts, 'second') = to_date('2012-01-01 14:25:29')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testFloorTimestamp() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(ts, 'day'), FLOOR(ts, 'hour', 1), FLOOR(ts, 'minute', 1), FLOOR(ts, 'second', 1), "
- + " FLOOR(ts, 'millisecond', 1) , FLOOR(ts,'week') , FLOOR(ts,'month') FROM "
- + TABLE_NAME);
- assertTrue(rs.next());
- Timestamp expectedTimestamp;
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(2));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(3));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(4));
-
- // FLOOR of "2012-01-01 14:25:28.660" + nanosPart will end up removing the nanos part.
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart);
- assertEquals(expectedTimestamp, rs.getTimestamp(5));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(6));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(7));
- }
-
- @Test
- public void testFloorTimestampInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE FLOOR(ts, 'second') = to_date('2012-01-01 14:25:28')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testWeekFloorTimestampInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE FLOOR(ts, 'week') = to_date('2011-12-26 00:00:00')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testCeilTimestamp() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(ts, 'day'), CEIL(ts, 'hour', 1), CEIL(ts, 'minute', 1), CEIL(ts, 'second', 1), CEIL(ts, 'millisecond', 1),"
- + " CEIL(ts,'week'), CEIL(ts,'month') , CEIL(ts,'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- Timestamp expectedTimestamp;
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(1));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(2));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(3));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(4));
-
- // CEIL of "2012-01-01 14:25:28.660" + nanosPart will end up bumping up the millisecond part of date.
- // That is, it should be evaluated as "2012-01-01 14:25:28.661".
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-01 14:25:28").getTime() + millisPart + 1);
- assertEquals(expectedTimestamp, rs.getTimestamp(5));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(6));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(7));
- expectedTimestamp = new Timestamp(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
- assertEquals(expectedTimestamp, rs.getTimestamp(8));
- }
-
- @Test
- public void testCeilTimestampInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM " + TABLE_NAME
- + " WHERE CEIL(ts, 'second') = to_date('2012-01-01 14:25:29')");
- assertTrue(rs.next());
- }
-
- @Test
- public void testRoundingUpTime() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT ROUND(t, 'day', 1), ROUND(t, 'hour', 1), ROUND(t, 'minute', 1), ROUND(t, 'second', 1),"
- + " ROUND(t,'week') , ROUND(t,'month') , ROUND(t,'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(1));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(2));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
- assertEquals(expectedTime, rs.getTime(3));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
- assertEquals(expectedTime, rs.getTime(4));
- expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(5));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(6));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(7));
- }
-
- @Test
- public void testFloorTime() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT FLOOR(t, 'day', 1), FLOOR(t, 'hour', 1), FLOOR(t, 'minute', 1), FLOOR(t, 'second', 1), "
- + " FLOOR(t, 'week'), FLOOR(t, 'month'), FLOOR(t, 'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- Time expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(1));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(2));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:00").getTime());
- assertEquals(expectedTime, rs.getTime(3));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:28").getTime());
- assertEquals(expectedTime, rs.getTime(4));
- expectedTime = new Time(DateUtil.parseDate("2011-12-26 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(5));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(6));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(7));
- }
-
- @Test
- public void testCeilTime() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery("SELECT CEIL(t, 'day', 1), CEIL(t, 'hour', 1), CEIL(t, 'minute', 1), CEIL(t, 'second', 1),"
- + " CEIL(t,'week') , CEIL(t,'month') , CEIL(t,'year') FROM " + TABLE_NAME);
- assertTrue(rs.next());
- Time expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(1));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 15:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(2));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:26:00").getTime());
- assertEquals(expectedTime, rs.getTime(3));
- expectedTime = new Time(DateUtil.parseDate("2012-01-01 14:25:29").getTime());
- assertEquals(expectedTime, rs.getTime(4));
- expectedTime = new Time(DateUtil.parseDate("2012-01-02 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(5));
- expectedTime = new Time(DateUtil.parseDate("2012-02-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(6));
- expectedTime = new Time(DateUtil.parseDate("2013-01-01 00:00:00").getTime());
- assertEquals(expectedTime, rs.getTime(7));
- }
-
- @Test
- public void testRoundingUpDecimal() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT ROUND(dec), ROUND(dec, 1), ROUND(dec, 2), ROUND(dec, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- BigDecimal expectedBd = BigDecimal.valueOf(1);
- assertEquals(expectedBd, rs.getBigDecimal(1));
- expectedBd = BigDecimal.valueOf(1.3);
- assertEquals(expectedBd, rs.getBigDecimal(2));
- expectedBd = BigDecimal.valueOf(1.26);
- assertEquals(expectedBd, rs.getBigDecimal(3));
- expectedBd = BigDecimal.valueOf(1.264);
- assertEquals(expectedBd, rs.getBigDecimal(4));
- }
-
- @Test
- public void testRoundingUpDecimalInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT * FROM " + TABLE_NAME + " WHERE ROUND(dec, 2) = 1.26");
- assertTrue(rs.next());
- }
-
- @Test
- public void testFloorDecimal() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT FLOOR(dec), FLOOR(dec, 1), FLOOR(dec, 2), FLOOR(dec, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- BigDecimal expectedBd = BigDecimal.valueOf(1);
- assertEquals(expectedBd, rs.getBigDecimal(1));
- expectedBd = BigDecimal.valueOf(1.2);
- assertEquals(expectedBd, rs.getBigDecimal(2));
- expectedBd = BigDecimal.valueOf(1.26);
- assertEquals(expectedBd, rs.getBigDecimal(3));
- expectedBd = BigDecimal.valueOf(1.264);
- assertEquals(expectedBd, rs.getBigDecimal(4));
- }
-
- @Test
- public void testFloorDecimalInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT * FROM " + TABLE_NAME + " WHERE FLOOR(dec, 2) = 1.26");
- assertTrue(rs.next());
- }
-
- @Test
- public void testCeilDecimal() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT CEIL(dec), CEIL(dec, 1), CEIL(dec, 2), CEIL(dec, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- BigDecimal expectedBd = BigDecimal.valueOf(2);
- assertEquals(expectedBd, rs.getBigDecimal(1));
- expectedBd = BigDecimal.valueOf(1.3);
- assertEquals(expectedBd, rs.getBigDecimal(2));
- expectedBd = BigDecimal.valueOf(1.27);
- assertEquals(expectedBd, rs.getBigDecimal(3));
- expectedBd = BigDecimal.valueOf(1.264);
- assertEquals(expectedBd, rs.getBigDecimal(4));
- }
-
- @Test
- public void testCeilDecimalInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT * FROM " + TABLE_NAME + " WHERE CEIL(dec, 2) = 1.27");
- assertTrue(rs.next());
- }
- @Test
- public void testRoundingUpDouble() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT ROUND(doub), ROUND(doub, 1), ROUND(doub, 2), ROUND(doub, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
- assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
- assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
- assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
- }
-
- @Test
- public void testRoundingUpDoubleInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT * FROM " + TABLE_NAME + " WHERE ROUND(dec, 2) = 1.26");
- assertTrue(rs.next());
- }
-
- @Test
- public void testCeilDouble() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT CEIL(doub), CEIL(doub, 1), CEIL(doub, 2), CEIL(doub, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- assertEquals(0, Doubles.compare(2, rs.getDouble(1)));
- assertEquals(0, Doubles.compare(1.3, rs.getDouble(2)));
- assertEquals(0, Doubles.compare(1.27, rs.getDouble(3)));
- assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
- }
-
- @Test
- public void testCeilDoubleInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT * FROM " + TABLE_NAME + " WHERE CEIL(doub, 2) = 1.27");
- assertTrue(rs.next());
- }
-
- @Test
- public void testFloorDouble() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT FLOOR(doub), FLOOR(doub, 1), FLOOR(doub, 2), FLOOR(doub, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- assertEquals(0, Doubles.compare(1, rs.getDouble(1)));
- assertEquals(0, Doubles.compare(1.2, rs.getDouble(2)));
- assertEquals(0, Doubles.compare(1.26, rs.getDouble(3)));
- assertEquals(0, Doubles.compare(1.264, rs.getDouble(4)));
- }
-
- @Test
- public void testFloorDoubleInWhere() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT * FROM " + TABLE_NAME + " WHERE FLOOR(doub, 2) = 1.26");
- assertTrue(rs.next());
- }
-
- @Test
- public void testRoundFloat() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT ROUND(fl), ROUND(fl, 1), ROUND(fl, 2), ROUND(fl, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- assertEquals(0, Floats.compare(1, rs.getFloat(1)));
- assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
- assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
- assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
- }
-
- @Test
- public void testRoundUnsignedFloat() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT ROUND(unfl), ROUND(unfl, 1), ROUND(unfl, 2), ROUND(unfl, 3) FROM " + TABLE_NAME);
- assertTrue(rs.next());
- assertEquals(0, Floats.compare(1, rs.getFloat(1)));
- assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
- assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
- assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
- }
-
- @Test
- public void testRoundUnsignedDouble() throws Exception {
- Connection conn = DriverManager.getConnection(getUrl());
- ResultSet rs = conn.createStatement().executeQuery(
- "SELECT ROUND(undoub), ROUND(undoub, 1), ROUND(undoub, 2), ROUND(undoub, 3) FROM "
- + TABLE_NAME);
- assertTrue(rs.next());
- assertEquals(0, Floats.compare(1, rs.getFloat(1)));
- assertEquals(0, Floats.compare(1.3f, rs.getFloat(2)));
- assertEquals(0, Floats.compare(1.26f, rs.getFloat(3)));
- assertEquals(0, Floats.compare(1.264f, rs.getFloat(4)));
- }
-
- @Test
- public void testTimestampAggregateFunctions() throws Exception {
- String dateString = "2015-03-08 09:09:11.665";
- Properties props = new Properties();
- props.setProperty(QueryServices.DATE_FORMAT_TIMEZONE_ATTRIB, "GMT+1");
- Connection conn = DriverManager.getConnection(getUrl(), props);
- try {
- conn.prepareStatement(
- "create table TIME_AGG_TABLE("
- + "ID unsigned_int NOT NULL, "
- + "THE_DATE TIMESTAMP, "
- + "constraint PK primary key (ID))").execute();
- PreparedStatement stmt = conn.prepareStatement("upsert into "
- + "TIME_AGG_TABLE(" + " ID, " + " THE_DATE)"
- + "VALUES (?, ?)");
- stmt.setInt(1, 1);
- stmt.setTimestamp(2, DateUtil.parseTimestamp(dateString));
- stmt.execute();
- conn.commit();
-
- ResultSet rs = conn.prepareStatement(
- "SELECT THE_DATE ,TRUNC(THE_DATE,'DAY') AS day_from_dt "
- + ",TRUNC(THE_DATE,'HOUR') AS hour_from_dt "
- + ",TRUNC(THE_DATE,'MINUTE') AS min_from_dt "
- + ",TRUNC(THE_DATE,'SECOND') AS sec_from_dt "
- + ",TRUNC(THE_DATE,'MILLISECOND') AS mil_from_dt "
- + "FROM TIME_AGG_TABLE").executeQuery();
- assertTrue(rs.next());
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("THE_DATE"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
- rs.getTimestamp("day_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
- rs.getTimestamp("hour_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
- rs.getTimestamp("min_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
- rs.getTimestamp("sec_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("mil_from_dt"));
- rs.close();
-
- rs = conn.prepareStatement(
- "SELECT THE_DATE ,ROUND(THE_DATE,'DAY') AS day_from_dt "
- + ",ROUND(THE_DATE,'HOUR') AS hour_from_dt "
- + ",ROUND(THE_DATE,'MINUTE') AS min_from_dt "
- + ",ROUND(THE_DATE,'SECOND') AS sec_from_dt "
- + ",ROUND(THE_DATE,'MILLISECOND') AS mil_from_dt "
- + "FROM TIME_AGG_TABLE").executeQuery();
- assertTrue(rs.next());
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("THE_DATE"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
- rs.getTimestamp("day_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
- rs.getTimestamp("hour_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
- rs.getTimestamp("min_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
- rs.getTimestamp("sec_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("mil_from_dt"));
- rs.close();
-
- rs = conn.prepareStatement(
- "SELECT THE_DATE ,FLOOR(THE_DATE,'DAY') AS day_from_dt "
- + ",FLOOR(THE_DATE,'HOUR') AS hour_from_dt "
- + ",FLOOR(THE_DATE,'MINUTE') AS min_from_dt "
- + ",FLOOR(THE_DATE,'SECOND') AS sec_from_dt "
- + ",FLOOR(THE_DATE,'MILLISECOND') AS mil_from_dt "
- + "FROM TIME_AGG_TABLE").executeQuery();
- assertTrue(rs.next());
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("THE_DATE"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 00:00:00.0"),
- rs.getTimestamp("day_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:00:00.0"),
- rs.getTimestamp("hour_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:00.0"),
- rs.getTimestamp("min_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.0"),
- rs.getTimestamp("sec_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("mil_from_dt"));
- rs.close();
-
- rs = conn.prepareStatement(
- "SELECT THE_DATE ,CEIL(THE_DATE,'DAY') AS day_from_dt "
- + ",CEIL(THE_DATE,'HOUR') AS hour_from_dt "
- + ",CEIL(THE_DATE,'MINUTE') AS min_from_dt "
- + ",CEIL(THE_DATE,'SECOND') AS sec_from_dt "
- + ",CEIL(THE_DATE,'MILLISECOND') AS mil_from_dt "
- + "FROM TIME_AGG_TABLE").executeQuery();
- assertTrue(rs.next());
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("THE_DATE"));
- assertEquals(DateUtil.parseTimestamp("2015-03-09 00:00:00.0"),
- rs.getTimestamp("day_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 10:00:00.0"),
- rs.getTimestamp("hour_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:10:00.0"),
- rs.getTimestamp("min_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:12.0"),
- rs.getTimestamp("sec_from_dt"));
- assertEquals(DateUtil.parseTimestamp("2015-03-08 09:09:11.665"),
- rs.getTimestamp("mil_from_dt"));
- rs.close();
- } finally {
- conn.close();
- }
- }
-
- @Test
- public void testRoundOffFunction() throws SQLException {
- long ts = nextTimestamp();
- Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10));
- Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "create table round_test(k bigint primary key)";
- conn.createStatement().execute(ddl);
- conn.close();
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30));
- conn = DriverManager.getConnection(getUrl(), props);
- PreparedStatement stmt = conn.prepareStatement("upsert into round_test values(1380603308885)");
- stmt.execute();
- conn.commit();
- conn.close();
-
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- ResultSet rs;
- stmt = conn.prepareStatement("select round(k/1000000,0) from round_test");
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(1380603, rs.getLong(1));
-
- props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40));
- conn = DriverManager.getConnection(getUrl(), props);
- stmt = conn.prepareStatement("select round(k/1000000,0) x from round_test group by x");
- rs = stmt.executeQuery();
- assertTrue(rs.next());
- assertEquals(1380603, rs.getLong(1));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
index aa6fa06..e5cd578 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/TransactionalViewIT.java
@@ -41,7 +41,6 @@ public class TransactionalViewIT extends BaseOwnClusterHBaseManagedTimeIT {
public static void doSetup() throws Exception {
Map<String,String> props = Maps.newHashMapWithExpectedSize(3);
props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Integer.toString(20));
- props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(1024));
props.put(QueryServices.TRANSACTIONS_ENABLED, Boolean.toString(true));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
@@ -107,8 +106,8 @@ public class TransactionalViewIT extends BaseOwnClusterHBaseManagedTimeIT {
}
assertEquals(4, count);
- Thread.sleep(DEFAULT_TXN_TIMEOUT_SECONDS*1000+20000);
- assertEquals("There should be one invalid transaction", 1, txManager.getInvalidSize());
+ // Thread.sleep(DEFAULT_TXN_TIMEOUT_SECONDS*1000+20000);
+ // assertEquals("There should be one invalid transaction", 1, txManager.getInvalidSize());
// verify stats can see the rows from the invalid transaction
analyzeTable(conn2, "v", true);
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
index 57ba858..c6a7bf0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UnionAllIT.java
@@ -30,49 +30,41 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.Collections;
-import java.util.Map;
import java.util.Properties;
import org.apache.phoenix.exception.SQLExceptionCode;
import org.apache.phoenix.util.PropertiesUtil;
import org.apache.phoenix.util.QueryUtil;
-import org.apache.phoenix.util.ReadOnlyProps;
-import org.junit.BeforeClass;
import org.junit.Test;
-public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
-
- @BeforeClass
- public static void doSetup() throws Exception {
- Map<String, String> props = Collections.emptyMap();
- setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
- }
+public class UnionAllIT extends BaseHBaseManagedTimeTableReuseIT {
@Test
public void testUnionAllSelects() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar(10) not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string char(20) not null, col1 bigint" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 20);
@@ -82,7 +74,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "select * from test_table union all select * from b_table union all select * from test_table";
+ ddl = "select * from " + tableName1 + " union all select * from " + tableName2 + " union all select * from " + tableName1;
ResultSet rs = conn.createStatement().executeQuery(ddl);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -104,17 +96,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testAggregate() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string char(5) not null, col1 tinyint" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
@@ -127,11 +121,11 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 20);
@@ -141,7 +135,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- String aggregate = "select count(*) from test_table union all select count(*) from b_table union all select count(*) from test_table";
+ String aggregate = "select count(*) from " + tableName1 + " union all select count(*) from " + tableName2 + " union all select count(*) from " + tableName1;
ResultSet rs = conn.createStatement().executeQuery(aggregate);
assertTrue(rs.next());
assertEquals(3,rs.getInt(1));
@@ -157,28 +151,30 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testGroupBy() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 20);
@@ -188,7 +184,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- String aggregate = "select count(*), col1 from test_table group by col1 union all select count(*), col1 from b_table group by col1";
+ String aggregate = "select count(*), col1 from " + tableName1 + " group by col1 union all select count(*), col1 from " + tableName2 + " group by col1";
ResultSet rs = conn.createStatement().executeQuery(aggregate);
assertTrue(rs.next());
assertEquals(1,rs.getInt(1));
@@ -204,17 +200,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testOrderByLimit() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table1 " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table1 VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
@@ -224,11 +222,11 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table1 " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table1 VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 20);
@@ -244,7 +242,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- String aggregate = "select count(*), col1 from b_table1 group by col1 union all select count(*), col1 from test_table1 group by col1 order by col1";
+ String aggregate = "select count(*), col1 from " + tableName2 + " group by col1 union all select count(*), col1 from " + tableName1 + " group by col1 order by col1";
ResultSet rs = conn.createStatement().executeQuery(aggregate);
assertTrue(rs.next());
assertEquals(2,rs.getInt(1));
@@ -254,7 +252,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(3,rs.getInt(1));
assertFalse(rs.next());
- String limit = "select count(*), col1 x from test_table1 group by col1 union all select count(*), col1 x from b_table1 group by col1 order by x limit 2";
+ String limit = "select count(*), col1 x from " + tableName1 + " group by col1 union all select count(*), col1 x from " + tableName2 + " group by col1 order by x limit 2";
rs = conn.createStatement().executeQuery(limit);
assertTrue(rs.next());
assertEquals(2,rs.getInt(1));
@@ -262,7 +260,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(1,rs.getInt(1));
assertFalse(rs.next());
- String limitOnly = "select * from test_table1 union all select * from b_table1 limit 2";
+ String limitOnly = "select * from " + tableName1 + " union all select * from " + tableName2 + " limit 2";
rs = conn.createStatement().executeQuery(limitOnly);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -278,22 +276,24 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testSelectDiff() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- ddl = "select a_string, col1, col1 from test_table union all select * from b_table union all select a_string, col1 from test_table";
+ ddl = "select a_string, col1, col1 from " + tableName1 + " union all select * from " + tableName2 + " union all select a_string, col1 from " + tableName1;
conn.createStatement().executeQuery(ddl);
fail();
} catch (SQLException e) {
@@ -305,38 +305,40 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testJoinInUnionAll() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 20);
stmt.execute();
conn.commit();
- ddl = "select x.a_string, y.col1 from test_table x, b_table y where x.a_string=y.a_string union all " +
- "select t.a_string, s.col1 from test_table s, b_table t where s.a_string=t.a_string";
+ ddl = "select x.a_string, y.col1 from " + tableName1 + " x, " + tableName2 + " y where x.a_string=y.a_string union all " +
+ "select t.a_string, s.col1 from " + tableName1 + " s, " + tableName2 + " t where s.a_string=t.a_string";
ResultSet rs = conn.createStatement().executeQuery(ddl);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -346,8 +348,8 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(10,rs.getInt(2));
assertFalse(rs.next());
- ddl = "select x.a_string, y.col1 from test_table x join b_table y on x.a_string=y.a_string union all " +
- "select t.a_string, s.col1 from test_table s inner join b_table t on s.a_string=t.a_string";
+ ddl = "select x.a_string, y.col1 from " + tableName1 + " x join " + tableName2 + " y on x.a_string=y.a_string union all " +
+ "select t.a_string, s.col1 from " + tableName1 + " s inner join " + tableName2 + " t on s.a_string=t.a_string";
rs = conn.createStatement().executeQuery(ddl);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -357,9 +359,9 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(10,rs.getInt(2));
assertFalse(rs.next());
- ddl = "select x.a_string, y.col1 from test_table x left join b_table y on x.a_string=y.a_string union all " +
- "select t.a_string, s.col1 from test_table s inner join b_table t on s.a_string=t.a_string union all " +
- "select y.a_string, x.col1 from b_table x right join test_table y on x.a_string=y.a_string";
+ ddl = "select x.a_string, y.col1 from " + tableName1 + " x left join " + tableName2 + " y on x.a_string=y.a_string union all " +
+ "select t.a_string, s.col1 from " + tableName1 + " s inner join " + tableName2 + " t on s.a_string=t.a_string union all " +
+ "select y.a_string, x.col1 from " + tableName2 + " x right join " + tableName1 + " y on x.a_string=y.a_string";
rs = conn.createStatement().executeQuery(ddl);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -378,37 +380,39 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testDerivedTable() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 20);
stmt.execute();
conn.commit();
- ddl = "select * from (select x.a_string, y.col1 from test_table x, b_table y where x.a_string=y.a_string) union all " +
- "select * from (select t.a_string, s.col1 from test_table s, b_table t where s.a_string=t.a_string)";
+ ddl = "select * from (select x.a_string, y.col1 from " + tableName1 + " x, " + tableName2 + " y where x.a_string=y.a_string) union all " +
+ "select * from (select t.a_string, s.col1 from " + tableName1 + " s, " + tableName2 + " t where s.a_string=t.a_string)";
ResultSet rs = conn.createStatement().executeQuery(ddl);
assertTrue(rs.next());
assertEquals("a",rs.getString(1));
@@ -424,17 +428,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testUnionAllInDerivedTable() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
@@ -444,12 +450,12 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col2 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 30);
@@ -460,7 +466,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
String query = "select a_string from " +
- "(select a_string, col1 from test_table union all select a_string, col2 from b_table order by a_string)";
+ "(select a_string, col1 from " + tableName1 + " union all select a_string, col2 from " + tableName2 + " order by a_string)";
ResultSet rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals("a", rs.getString(1));
@@ -473,7 +479,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertFalse(rs.next());
query = "select c from " +
- "(select a_string, col1 c from test_table union all select a_string, col2 c from b_table order by c)";
+ "(select a_string, col1 c from " + tableName1 + " union all select a_string, col2 c from " + tableName2 + " order by c)";
rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
assertEquals(10, rs.getInt(1));
@@ -491,17 +497,19 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testUnionAllInSubquery() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
@@ -511,12 +519,12 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 30);
@@ -527,10 +535,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
String[] queries = new String[2];
- queries[0] = "select a_string, col1 from test_table where a_string in " +
- "(select a_string aa from b_table where a_string != 'a' union all select a_string bb from b_table)";
- queries[1] = "select a_string, col1 from test_table where a_string in (select a_string from " +
- "(select a_string from b_table where a_string != 'a' union all select a_string from b_table))";
+ queries[0] = "select a_string, col1 from " + tableName1 + " where a_string in " +
+ "(select a_string aa from " + tableName2 + " where a_string != 'a' union all select a_string bb from " + tableName2 + ")";
+ queries[1] = "select a_string, col1 from " + tableName1 + " where a_string in (select a_string from " +
+ "(select a_string from " + tableName2 + " where a_string != 'a' union all select a_string from " + tableName2 + "))";
for (String query : queries) {
ResultSet rs = conn.createStatement().executeQuery(query);
assertTrue(rs.next());
@@ -545,34 +553,36 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testUnionAllWithBindParam() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 20);
stmt.execute();
conn.commit();
- ddl = "select a_string, col1 from b_table where col1=? union all select a_string, col1 from test_table where col1=? ";
+ ddl = "select a_string, col1 from " + tableName2 + " where col1=? union all select a_string, col1 from " + tableName1 + " where col1=? ";
stmt = conn.prepareStatement(ddl);
stmt.setInt(1, 20);
stmt.setInt(2, 10);
@@ -591,43 +601,45 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testExplainUnionAll() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- ddl = "explain select a_string, col1 from test_table union all select a_string, col1 from b_table order by col1 limit 1";
+ ddl = "explain select a_string, col1 from " + tableName1 + " union all select a_string, col1 from " + tableName2 + " order by col1 limit 1";
ResultSet rs = conn.createStatement().executeQuery(ddl);
assertEquals(
"UNION ALL OVER 2 QUERIES\n" +
- " CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_TABLE\n" +
+ " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName1 + "\n" +
" SERVER TOP 1 ROW SORTED BY [COL1]\n" +
" CLIENT MERGE SORT\n" +
- " CLIENT PARALLEL 1-WAY FULL SCAN OVER B_TABLE\n" +
+ " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName2 + "\n" +
" SERVER TOP 1 ROW SORTED BY [COL1]\n" +
" CLIENT MERGE SORT\n" +
"CLIENT MERGE SORT", QueryUtil.getExplainPlan(rs));
String limitPlan =
"UNION ALL OVER 2 QUERIES\n" +
- " CLIENT SERIAL 1-WAY FULL SCAN OVER TEST_TABLE\n" +
+ " CLIENT SERIAL 1-WAY FULL SCAN OVER " + tableName1 + "\n" +
" SERVER 2 ROW LIMIT\n" +
" CLIENT 2 ROW LIMIT\n" +
- " CLIENT SERIAL 1-WAY FULL SCAN OVER B_TABLE\n" +
+ " CLIENT SERIAL 1-WAY FULL SCAN OVER " + tableName2 + "\n" +
" SERVER 2 ROW LIMIT\n" +
" CLIENT 2 ROW LIMIT\n" +
"CLIENT 2 ROW LIMIT";
- ddl = "explain select a_string, col1 from test_table union all select a_string, col1 from b_table";
+ ddl = "explain select a_string, col1 from " + tableName1 + " union all select a_string, col1 from " + tableName2;
rs = conn.createStatement().executeQuery(ddl + " limit 2");
assertEquals(limitPlan, QueryUtil.getExplainPlan(rs));
Statement stmt = conn.createStatement();
@@ -635,12 +647,12 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
rs = stmt.executeQuery(ddl);
assertEquals(limitPlan, QueryUtil.getExplainPlan(rs));
- ddl = "explain select a_string, col1 from test_table union all select a_string, col1 from b_table";
+ ddl = "explain select a_string, col1 from " + tableName1 + " union all select a_string, col1 from " + tableName2;
rs = conn.createStatement().executeQuery(ddl);
assertEquals(
"UNION ALL OVER 2 QUERIES\n" +
- " CLIENT PARALLEL 1-WAY FULL SCAN OVER TEST_TABLE\n" +
- " CLIENT PARALLEL 1-WAY FULL SCAN OVER B_TABLE", QueryUtil.getExplainPlan(rs));
+ " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName1 + "\n" +
+ " CLIENT PARALLEL 1-WAY FULL SCAN OVER " + tableName2, QueryUtil.getExplainPlan(rs));
} finally {
conn.close();
}
@@ -648,66 +660,68 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testBug2295() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
+ String itableName1 = generateRandomString();
+ String itableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
conn.setAutoCommit(false);
try {
- String ddl = "CREATE TABLE table1(" +
+ String ddl = "CREATE TABLE " + tableName1 + "(" +
"id BIGINT, col1 VARCHAR, col2 integer, CONSTRAINT pk PRIMARY KEY (id)) IMMUTABLE_ROWS=true";
createTestTable(getUrl(), ddl);
- ddl = "CREATE TABLE table2(" +
+ ddl = "CREATE TABLE " + tableName2 + "(" +
"id BIGINT, col1 VARCHAR, col2 integer, CONSTRAINT pk PRIMARY KEY (id)) IMMUTABLE_ROWS=true";
createTestTable(getUrl(), ddl);
- ddl = "CREATE index idx_table1_col1 on table1(col1)";
+ ddl = "CREATE index " + itableName1 + " on " + tableName1 + "(col1)";
createTestTable(getUrl(), ddl);
- ddl = "CREATE index idx_table2_col1 on table2(col1)";
+ ddl = "CREATE index " + itableName2 + " on " + tableName2 + "(col1)";
createTestTable(getUrl(), ddl);
- ddl = "Explain SELECT /*+ INDEX(table1 idx_table1_col1) */ col1, col2 from table1 where col1='123' " +
- "union all SELECT /*+ INDEX(table2 idx_table2_col1) */ col1, col2 from table2 where col1='123'";
+ ddl = "Explain SELECT /*+ INDEX(" + tableName1 + " " + itableName1 + ") */ col1, col2 from " + tableName1 + " where col1='123' " +
+ "union all SELECT /*+ INDEX(" + tableName2 + " " + itableName2 + ") */ col1, col2 from " + tableName2 + " where col1='123'";
ResultSet rs = conn.createStatement().executeQuery(ddl);
assertTrue(rs.next());
} finally {
- String ddl = "drop table table1";
- conn.createStatement().execute(ddl);
- ddl = "drop table table2";
- conn.createStatement().execute(ddl);
conn.close();
}
}
@Test
public void testParameterMetaDataNotNull() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "CREATE TABLE test_table " +
+ String ddl = "CREATE TABLE " + tableName1 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- String dml = "UPSERT INTO test_table VALUES(?, ?)";
+ String dml = "UPSERT INTO " + tableName1 + " VALUES(?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setString(1, "a");
stmt.setInt(2, 10);
stmt.execute();
conn.commit();
- ddl = "CREATE TABLE b_table " +
+ ddl = "CREATE TABLE " + tableName2 + " " +
" (a_string varchar not null, col1 integer" +
" CONSTRAINT pk PRIMARY KEY (a_string))\n";
createTestTable(getUrl(), ddl);
- dml = "UPSERT INTO b_table VALUES(?, ?)";
+ dml = "UPSERT INTO " + tableName2 + " VALUES(?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setString(1, "b");
stmt.setInt(2, 20);
stmt.execute();
conn.commit();
- String query = "select * from test_table union all select * from b_table";
+ String query = "select * from " + tableName1 + " union all select * from " + tableName2;
try{
PreparedStatement pstmt = conn.prepareStatement(query);
@@ -727,13 +741,17 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testDiffDataTypes() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
+ String tableName3 = generateRandomString();
+ String tableName4 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "create table person ( id bigint not null primary key, " +
+ String ddl = "create table " + tableName1 + " ( id bigint not null primary key, " +
"firstname varchar(10), lastname varchar(10) )";
createTestTable(getUrl(), ddl);
- String dml = "upsert into person values (?, ?, ?)";
+ String dml = "upsert into " + tableName1 + " values (?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "john");
@@ -745,10 +763,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "create table user ( id integer not null primary key, firstname char(12)," +
+ ddl = "create table " + tableName2 + " ( id integer not null primary key, firstname char(12)," +
" lastname varchar(12) )";
createTestTable(getUrl(), ddl);
- dml = "upsert into user values (?, ?, ?)";
+ dml = "upsert into " + tableName2 + " values (?, ?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "sam");
@@ -760,20 +778,20 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "create table t1 ( id varchar(20) not null primary key)";
+ ddl = "create table " + tableName3 + " ( id varchar(20) not null primary key)";
createTestTable(getUrl(), ddl);
- dml = "upsert into t1 values ('abcd')";
+ dml = "upsert into " + tableName3 + " values ('abcd')";
stmt = conn.prepareStatement(dml);
stmt.execute();
conn.commit();
- ddl = "create table t2 ( id char(50) not null primary key)";
+ ddl = "create table " + tableName4 + " ( id char(50) not null primary key)";
createTestTable(getUrl(), ddl);
- dml = "upsert into t2 values ('xyz')";
+ dml = "upsert into " + tableName4 + " values ('xyz')";
stmt = conn.prepareStatement(dml);
stmt.execute();
conn.commit();
- String query = "select id, 'foo' firstname, lastname from person union all" +
- " select * from user";
+ String query = "select id, 'foo' firstname, lastname from " + tableName1 + " union all" +
+ " select * from " + tableName2;
try {
PreparedStatement pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
@@ -795,7 +813,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals("wiely", rs.getString(3));
assertFalse(rs.next());
- pstmt = conn.prepareStatement("select * from t1 union all select * from t2");
+ pstmt = conn.prepareStatement("select * from " + tableName3 + " union all select * from " + tableName4);
rs = pstmt.executeQuery();
assertTrue(rs.next());
assertEquals("abcd", rs.getString(1));
@@ -809,13 +827,17 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testDiffScaleSortOrder() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
+ String tableName3 = generateRandomString();
+ String tableName4 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "create table person ( id bigint not null primary key desc, " +
+ String ddl = "create table " + tableName1 + " ( id bigint not null primary key desc, " +
"firstname char(10), lastname varchar(10) )";
createTestTable(getUrl(), ddl);
- String dml = "upsert into person values (?, ?, ?)";
+ String dml = "upsert into " + tableName1 + " values (?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "john");
@@ -827,10 +849,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "create table user ( id integer not null primary key asc, " +
+ ddl = "create table " + tableName2 + " ( id integer not null primary key asc, " +
"firstname varchar(12), lastname varchar(10) )";
createTestTable(getUrl(), ddl);
- dml = "upsert into user values (?, ?, ?)";
+ dml = "upsert into " + tableName2 + " values (?, ?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "sam");
@@ -842,20 +864,20 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "create table t1 ( id varchar(20) not null primary key, col1 decimal)";
+ ddl = "create table " + tableName3 + " ( id varchar(20) not null primary key, col1 decimal)";
createTestTable(getUrl(), ddl);
- dml = "upsert into t1 values ('abcd', 234.23)";
+ dml = "upsert into " + tableName3 + " values ('abcd', 234.23)";
stmt = conn.prepareStatement(dml);
stmt.execute();
conn.commit();
- ddl = "create table t2 ( id char(50) not null primary key, col1 decimal(12,4))";
+ ddl = "create table " + tableName4 + " ( id char(50) not null primary key, col1 decimal(12,4))";
createTestTable(getUrl(), ddl);
- dml = "upsert into t2 values ('xyz', 1342.1234)";
+ dml = "upsert into " + tableName4 + " values ('xyz', 1342.1234)";
stmt = conn.prepareStatement(dml);
stmt.execute();
conn.commit();
- String query = "select * from user union all select * from person";
+ String query = "select * from " + tableName2 + " union all select * from " + tableName1;
try {
PreparedStatement pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
@@ -877,7 +899,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals("doe", rs.getString(3));
assertFalse(rs.next());
- pstmt = conn.prepareStatement("select * from t1 union all select * from t2");
+ pstmt = conn.prepareStatement("select * from " + tableName3 + " union all select * from " + tableName4);
rs = pstmt.executeQuery();
assertTrue(rs.next());
assertEquals("abcd", rs.getString(1));
@@ -893,13 +915,15 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testVarcharChar() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "create table user ( id integer not null primary key asc, " +
+ String ddl = "create table " + tableName2 + " ( id integer not null primary key asc, " +
"firstname char(8), lastname varchar )";
createTestTable(getUrl(), ddl);
- String dml = "upsert into user values (?, ?, ?)";
+ String dml = "upsert into " + tableName2 + " values (?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "sam");
@@ -911,10 +935,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "create table person ( id bigint not null primary key desc, " +
+ ddl = "create table " + tableName1 + " ( id bigint not null primary key desc, " +
"firstname varchar(10), lastname char(10) )";
createTestTable(getUrl(), ddl);
- dml = "upsert into person values (?, ?, ?)";
+ dml = "upsert into " + tableName1 + " values (?, ?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "john");
@@ -926,8 +950,8 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- String query = "select id, 'baa' firstname, lastname from user " +
- "union all select * from person";
+ String query = "select id, 'baa' firstname, lastname from " + tableName2 + " " +
+ "union all select * from " + tableName1;
try {
PreparedStatement pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
@@ -955,13 +979,15 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
@Test
public void testCoerceExpr() throws Exception {
+ String tableName1 = generateRandomString();
+ String tableName2 = generateRandomString();
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
- String ddl = "create table user ( id integer not null primary key desc, " +
+ String ddl = "create table " + tableName2 + " ( id integer not null primary key desc, " +
"firstname char(8), lastname varchar, sales double)";
createTestTable(getUrl(), ddl);
- String dml = "upsert into user values (?, ?, ?, ?)";
+ String dml = "upsert into " + tableName2 + " values (?, ?, ?, ?)";
PreparedStatement stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "sam");
@@ -975,10 +1001,10 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
stmt.execute();
conn.commit();
- ddl = "create table person (id bigint not null primary key, " +
+ ddl = "create table " + tableName1 + " (id bigint not null primary key, " +
"firstname char(10), lastname varchar(10), sales decimal)";
createTestTable(getUrl(), ddl);
- dml = "upsert into person values (?, ?, ?, ?)";
+ dml = "upsert into " + tableName1 + " values (?, ?, ?, ?)";
stmt = conn.prepareStatement(dml);
stmt.setInt(1, 1);
stmt.setString(2, "john");
@@ -993,7 +1019,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
conn.commit();
String query = "select id, cast('foo' as char(10)) firstname, lastname, sales " +
- "from person union all select * from user";
+ "from " + tableName1 + " union all select * from " + tableName2;
try {
PreparedStatement pstmt = conn.prepareStatement(query);
ResultSet rs = pstmt.executeQuery();
@@ -1019,7 +1045,7 @@ public class UnionAllIT extends BaseOwnClusterHBaseManagedTimeIT {
assertEquals(BigDecimal.valueOf(100.6798), rs.getBigDecimal(4));
assertFalse(rs.next());
- query = "select id, cast('foo' as char(10)) firstname, lastname, sales from person";
+ query = "select id, cast('foo' as char(10)) firstname, lastname, sales from " + tableName1;
pstmt = conn.prepareStatement(query);
rs = pstmt.executeQuery();
assertTrue(rs.next());
http://git-wip-us.apache.org/repos/asf/phoenix/blob/14d16c85/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
index 867c0f7..32f272d 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ImmutableIndexWithStatsIT.java
@@ -46,9 +46,6 @@ public class ImmutableIndexWithStatsIT extends BaseOwnClusterHBaseManagedTimeIT
public static void doSetup() throws Exception {
Map<String,String> props = Maps.newHashMapWithExpectedSize(5);
props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, Long.toString(1));
- props.put(QueryServices.EXPLAIN_CHUNK_COUNT_ATTRIB, Boolean.TRUE.toString());
- props.put(QueryServices.THREAD_POOL_SIZE_ATTRIB, Integer.toString(4));
- props.put(QueryServices.QUEUE_SIZE_ATTRIB, Integer.toString(500));
setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
}
@@ -77,7 +74,7 @@ public class ImmutableIndexWithStatsIT extends BaseOwnClusterHBaseManagedTimeIT
conn.createStatement().execute("UPDATE STATISTICS " + tableName);
query = "SELECT COUNT(*) FROM " + tableName;
rs = conn.createStatement().executeQuery("EXPLAIN " + query);
- assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT 7-CHUNK PARALLEL 1-WAY FULL SCAN"));
+ assertTrue(QueryUtil.getExplainPlan(rs).startsWith("CLIENT PARALLEL 1-WAY FULL SCAN"));
String indexName = TestUtil.DEFAULT_INDEX_TABLE_NAME;
conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + tableName + " (v)");