You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@phoenix.apache.org by GitBox <gi...@apache.org> on 2020/06/05 05:41:07 UTC

[GitHub] [phoenix] abhishek-chouhan commented on a change in pull request #797: PHOENIX-5932 View Index rebuild results in surplus rows from other vi…

abhishek-chouhan commented on a change in pull request #797:
URL: https://github.com/apache/phoenix/pull/797#discussion_r435700547



##########
File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
##########
@@ -208,6 +209,195 @@ protected static void setEveryNthRowWithNull(int nrows, int nthRowNull, Prepared
         }
     }
 
+    @Test
+    public void testUpdatableViewIndex() throws Exception {
+        if (!mutable || transactional || localIndex || useTenantId) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, dataTableName);
+        String view1Name = generateUniqueName();
+        String view1FullName = SchemaUtil.getTableName(schemaName, view1Name);
+        String view2Name = generateUniqueName();
+        String view2FullName = SchemaUtil.getTableName(schemaName, view2Name);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            // Create Table and Views
+            String createTable =
+                    "CREATE TABLE IF NOT EXISTS " + dataTableFullName + " (\n"
+                            + "    ORGANIZATION_ID VARCHAR NOT NULL,\n"
+                            + "    KEY_PREFIX CHAR(3) NOT NULL,\n" + "    CREATED_BY VARCHAR,\n"
+                            + "    CONSTRAINT PK PRIMARY KEY (\n" + "        ORGANIZATION_ID,\n"
+                            + "        KEY_PREFIX\n" + "    )\n"
+                            + ") VERSIONS=1, COLUMN_ENCODED_BYTES=0";
+            conn.createStatement().execute(createTable);
+            String createView1 =
+                    "CREATE VIEW IF NOT EXISTS " + view1FullName + " (\n"
+                            + " VIEW_COLA VARCHAR NOT NULL,\n"
+                            + " VIEW_COLB CHAR(1) CONSTRAINT PKVIEW PRIMARY KEY (\n"
+                            + " VIEW_COLA\n" + " )) AS \n" + " SELECT * FROM " + dataTableFullName
+                            + " WHERE KEY_PREFIX = 'aaa'";
+            conn.createStatement().execute(createView1);
+            String createView2 =
+                    "CREATE VIEW IF NOT EXISTS " + view2FullName + " (\n"
+                            + " VIEW_COL1 VARCHAR NOT NULL,\n"
+                            + " VIEW_COL2 CHAR(1) CONSTRAINT PKVIEW PRIMARY KEY (\n"
+                            + " VIEW_COL1\n" + " )) AS \n" + " SELECT * FROM " + dataTableFullName
+                            + " WHERE KEY_PREFIX = 'ccc'";
+            conn.createStatement().execute(createView2);
+
+            // We want to verify if deletes and set null result in expected rebuild of view index
+            conn.createStatement().execute("UPSERT INTO " + view1FullName
+                    + "(ORGANIZATION_ID, VIEW_COLA, VIEW_COLB) VALUES('ORG1', 'A', 'G')");
+            conn.createStatement().execute("UPSERT INTO " + view1FullName
+                    + "(ORGANIZATION_ID, VIEW_COLA, VIEW_COLB) VALUES('ORG1', 'C', 'I')");
+            conn.createStatement().execute("UPSERT INTO " + view1FullName
+                    + "(ORGANIZATION_ID, VIEW_COLA, VIEW_COLB) VALUES('ORG1', 'D', 'J')");
+
+            conn.createStatement().execute("UPSERT INTO " + view2FullName
+                    + "(ORGANIZATION_ID, VIEW_COL1, VIEW_COL2) VALUES('ORG2', 'B', 'H')");
+            conn.commit();
+            conn.createStatement().execute("DELETE FROM " + view1FullName
+                    + " WHERE ORGANIZATION_ID = 'ORG1' AND VIEW_COLA = 'C'");
+            conn.createStatement().execute("UPSERT INTO " + view1FullName
+                    + "(ORGANIZATION_ID, VIEW_COLA, VIEW_COLB) VALUES('ORG1', 'D', NULL)");
+            conn.commit();
+
+            String createViewIndex =
+                    "CREATE INDEX IF NOT EXISTS " + indexTableName + " ON " + view1FullName
+                            + " (VIEW_COLB) ASYNC";
+            conn.createStatement().execute(createViewIndex);
+            conn.commit();
+            // Rebuild using index tool
+            runIndexTool(directApi, useSnapshot, schemaName, view1Name, indexTableName);
+            ResultSet rs =
+                    conn.createStatement()
+                            .executeQuery("SELECT COUNT(*) FROM " + indexTableFullName);
+            rs.next();
+            assertEquals(2, rs.getInt(1));
+
+            try (org.apache.hadoop.hbase.client.Connection hcon =
+                    ConnectionFactory.createConnection(config)) {
+                Table htable = hcon.getTable(TableName.valueOf("_IDX_" + dataTableFullName));
+                Scan scan = new Scan();
+                scan.setRaw(true);
+                ResultScanner scanner = htable.getScanner(scan);
+                int numPuts = 0;
+                int numDeletes = 0;
+                for (Result result = scanner.next(); result != null; result = scanner.next()) {
+                    for (Cell cell : result.rawCells()) {
+                        if (KeyValue.Type.codeToType(cell.getTypeByte()) == KeyValue.Type.Put) {
+                            numPuts++;
+                        } else if (KeyValue.Type
+                                .codeToType(cell.getTypeByte()) == KeyValue.Type.DeleteFamily) {
+                                    numDeletes++;
+                                }
+                    }
+                }
+                assertEquals(4, numPuts);
+                assertEquals(2, numDeletes);
+            }
+        }
+    }
+
+    @Test
+    public void testUpdatableViewIndex2() throws Exception {

Review comment:
       Tried a more descriptive name in the latest commit :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org