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-1799 Provide parameter metadata for prepared create table statements
Date Thu, 02 Apr 2015 23:34:45 GMT
Repository: phoenix
Updated Branches:
  refs/heads/master 4859fb9d6 -> eb7327113


PHOENIX-1799 Provide parameter metadata for prepared create table statements


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

Branch: refs/heads/master
Commit: eb7327113c1310af209015cf84caec339930ae3e
Parents: 4859fb9
Author: James Taylor <jtaylor@salesforce.com>
Authored: Thu Apr 2 13:32:47 2015 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Thu Apr 2 16:34:41 2015 -0700

----------------------------------------------------------------------
 .../phoenix/compile/CreateTableCompiler.java    | 37 ++++++++++++++++++++
 .../phoenix/compile/QueryMetaDataTest.java      | 11 ++++++
 2 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb732711/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
index edee788..a5adc49 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/CreateTableCompiler.java
@@ -41,6 +41,7 @@ import org.apache.phoenix.expression.RowKeyColumnExpression;
 import org.apache.phoenix.expression.visitor.StatelessTraverseNoExpressionVisitor;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
+import org.apache.phoenix.parse.BindParseNode;
 import org.apache.phoenix.parse.ColumnParseNode;
 import org.apache.phoenix.parse.CreateTableStatement;
 import org.apache.phoenix.parse.ParseNode;
@@ -50,11 +51,15 @@ import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.DelegateConnectionQueryServices;
 import org.apache.phoenix.schema.ColumnRef;
 import org.apache.phoenix.schema.MetaDataClient;
+import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PMetaData;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.TableRef;
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PVarbinary;
 import org.apache.phoenix.util.ByteUtil;
 import org.apache.phoenix.util.QueryUtil;
 
@@ -62,6 +67,7 @@ import com.google.common.collect.Iterators;
 
 
 public class CreateTableCompiler {
+    private static final PDatum VARBINARY_DATUM = new VarbinaryDatum();
     private final PhoenixStatement statement;
     
     public CreateTableCompiler(PhoenixStatement statement) {
@@ -151,6 +157,9 @@ public class CreateTableCompiler {
         ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);
         for (int i = 0; i < splits.length; i++) {
             ParseNode node = splitNodes.get(i);
+            if (node instanceof BindParseNode) {
+                context.getBindManager().addParamMetaData((BindParseNode) node, VARBINARY_DATUM);
+            }
             if (node.isStateless()) {
                 Expression expression = node.accept(expressionCompiler);
                 if (expression.evaluate(null, ptr)) {;
@@ -302,4 +311,32 @@ public class CreateTableCompiler {
         }
         
     }
+    private static class VarbinaryDatum implements PDatum {
+
+        @Override
+        public boolean isNullable() {
+            return false;
+        }
+
+        @Override
+        public PDataType getDataType() {
+            return PVarbinary.INSTANCE;
+        }
+
+        @Override
+        public Integer getMaxLength() {
+            return null;
+        }
+
+        @Override
+        public Integer getScale() {
+            return null;
+        }
+
+        @Override
+        public SortOrder getSortOrder() {
+            return SortOrder.getDefault();
+        }
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb732711/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryMetaDataTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryMetaDataTest.java
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryMetaDataTest.java
index 73ba2a4..bf11b72 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryMetaDataTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryMetaDataTest.java
@@ -441,4 +441,15 @@ public class QueryMetaDataTest extends BaseConnectionlessQueryTest {
         assertEquals(String.class.getName(), pmd.getParameterClassName(2));
         assertEquals(String.class.getName(), pmd.getParameterClassName(3));
     }
+    
+    @Test
+    public void testBindParamMetaDataForCreateTable() throws Exception {
+        String ddl = "CREATE TABLE foo (k VARCHAR PRIMARY KEY) SPLIT ON (?, ?)";
+        Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES));
+        PreparedStatement statement = conn.prepareStatement(ddl);
+        ParameterMetaData pmd = statement.getParameterMetaData();
+        assertEquals(2, pmd.getParameterCount());
+        assertEquals(byte[].class.getName(), pmd.getParameterClassName(1));
+        assertEquals(byte[].class.getName(), pmd.getParameterClassName(2));
+    }
 }


Mime
View raw message