You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2016/11/03 21:10:23 UTC

phoenix git commit: PHOENIX-3394 Handle SequenceResolving through ConnectionQueryServices interface

Repository: phoenix
Updated Branches:
  refs/heads/calcite 9f1eb6ef3 -> 605b25aff


PHOENIX-3394 Handle SequenceResolving through ConnectionQueryServices interface


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

Branch: refs/heads/calcite
Commit: 605b25affd6d462720a11b4f6d703f9c6dc22587
Parents: 9f1eb6e
Author: maryannxue <ma...@gmail.com>
Authored: Thu Nov 3 14:10:16 2016 -0700
Committer: maryannxue <ma...@gmail.com>
Committed: Thu Nov 3 14:10:16 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/calcite/CalciteIT.java   | 11 ++++++
 .../apache/phoenix/calcite/PhoenixSchema.java   | 38 ++++++++++----------
 2 files changed, 30 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/605b25af/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
index 5d60425..142fa1b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
@@ -1315,6 +1315,17 @@ public class CalciteIT extends BaseCalciteIT {
                         {6L, "00A323122312312"},
                         {8L, "00A423122312312"}})
                 .close();
+
+        start(false, 1000f).sql("select CURRENT VALUE FOR my.seq1, entity_id from aTable where a_string = 'a'")
+                .explainIs("PhoenixToEnumerableConverter\n" +
+                        "  PhoenixClientProject(EXPR$0=[CURRENT_VALUE('\"MY\".\"SEQ1\"')], ENTITY_ID=[$1])\n" +
+                        "    PhoenixTableScan(table=[[phoenix, ATABLE]], filter=[=($2, 'a')])\n")
+                .resultIs(1, new Object[][]{
+                        {8L, "00A123122312312"},
+                        {8L, "00A223122312312"},
+                        {8L, "00A323122312312"},
+                        {8L, "00A423122312312"}})
+                .close();
         
         start(false, 1000f).sql("SELECT NEXT VALUE FOR seq0, item.\"item_id\", item.name, supp.\"supplier_id\", supp.name FROM " + JOIN_ITEM_TABLE_FULL_NAME + " item JOIN " + JOIN_SUPPLIER_TABLE_FULL_NAME + " supp ON item.\"supplier_id\" = supp.\"supplier_id\"")
                 .explainIs("PhoenixToEnumerableConverter\n" +

http://git-wip-us.apache.org/repos/asf/phoenix/blob/605b25af/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index ac918b7..47b63fc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -14,19 +14,22 @@ import org.apache.calcite.schema.impl.ViewTable;
 import org.apache.calcite.sql.ListJarsTable;
 import org.apache.phoenix.compile.ColumnResolver;
 import org.apache.phoenix.compile.FromCompiler;
+import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.expression.function.UDFExpression;
 import org.apache.phoenix.jdbc.PhoenixConnection;
-import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.parse.ColumnDef;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.PFunction;
+import org.apache.phoenix.parse.SequenceValueParseNode;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.schema.MetaDataClient;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.schema.PTable.ViewType;
 import org.apache.phoenix.schema.PTableImpl;
 import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.Sequence;
 import org.apache.phoenix.schema.TableNotFoundException;
 import org.apache.phoenix.schema.TableRef;
 import org.apache.phoenix.util.IndexUtil;
@@ -34,7 +37,6 @@ import org.apache.phoenix.util.SchemaUtil;
 
 import java.sql.Connection;
 import java.sql.DriverManager;
-import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -62,6 +64,7 @@ public class PhoenixSchema implements Schema {
     protected final String schemaName;
     protected final SchemaPlus parentSchema;
     protected final MetaDataClient client;
+    protected final SequenceManager sequenceManager;
     
     protected final Map<String, Schema> subSchemas;
     protected final Map<String, Table> tables;
@@ -83,6 +86,12 @@ public class PhoenixSchema implements Schema {
         this.views = Maps.newHashMap();
         this.views.put("ListJars", listJarsFunction);
         this.viewTables = Sets.newHashSet();
+        try {
+            PhoenixStatement stmt = (PhoenixStatement) pc.createStatement();
+            this.sequenceManager = new SequenceManager(stmt);
+        } catch (SQLException e){
+            throw new RuntimeException(e);
+        }
 
     }
 
@@ -329,24 +338,15 @@ public class PhoenixSchema implements Schema {
     
     private PhoenixSequence resolveSequence(String name) {
         try {
-            // FIXME: Do this the same way as resolving a table after PHOENIX-2489.
-            String tenantId = pc.getTenantId() == null ? null : pc.getTenantId().getString();
-            String q = "select 1 from " + PhoenixDatabaseMetaData.SYSTEM_SEQUENCE
-                    + " where " + PhoenixDatabaseMetaData.SEQUENCE_SCHEMA
-                    + (schemaName == null ? " is null" : " = '" + schemaName + "'")
-                    + " and " + PhoenixDatabaseMetaData.SEQUENCE_NAME
-                    + " = '" + name + "'"
-                    + " and " + PhoenixDatabaseMetaData.TENANT_ID
-                    + (tenantId == null ? " is null" : " = '" + tenantId + "'");
-            ResultSet rs = pc.createStatement().executeQuery(q);
-            if (rs.next()) {
-                return new PhoenixSequence(schemaName, name, pc);
-            }
-        } catch (SQLException e) {
-            throw new RuntimeException(e);
+            sequenceManager.newSequenceReference(pc.getTenantId(),
+                    TableName.createNormalized(schemaName, name) ,
+                    null, SequenceValueParseNode.Op.NEXT_VALUE);
+            sequenceManager.validateSequences(Sequence.ValueOp.VALIDATE_SEQUENCE);
+        } catch (SQLException e){
+            return null;
         }
-        
-        return null;
+
+        return new PhoenixSequence(schemaName, name, pc);
     }
 
     /** Schema factory that creates a