phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject git commit: PHOENIX-1368 Persist link from VIEW back to its child VIEW
Date Mon, 20 Oct 2014 06:47:06 GMT
Repository: phoenix
Updated Branches:
  refs/heads/3.0 d9e58958a -> d3f01f3b2


PHOENIX-1368 Persist link from VIEW back to its child VIEW

Conflicts:
	phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java


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

Branch: refs/heads/3.0
Commit: d3f01f3b2d2772bdd56ac5876e7b6b86aaa8dd43
Parents: d9e5895
Author: James Taylor <jtaylor@salesforce.com>
Authored: Sun Oct 19 23:46:39 2014 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Sun Oct 19 23:52:49 2014 -0700

----------------------------------------------------------------------
 .../coprocessor/MetaDataEndpointImpl.java       |  2 --
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |  4 ++++
 .../apache/phoenix/schema/MetaDataClient.java   | 22 ++++++++++++++++++++
 .../java/org/apache/phoenix/schema/PTable.java  |  6 +++++-
 4 files changed, 31 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d3f01f3b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
index 0f6fa27..f7c0aae 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
@@ -452,8 +452,6 @@ public class MetaDataEndpointImpl extends BaseEndpointCoprocessor implements
Met
                     addIndexToTable(tenantId, schemaName, famName, tableName, clientTimeStamp,
indexes);
                 } else if (linkType == LinkType.PHYSICAL_TABLE) {
                     physicalTables.add(famName);
-                } else {
-                    logger.warn("Unknown link type: " + colKv.getBuffer()[colKv.getValueOffset()]
+ " for " + SchemaUtil.getTableName(schemaName.getString(), tableName.getString()));
                 }
             } else {
                 addColumnToTable(results, colName, famName, colKeyValues, columns, saltBucketNum
!= null);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d3f01f3b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
index 852bbb1..f0b709c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixDatabaseMetaData.java
@@ -248,6 +248,10 @@ public class PhoenixDatabaseMetaData implements DatabaseMetaData, org.apache.pho
     public static final byte[] MAX_KEY_BYTES = Bytes.toBytes(MAX_KEY);
     public static final String LAST_STATS_UPDATE_TIME = "LAST_STATS_UPDATE_TIME";
     public static final byte[] LAST_STATS_UPDATE_TIME_BYTES = Bytes.toBytes(LAST_STATS_UPDATE_TIME);
+
+    public static final String PARENT_TENANT_ID = "PARENT_TENANT_ID";
+    public static final byte[] PARENT_TENANT_ID_BYTES = Bytes.toBytes(PARENT_TENANT_ID);
+        
     private final PhoenixConnection connection;
     private final ResultSet emptyResultSet;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d3f01f3b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
index 3941e17..5ce2f93 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java
@@ -41,6 +41,7 @@ import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.LINK_TYPE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.MULTI_TENANT;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.NULLABLE;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.ORDINAL_POSITION;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PARENT_TENANT_ID;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PHYSICAL_NAME;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.PK_NAME;
 import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.REGION_NAME;
@@ -174,6 +175,15 @@ public class MetaDataClient {
             COLUMN_FAMILY + "," +
             LINK_TYPE +
             ") VALUES (?, ?, ?, ?, ?)";
+    private static final String CREATE_VIEW_LINK =
+            "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"(
" +
+            TENANT_ID + "," +
+            TABLE_SCHEM + "," +
+            TABLE_NAME + "," +
+            COLUMN_FAMILY + "," +
+            LINK_TYPE + "," +
+            PARENT_TENANT_ID + " " + PDataType.VARCHAR.getSqlTypeName() + // Dynamic column
for now to prevent schema change
+            ") VALUES (?, ?, ?, ?, ?, ?)";
     private static final String INCREMENT_SEQ_NUM =
             "UPSERT INTO " + SYSTEM_CATALOG_SCHEMA + ".\"" + SYSTEM_CATALOG_TABLE + "\"(
" + 
             TENANT_ID + "," +
@@ -1111,6 +1121,18 @@ public class MetaDataClient {
                     columns = newArrayListWithExpectedSize(allColumns.size() + colDefs.size());
                     columns.addAll(allColumns);
                     pkColumns = newLinkedHashSet(parent.getPKColumns());
+                    
+                    // Add row linking from view to its parent table
+                    // FIXME: not currently used, but see PHOENIX-1367
+                    // as fixing that will require it's usage.
+                    PreparedStatement linkStatement = connection.prepareStatement(CREATE_VIEW_LINK);
+                    linkStatement.setString(1, connection.getTenantId() == null ? null :
connection.getTenantId().getString());
+                    linkStatement.setString(2, schemaName);
+                    linkStatement.setString(3, tableName);
+                    linkStatement.setString(4, parent.getName().getString());
+                    linkStatement.setByte(5, LinkType.PARENT_TABLE.getSerializedValue());
+                    linkStatement.setString(6, parent.getTenantId() == null ? null : parent.getTenantId().getString());
+                    linkStatement.execute();
                 }
             } else {
                 columns = newArrayListWithExpectedSize(colDefs.size());

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d3f01f3b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
index 01e766d..acb6d1f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PTable.java
@@ -89,7 +89,11 @@ public interface PTable extends Writable {
         /**
          * Link from a view to its physical table
          */
-        PHYSICAL_TABLE((byte)2);
+        PHYSICAL_TABLE((byte)2),
+        /**
+         * Link from a view to its parent table
+         */
+        PARENT_TABLE((byte)3);
 
         private final byte[] byteValue;
         private final byte serializedValue;


Mime
View raw message