PHOENIX-2036 - PhoenixConfigurationUtil should provide a pre-normalize table name to PhoenixRuntime
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/c398e182 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/c398e182 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/c398e182 Branch: refs/heads/calcite Commit: c398e1823d8fe16c729e3b75eaf754eef0702856 Parents: be5aba5 Author: ravimagham <[email protected]> Authored: Sat Jul 4 10:08:00 2015 -0700 Committer: ravimagham <[email protected]> Committed: Sat Jul 4 10:08:00 2015 -0700 ---------------------------------------------------------------------- .../util/PhoenixConfigurationUtilTest.java | 28 +++++++++++++-- .../org/apache/phoenix/util/QueryUtilTest.java | 36 ++++++++++++++++++-- 2 files changed, 58 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/c398e182/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java index f8f2a63..aa03501 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/mapreduce/util/PhoenixConfigurationUtilTest.java @@ -73,7 +73,29 @@ public class PhoenixConfigurationUtilTest extends BaseConnectionlessQueryTest { configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl()); PhoenixConfigurationUtil.setInputTableName(configuration, tableName); final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration); - final String expectedSelectStatement = "SELECT \"A_STRING\",\"A_BINARY\",\"0\".\"COL1\" FROM " + SchemaUtil.getEscapedArgument(tableName) ; + final String expectedSelectStatement = "SELECT \"A_STRING\",\"A_BINARY\",\"0\".\"COL1\" FROM " + tableName ; + assertEquals(expectedSelectStatement, selectStatement); + } finally { + conn.close(); + } + } + + @Test + public void testSelectStatementWithSchema() throws Exception { + Connection conn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES)); + final String tableName = "TEST_TABLE"; + final String schemaName = SchemaUtil.getEscapedArgument("schema"); + final String fullTableName = SchemaUtil.getTableName(schemaName, tableName); + try { + String ddl = "CREATE TABLE "+ fullTableName + + " (a_string varchar not null, a_binary varbinary not null, col1 integer" + + " CONSTRAINT pk PRIMARY KEY (a_string, a_binary))\n"; + conn.createStatement().execute(ddl); + final Configuration configuration = new Configuration (); + configuration.set(HConstants.ZOOKEEPER_QUORUM, getUrl()); + PhoenixConfigurationUtil.setInputTableName(configuration, fullTableName); + final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration); + final String expectedSelectStatement = "SELECT \"A_STRING\",\"A_BINARY\",\"0\".\"COL1\" FROM " + fullTableName; assertEquals(expectedSelectStatement, selectStatement); } finally { conn.close(); @@ -94,7 +116,7 @@ public class PhoenixConfigurationUtilTest extends BaseConnectionlessQueryTest { PhoenixConfigurationUtil.setInputTableName(configuration, tableName); PhoenixConfigurationUtil.setSelectColumnNames(configuration, "A_BINARY"); final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration); - final String expectedSelectStatement = "SELECT \"A_BINARY\" FROM " + SchemaUtil.getEscapedArgument(tableName) ; + final String expectedSelectStatement = "SELECT \"A_BINARY\" FROM " + tableName ; assertEquals(expectedSelectStatement, selectStatement); } finally { conn.close(); @@ -115,7 +137,7 @@ public class PhoenixConfigurationUtilTest extends BaseConnectionlessQueryTest { PhoenixConfigurationUtil.setSchemaType(configuration, SchemaType.QUERY); PhoenixConfigurationUtil.setInputTableName(configuration, tableName); final String selectStatement = PhoenixConfigurationUtil.getSelectStatement(configuration); - final String expectedSelectStatement = "SELECT \"ID\",\"0\".\"VCARRAY\" FROM " + SchemaUtil.getEscapedArgument(tableName) ; + final String expectedSelectStatement = "SELECT \"ID\",\"0\".\"VCARRAY\" FROM " + tableName ; assertEquals(expectedSelectStatement, selectStatement); } finally { conn.close(); http://git-wip-us.apache.org/repos/asf/phoenix/blob/c398e182/phoenix-core/src/test/java/org/apache/phoenix/util/QueryUtilTest.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/QueryUtilTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/QueryUtilTest.java index 8446e9e..45f536d 100644 --- a/phoenix-core/src/test/java/org/apache/phoenix/util/QueryUtilTest.java +++ b/phoenix-core/src/test/java/org/apache/phoenix/util/QueryUtilTest.java @@ -17,6 +17,11 @@ */ package org.apache.phoenix.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.sql.Types; import java.util.Properties; @@ -26,8 +31,6 @@ import org.junit.Test; import com.google.common.collect.ImmutableList; -import static org.junit.Assert.*; - public class QueryUtilTest { private static final ColumnInfo ID_COLUMN = new ColumnInfo("ID", Types.BIGINT); @@ -61,10 +64,37 @@ public class QueryUtilTest { @Test public void testConstructSelectStatement() { assertEquals( - "SELECT \"ID\",\"NAME\" FROM \"MYTAB\"", + "SELECT \"ID\",\"NAME\" FROM MYTAB", QueryUtil.constructSelectStatement("MYTAB", ImmutableList.of(ID_COLUMN,NAME_COLUMN),null)); } + @Test + public void testConstructSelectStatementWithSchema() { + assertEquals( + "SELECT \"ID\",\"NAME\" FROM A.MYTAB", + QueryUtil.constructSelectStatement("A.MYTAB", ImmutableList.of(ID_COLUMN,NAME_COLUMN),null)); + } + + @Test + public void testConstructSelectStatementWithCaseSensitiveSchema() { + final String tableName = "MYTAB"; + final String schemaName = SchemaUtil.getEscapedArgument("a"); + final String fullTableName = SchemaUtil.getTableName(schemaName, tableName); + assertEquals( + "SELECT \"ID\",\"NAME\" FROM \"a\".MYTAB", + QueryUtil.constructSelectStatement(fullTableName, ImmutableList.of(ID_COLUMN,NAME_COLUMN),null)); + } + + @Test + public void testConstructSelectStatementWithCaseSensitiveTable() { + final String tableName = SchemaUtil.getEscapedArgument("mytab"); + final String schemaName = SchemaUtil.getEscapedArgument("a"); + final String fullTableName = SchemaUtil.getTableName(schemaName, tableName); + assertEquals( + "SELECT \"ID\",\"NAME\" FROM \"a\".\"mytab\"", + QueryUtil.constructSelectStatement(fullTableName, ImmutableList.of(ID_COLUMN,NAME_COLUMN),null)); + } + /** * Test that we create connection strings from the HBase Configuration that match the * expected syntax. Expected to log exceptions as it uses ZK host names that don't exist
