phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravimag...@apache.org
Subject [6/6] phoenix git commit: PHOENIX - 2036 PhoenixConfigurationUtil should provide a pre-normalize table name to PhoenixRuntime
Date Sat, 04 Jul 2015 17:15:06 GMT
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/de1c709e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/de1c709e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/de1c709e

Branch: refs/heads/4.4-HBase-0.98
Commit: de1c709e4841d0358edf7ba291d7b36fbcebbd2e
Parents: d8c066e
Author: ravimagham <ravimagham@apache.org>
Authored: Sat Jul 4 10:13:40 2015 -0700
Committer: ravimagham <ravimagham@apache.org>
Committed: Sat Jul 4 10:13:40 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/de1c709e/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/de1c709e/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


Mime
View raw message