phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject phoenix git commit: PHOENIX-1682 PhoenixRuntime.getTable() does not work with case-sensitive table names (Ivan Weiss)
Date Tue, 21 Apr 2015 23:29:42 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 572fa3c65 -> ed7d0e978


PHOENIX-1682 PhoenixRuntime.getTable() does not work with case-sensitive table names (Ivan
Weiss)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/ed7d0e97
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/ed7d0e97
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/ed7d0e97

Branch: refs/heads/master
Commit: ed7d0e978ecc46dec7fd2ae1eb99a32de9c8c32a
Parents: 572fa3c
Author: James Taylor <jtaylor@salesforce.com>
Authored: Tue Apr 21 16:28:02 2015 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Tue Apr 21 16:28:02 2015 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/util/PhoenixRuntime.java |  8 ++-
 .../apache/phoenix/util/PhoenixRuntimeTest.java | 75 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ed7d0e97/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
index b2736aa..8eaeefb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java
@@ -309,11 +309,17 @@ public class PhoenixRuntime {
         };
     }
 
+    /**
+     * 
+     * @param conn
+     * @param name requires a pre-normalized table name or a pre-normalized schema and table
name
+     * @return
+     * @throws SQLException
+     */
     public static PTable getTable(Connection conn, String name) throws SQLException {
         PTable table = null;
         PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
         try {
-            name = SchemaUtil.normalizeIdentifier(name);
             table = pconn.getMetaDataCache().getTable(new PTableKey(pconn.getTenantId(),
name));
         } catch (TableNotFoundException e) {
             String schemaName = SchemaUtil.getSchemaNameFromFullName(name);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ed7d0e97/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
index c1f3244..b6465c3 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/util/PhoenixRuntimeTest.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.fail;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.sql.SQLFeatureNotSupportedException;
 import java.util.ArrayList;
 import java.util.List;
@@ -39,6 +40,7 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
+import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.types.PDataType;
 import org.junit.Test;
@@ -213,4 +215,77 @@ public class PhoenixRuntimeTest extends BaseConnectionlessQueryTest {
             // Expected
         }
     }
+    
+    @Test
+    public void testTableNameWithoutSchema() throws Exception {
+        String tableName = "tableName";
+        String tableNameNormalized = tableName.toUpperCase(); 
+        
+        getTableTester(tableNameNormalized, tableName);
+    }
+
+    @Test
+    public void testTableNameWithSchema() throws Exception {
+        String tableName = "tableName";
+        String schemaName = "schemaName";
+        String fullName = schemaName + "." + tableName;
+        String fullNameNormalized = fullName.toUpperCase(); 
+        
+        getTableTester(fullNameNormalized, fullName);
+    }
+    
+    @Test
+    public void testCaseSensitiveTableNameWithoutSchema() throws Exception {
+        String caseSensitiveTableName = "tableName"; 
+        
+        getTableTester(caseSensitiveTableName, quoteString(caseSensitiveTableName));
+    }
+    
+    @Test
+    public void testCaseSensitiveTableNameWithSchema() throws Exception {
+        String caseSensitiveTableName = "tableName"; 
+        String schemaName = "schemaName";
+        String fullNameNormalized = schemaName.toUpperCase() + "." + caseSensitiveTableName;
+        String fullNameQuoted = schemaName + "." + quoteString(caseSensitiveTableName);
+        
+        getTableTester(fullNameNormalized, fullNameQuoted);
+    }
+    
+    @Test
+    public void testCaseSensitiveTableNameWithCaseSensitiveSchema() throws Exception {
+        String caseSensitiveTableName = "tableName";
+        String caseSensitiveSchemaName = "schemaName";
+        String fullName = caseSensitiveSchemaName + "." + caseSensitiveTableName;
+        String fullNameQuoted = quoteString(caseSensitiveSchemaName) + "." + quoteString(caseSensitiveTableName);
+        
+        getTableTester(fullName, fullNameQuoted);
+    }
+
+    @Test
+    public void testCaseSensitiveTableNameWithCaseSensitiveSchemaWithPeriod() throws Exception
{
+        String caseSensitiveTableName = "tableName";
+        String caseSensitiveSchemaName = "schema.Name";
+        String fullName = caseSensitiveSchemaName + "." + caseSensitiveTableName;
+        String fullNameQuoted = quoteString(caseSensitiveSchemaName) + "." + quoteString(caseSensitiveTableName);
+        
+        getTableTester(fullName, fullNameQuoted);
+    }
+    
+    private void getTableTester(String normalizedName, String sqlStatementName) throws SQLException
{
+        Connection conn = DriverManager.getConnection(getUrl());
+        try {
+            conn.createStatement().execute("CREATE TABLE " + sqlStatementName + " (k VARCHAR
PRIMARY KEY)");
+            PTable aTable = PhoenixRuntime.getTable(conn, normalizedName);
+            assertNotNull(aTable);
+        } finally {
+            if (null != conn) {
+                conn.createStatement().execute("DROP TABLE IF EXISTS " + sqlStatementName);
+            }
+        }
+    }
+    
+    private String quoteString(String string) {
+        return "\"" + string + "\"";
+    }
+
 }


Mime
View raw message