You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ya...@apache.org on 2020/10/29 01:02:33 UTC

[phoenix] branch 4.x updated: PHOENIX-6158 create table/view should not update VIEW_INDEX_ID_DATA_TYPE column

This is an automated email from the ASF dual-hosted git repository.

yanxinyi pushed a commit to branch 4.x
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/4.x by this push:
     new 2aaf2e2  PHOENIX-6158 create table/view should not update VIEW_INDEX_ID_DATA_TYPE column
2aaf2e2 is described below

commit 2aaf2e2f678a3389e148e85dad2085b84cc03967
Author: Xinyi Yan <ya...@apache.org>
AuthorDate: Wed Oct 28 17:48:27 2020 -0700

    PHOENIX-6158 create table/view should not update VIEW_INDEX_ID_DATA_TYPE column
    
    Signed-off-by: Xinyi Yan <ya...@apache.org>
---
 .../apache/phoenix/end2end/index/ViewIndexIT.java  | 52 ++++++++++++++++++++++
 .../org/apache/phoenix/schema/MetaDataClient.java  |  9 +++-
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
index 18ad2b7..9a3f648 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/index/ViewIndexIT.java
@@ -17,11 +17,17 @@
  */
 package org.apache.phoenix.end2end.index;
 
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.COLUMN_COUNT;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_NAME;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.TABLE_SCHEM;
+import static org.apache.phoenix.jdbc.PhoenixDatabaseMetaData.VIEW_INDEX_ID_DATA_TYPE;
 import static org.apache.phoenix.util.MetaDataUtil.getViewIndexSequenceName;
 import static org.apache.phoenix.util.MetaDataUtil.getViewIndexSequenceSchemaName;
 import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -33,6 +39,7 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.Types;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -53,6 +60,7 @@ import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.KeyRange;
 import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
 import org.apache.phoenix.schema.PNameFactory;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.TableNotFoundException;
@@ -626,4 +634,48 @@ public class ViewIndexIT extends SplitSystemCatalogIT {
       }
       return size;
     }
+
+    @Test
+    public void testIndexIdDataTypeDefaultValue() throws Exception {
+        String tableName = "T_" + generateUniqueName();
+        String globalViewName = "V_" + generateUniqueName();
+        String globalViewIndexName = "GV_" + generateUniqueName();
+        try (Connection globalConn = getConnection()) {
+            createBaseTable(SCHEMA1, tableName, true, 0, null, true);
+            createView(globalConn, SCHEMA1, globalViewName, tableName);
+            createViewIndex(globalConn, SCHEMA1, globalViewIndexName, globalViewName, "v1");
+
+            String sql = "SELECT " + VIEW_INDEX_ID_DATA_TYPE + " FROM " + SYSTEM_CATALOG_NAME + " WHERE " +
+                    TABLE_SCHEM + " = '%s' AND " +
+                    TABLE_NAME + " = '%s' AND " +
+                    COLUMN_COUNT + " IS NOT NULL";
+            // should not have default value for table
+            ResultSet rs = globalConn.createStatement().executeQuery(String.format(sql, SCHEMA1, tableName));
+            if (rs.next()) {
+                assertNull(rs.getObject(1));
+            } else {
+                fail();
+            }
+            // should not have default value for view
+            rs = globalConn.createStatement().executeQuery(String.format(sql, SCHEMA1, globalViewName));
+            if (rs.next()) {
+                assertNull(rs.getObject(1));
+            } else {
+                fail();
+            }
+            // should have default value
+            rs = globalConn.createStatement().executeQuery(String.format(sql, SCHEMA1, globalViewIndexName));
+            if (rs.next()) {
+            /*
+                quote from hbase-site.xml so default value is BIGINT
+                We have some hardcoded viewIndex ids in the IT tests which assumes viewIndexId is of type Long.
+                However the default viewIndexId type is set to "short" by default until we upgrade all clients to
+                 support  long viewIndex ids.
+             */
+                assertEquals(Types.BIGINT, rs.getInt(1));
+            } else {
+                fail();
+            }
+        }
+    }
 }
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 5843421..f18c9f3 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
@@ -2954,7 +2954,14 @@ public class MetaDataClient {
             } else {
                 tableUpsert.setBoolean(28, useStatsForParallelizationProp);
             }
-            tableUpsert.setInt(29, viewIndexIdType.getSqlType());
+            if (indexType == IndexType.LOCAL ||
+                    (parent != null && parent.getType() == PTableType.VIEW
+                            && tableType == PTableType.INDEX)) {
+                tableUpsert.setInt(29, viewIndexIdType.getSqlType());
+            } else {
+                tableUpsert.setNull(29, Types.NULL);
+            }
+
             if (phoenixTTL == null || phoenixTTL == PHOENIX_TTL_NOT_DEFINED) {
                 tableUpsert.setNull(30, Types.BIGINT);
                 tableUpsert.setNull(31, Types.BIGINT);