gokceni commented on a change in pull request #1371:
URL: https://github.com/apache/phoenix/pull/1371#discussion_r781759846



##########
File path: 
phoenix-core/src/it/java/org/apache/phoenix/end2end/TransformToolIT.java
##########
@@ -413,59 +431,314 @@ public void testTransformMutationFailureRepair() throws 
Exception {
         String schemaName = generateUniqueName();
         String dataTableName = generateUniqueName();
         String dataTableFullName = SchemaUtil.getTableName(schemaName, 
dataTableName);
+        String parentViewName = "VWP_" + generateUniqueName();
+        String viewName = "VW_" + generateUniqueName();
+        String viewIdxName = "VWIDX_" + generateUniqueName();
 
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
             conn.setAutoCommit(true);
-            IndexRegionObserver.setFailPreIndexUpdatesForTesting(true);
             int numOfRows = 0;
             createTableAndUpsertRows(conn, dataTableFullName, numOfRows);
+            String createParentViewSql = "CREATE VIEW " + parentViewName + " ( 
PARENT_VIEW_COL1 VARCHAR ) AS SELECT * FROM " + dataTableFullName;
+            conn.createStatement().execute(createParentViewSql);
+
+            String createViewSql = "CREATE VIEW " + viewName + " ( VIEW_COL1 
INTEGER, VIEW_COL2 VARCHAR ) AS SELECT * FROM " + parentViewName;
+            conn.createStatement().execute(createViewSql);
+
+            String createViewIdxSql = "CREATE INDEX " + viewIdxName + " ON " + 
viewName + " (VIEW_COL1) include (VIEW_COL2) ";
+            conn.createStatement().execute(createViewIdxSql);
+
             SingleCellIndexIT.assertMetadata(conn, 
PTable.ImmutableStorageScheme.ONE_CELL_PER_COLUMN, 
PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, dataTableFullName);
 
             conn.createStatement().execute("ALTER TABLE " + dataTableFullName +
                     " SET 
IMMUTABLE_STORAGE_SCHEME=SINGLE_CELL_ARRAY_WITH_OFFSETS, 
COLUMN_ENCODED_BYTES=2");
             SystemTransformRecord record = 
Transform.getTransformRecord(schemaName, dataTableName, null, null, 
conn.unwrap(PhoenixConnection.class));
             assertNotNull(record);
             assertMetadata(conn, 
PTable.ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS, 
PTable.QualifierEncodingScheme.TWO_BYTE_QUALIFIERS, 
record.getNewPhysicalTableName());
-
-            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, 
?)", dataTableFullName);
+            IndexRegionObserver.setFailPreIndexUpdatesForTesting(true);
+            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, 
?)", viewName);
             PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
             try {
                 IndexToolIT.upsertRow(stmt1, 1);
                 fail("Transform table upsert should have failed");
             } catch (Exception e) {
             }
             assertEquals(0, getRowCount(conn, 
record.getNewPhysicalTableName()));
-            assertEquals(0, getRowCount(conn,dataTableFullName));
+            assertEquals(0, getRowCount(conn, dataTableFullName));
 
             IndexRegionObserver.setFailPreIndexUpdatesForTesting(false);
             IndexRegionObserver.setFailPostIndexUpdatesForTesting(true);
             IndexToolIT.upsertRow(stmt1, 2);
+            IndexToolIT.upsertRow(stmt1, 3);
 
-            assertEquals(1, getRowCount(conn, 
record.getNewPhysicalTableName()));
-            assertEquals(1, getRowCount(conn,dataTableFullName));
+            assertEquals(2, getRowCount(conn, 
record.getNewPhysicalTableName()));
+            assertEquals(2, getRowCount(conn,dataTableFullName));
 
             IndexRegionObserver.setFailPostIndexUpdatesForTesting(false);
             IndexRegionObserver.setFailDataTableUpdatesForTesting(true);
             try {
-                IndexToolIT.upsertRow(stmt1, 3);
+                IndexToolIT.upsertRow(stmt1, 4);
                 fail("Data table upsert should have failed");
             } catch (Exception e) {
             }
-            assertEquals(2, getRowCount(conn, 
record.getNewPhysicalTableName()));
-            assertEquals(1, getRowCount(conn,dataTableFullName));
+            try {
+                IndexToolIT.upsertRow(stmt1, 5);
+                fail("Data table upsert should have failed");
+            } catch (Exception e) {
+            }
+            assertEquals(4, getRowCount(conn, 
record.getNewPhysicalTableName()));
+            assertEquals(2, getRowCount(conn,dataTableFullName));
 
             IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
 
             List<String> args = getArgList(schemaName, dataTableName, null,
-                    null, null, null, false, false, false, false);
+                    null, null, null, false, false, false, false, true);
             runTransformTool(args.toArray(new String[0]), 0);
 
-            //TODO: Implement GlobalIndexChecker like repair for unverified 
rows
-            assertEquals(1, 
getRowCount(conn.unwrap(PhoenixConnection.class).getQueryServices()
+            assertEquals(2, 
getRowCount(conn.unwrap(PhoenixConnection.class).getQueryServices()
                     .getTable(Bytes.toBytes(dataTableFullName)), false));
-//            assertEquals(1, 
getRowCount(conn.unwrap(PhoenixConnection.class).getQueryServices()
-//                    
.getTable(Bytes.toBytes(record.getNewPhysicalTableName())), false));
+            assertEquals(0, getRowCountForEmptyColValue(conn, 
record.getNewPhysicalTableName(), UNVERIFIED_BYTES));
+            assertEquals(2, getRowCountForEmptyColValue(conn, 
record.getNewPhysicalTableName(), VERIFIED_BYTES));
+        } finally {
+            IndexRegionObserver.setFailPreIndexUpdatesForTesting(false);
+            IndexRegionObserver.setFailDataTableUpdatesForTesting(false);
+            IndexRegionObserver.setFailPostIndexUpdatesForTesting(false);
+        }
+    }
+
+    @Test
+    public void testTransformVerifiedForTransactionalTable() throws Exception {
+        // TODO: Column encoding is not supported for OMID. Have omid test for 
other type of transforms.
+        // For now, we don't support transforms other than storage and column 
encoding type change.
+        //testVerifiedForTransactionalTable("OMID");
+        testVerifiedForTransactionalTable("TEPHRA");
+    }
+
+    private void testVerifiedForTransactionalTable(String provider) throws 
Exception{
+        String tableOptions = tableDDLOptions + " 
,TRANSACTIONAL=true,TRANSACTION_PROVIDER='" + provider + "'";
+
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, 
dataTableName);
+
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(true);
+            int numOfRows = 1;
+            createTableAndUpsertRows(conn, dataTableFullName, numOfRows, 
tableOptions);
+            SingleCellIndexIT.assertMetadata(conn, 
PTable.ImmutableStorageScheme.ONE_CELL_PER_COLUMN, 
PTable.QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, dataTableFullName);
+
+            conn.createStatement().execute("ALTER TABLE " + dataTableFullName +
+                    " SET 
IMMUTABLE_STORAGE_SCHEME=SINGLE_CELL_ARRAY_WITH_OFFSETS, 
COLUMN_ENCODED_BYTES=2");
+            SystemTransformRecord record = 
Transform.getTransformRecord(schemaName, dataTableName, null, null, 
conn.unwrap(PhoenixConnection.class));
+            assertNotNull(record);
+            assertMetadata(conn, 
PTable.ImmutableStorageScheme.SINGLE_CELL_ARRAY_WITH_OFFSETS, 
PTable.QualifierEncodingScheme.TWO_BYTE_QUALIFIERS, 
record.getNewPhysicalTableName());
+
+            List<String> args = getArgList(schemaName, dataTableName, null,
+                    null, null, null, false, false, false, false, false);
+            runTransformTool(args.toArray(new String[0]), 0);
+            assertEquals(1, getRowCountForEmptyColValue(conn, 
record.getNewPhysicalTableName(), VERIFIED_BYTES));
+
+
+            String upsertQuery = String.format("UPSERT INTO %s VALUES(?, ?, 
?)", dataTableFullName);
+            PreparedStatement stmt1 = conn.prepareStatement(upsertQuery);
+
+            // Run again to check that VERIFIED row still remains verified
+            runTransformTool(args.toArray(new String[0]), 0);
+            assertEquals(1, getRowCountForEmptyColValue(conn, 
record.getNewPhysicalTableName(), VERIFIED_BYTES));

Review comment:
       @gjacoby126 for the UNSUPPORTED_STORAGE_FORMAT_FOR_TXN_PROVIDER 
question, it is thrown in createTableInternal function. But it is also thrown 
for ALTER. Here is the explanation: 1. The table cannot be created due to this 
check. 2. If you ALTER and change encoding, we use createTableInternal to 
create a new transforming table and it is thrown again during ALTER. 
   
   For the test, I added it because of a previous issue Istvan fixed to and 
asked to make sure we are not breaking it. I wouldn't worry too much about 
Tephra.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to