You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2015/04/03 02:01:48 UTC

[1/2] phoenix git commit: PHOENIX-1799 Provide parameter metadata for prepared create table statements

Repository: phoenix
Updated Branches:
  refs/heads/3.0 2742cdced -> f490692c2


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/a828537d
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/a828537d
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/a828537d

Branch: refs/heads/3.0
Commit: a828537d398a602015e144aa67cc1af6d8e54cb2
Parents: 2742cdc
Author: James Taylor <jt...@salesforce.com>
Authored: Thu Apr 2 13:32:47 2015 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Thu Apr 2 16:46:30 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/a828537d/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 ade8345..ac50285 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.TraverseNoExpressionVisitor;
 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) {
@@ -149,6 +155,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)) {;
@@ -300,4 +309,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/a828537d/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));
+    }
 }


[2/2] phoenix git commit: PHOENIX-1776 The literal -1.0 (floating point) should not be converted to -1 (Integer) (Dave Hacker)

Posted by ja...@apache.org.
PHOENIX-1776 The literal -1.0 (floating point) should not be converted to -1 (Integer) (Dave Hacker)

Conflicts:
	phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java


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

Branch: refs/heads/3.0
Commit: f490692c2935707497153381312bbf8fea709749
Parents: a828537
Author: Samarth <sa...@salesforce.com>
Authored: Thu Mar 26 00:37:12 2015 -0700
Committer: James Taylor <jt...@salesforce.com>
Committed: Thu Apr 2 16:57:06 2015 -0700

----------------------------------------------------------------------
 .../phoenix/end2end/ArithmeticQueryIT.java      | 28 ++++++++++++++++++++
 .../phoenix/compile/CreateTableCompiler.java    |  5 ++--
 .../apache/phoenix/parse/LiteralParseNode.java  |  1 +
 .../apache/phoenix/parse/ParseNodeFactory.java  | 11 ++++++--
 4 files changed, 40 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
index 21af737..3cb4b57 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ArithmeticQueryIT.java
@@ -857,4 +857,32 @@ public class ArithmeticQueryIT extends BaseHBaseManagedTimeIT {
         assertTrue(rs.next());
         assertEquals(1.333333333, rs.getDouble(1), 0.001);
     }
+
+    @Test
+    public void testFloatingPointUpsert() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE test (id VARCHAR not null primary key, name VARCHAR, lat FLOAT)";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO test(id,name,lat) VALUES ('testid', 'testname', -1.00)";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT lat FROM test");
+        assertTrue(rs.next());
+        assertEquals(-1.0f, rs.getFloat(1), 0.001);
+    }
+
+    @Test
+    public void testFloatingPointMultiplicationUpsert() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE test (id VARCHAR not null primary key, name VARCHAR, lat FLOAT)";
+        conn.createStatement().execute(ddl);
+        String dml = "UPSERT INTO test(id,name,lat) VALUES ('testid', 'testname', -1.00 * 1)";
+        conn.createStatement().execute(dml);
+        conn.commit();
+
+        ResultSet rs = conn.createStatement().executeQuery("SELECT lat FROM test");
+        assertTrue(rs.next());
+        assertEquals(-1.0f, rs.getFloat(1), 0.001);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/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 ac50285..4af0cc9 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
@@ -51,6 +51,7 @@ 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.PDataType;
 import org.apache.phoenix.schema.PDatum;
 import org.apache.phoenix.schema.PMetaData;
 import org.apache.phoenix.schema.PTable;
@@ -58,8 +59,6 @@ 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;
 
@@ -318,7 +317,7 @@ public class CreateTableCompiler {
 
         @Override
         public PDataType getDataType() {
-            return PVarbinary.INSTANCE;
+            return PDataType.VARBINARY;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
index f9bbea1..a291b2a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/LiteralParseNode.java
@@ -37,6 +37,7 @@ public class LiteralParseNode extends TerminalParseNode {
     public static final ParseNode NULL = new LiteralParseNode(null);
     public static final ParseNode ZERO = new LiteralParseNode(0);
     public static final ParseNode ONE = new LiteralParseNode(1);
+    public static final ParseNode MINUS_ONE = new LiteralParseNode(-1L);
     
     private final Object value;
     private final PDataType type;

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f490692c/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 9ab31b1..7d14e58 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -542,8 +542,15 @@ public class ParseNodeFactory {
     	return new ArrayConstructorNode(upsertStmtArray);
     }
 
-    public MultiplyParseNode negate(ParseNode child) {
-        return new MultiplyParseNode(Arrays.asList(child,this.literal(-1)));
+
+    public ParseNode negate(ParseNode child) {
+        // Prevents reparsing of -1 from becoming 1*-1 and 1*1*-1 with each re-parsing
+        if (LiteralParseNode.ONE.equals(child) && ((LiteralParseNode)child).getType().isCoercibleTo(
+                PDataType.LONG)) {
+            return LiteralParseNode.MINUS_ONE;
+        }
+        return new MultiplyParseNode(Arrays.asList(child,LiteralParseNode.MINUS_ONE));
+
     }
 
     public NotEqualParseNode notEqual(ParseNode lhs, ParseNode rhs) {