Return-Path: X-Original-To: apmail-phoenix-commits-archive@minotaur.apache.org Delivered-To: apmail-phoenix-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 78EF918512 for ; Sat, 4 Jul 2015 17:15:02 +0000 (UTC) Received: (qmail 10726 invoked by uid 500); 4 Jul 2015 17:15:02 -0000 Delivered-To: apmail-phoenix-commits-archive@phoenix.apache.org Received: (qmail 10684 invoked by uid 500); 4 Jul 2015 17:15:02 -0000 Mailing-List: contact commits-help@phoenix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@phoenix.apache.org Delivered-To: mailing list commits@phoenix.apache.org Received: (qmail 10646 invoked by uid 99); 4 Jul 2015 17:15:02 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 04 Jul 2015 17:15:02 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BDA53DFE65; Sat, 4 Jul 2015 17:15:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ravimagham@apache.org To: commits@phoenix.apache.org Date: Sat, 04 Jul 2015 17:15:02 -0000 Message-Id: <460b68bf8ecd443fb3d5eb4cf8945b0f@git.apache.org> In-Reply-To: <28ee47800ec9458383b88c288c420176@git.apache.org> References: <28ee47800ec9458383b88c288c420176@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/6] phoenix git commit: PHOENIX - 2036 PhoenixConfigurationUtil should provide a pre-normalize table name to PhoenixRuntime 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/dcacbc3b Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/dcacbc3b Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/dcacbc3b Branch: refs/heads/4.x-HBase-1.0 Commit: dcacbc3b00eb7d2ce03bb9d993f2fd0e0f9eb95a Parents: f264dbf Author: ravimagham Authored: Sat Jul 4 10:09:12 2015 -0700 Committer: ravimagham Committed: Sat Jul 4 10:09:12 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/dcacbc3b/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/dcacbc3b/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