gjacoby126 commented on a change in pull request #702: PHOENIX-5707: Index 
rebuild after truncate incorrectly writes the inc…
URL: https://github.com/apache/phoenix/pull/702#discussion_r373929394
 
 

 ##########
 File path: phoenix-core/src/it/java/org/apache/phoenix/end2end/IndexToolIT.java
 ##########
 @@ -237,6 +237,80 @@ public void testWithSetNull() throws Exception {
         }
     }
 
+    @Test
+    public void testIncorrectRebuild() throws Exception {
+        // This test is for building non-transactional mutable global indexes 
with direct api
+        if (localIndex || transactional || !mutable || !directApi || 
useSnapshot) {
+            return;
+        }
+        String schemaName = generateUniqueName();
+        String dataTableName = generateUniqueName();
+        String dataTableFullName = SchemaUtil.getTableName(schemaName, 
dataTableName);
+        String indexTableName = generateUniqueName();
+        String indexTableFullName = SchemaUtil.getTableName(schemaName, 
indexTableName);
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+            conn.setAutoCommit(true);
+            conn.createStatement().execute("create table " + dataTableFullName 
+
+                    " (id varchar(10) not null primary key, val1 varchar(10), 
val2 varchar(10), val3 varchar(10)) COLUMN_ENCODED_BYTES=0");
+            conn.createStatement().execute("CREATE INDEX " + indexTableName + 
" on " +
+                    dataTableFullName + " (val1) include (val2, val3)" );
+            //insert a full row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " values ('a', 'ab', 'efgh', 'abcd')");
+            Thread.sleep(1000);
+
+            // insert a partial row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " (id, val3) values ('a', 'uvwx')");
+            Thread.sleep(1000);
+            //insert a full row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " values ('a', 'ab', 'efgh', 'yuio')");
+            Thread.sleep(1000);
+            //insert a partial row
+            conn.createStatement().execute("upsert into " + dataTableFullName 
+ " (id, val3) values ('a', 'asdf')");
+
+            //truncate index table
+            ConnectionQueryServices queryServices = 
conn.unwrap(PhoenixConnection.class).getQueryServices();
+            Admin admin = queryServices.getAdmin();
+            TableName tableName = TableName.valueOf(indexTableFullName);
+            admin.disableTable(tableName);
+            admin.truncateTable(tableName, false);
+
+            //rebuild index
+            runIndexTool(true, false, schemaName, dataTableName, 
indexTableName);
+
+            //assert
+            Scan scan = new Scan();
+            scan.setRaw(true);
+            scan.setMaxVersions(10);
+            HTable indexTable = new HTable(getUtility().getConfiguration(), 
indexTableFullName);
+            HTable dataTable = new HTable(getUtility().getConfiguration(), 
dataTableFullName);
+
+            long dataFullRowTS = 0;
+            ResultScanner rs = dataTable.getScanner(scan);
+            for (Result r : rs) {
+                for (Cell c : r.listCells()) {
+                    String column = new String(CellUtil.cloneQualifier(c));
+                    String value = new String(CellUtil.cloneValue(c));
+                    if (column.equalsIgnoreCase("VAL3") && 
value.equalsIgnoreCase("yuio")) {
+                        dataFullRowTS = c.getTimestamp();
+                    }
+                }
+            }
+
+            rs = indexTable.getScanner(scan);
+            for (Result r : rs) {
+                for (Cell c : r.listCells()) {
+                    long indexTS = c.getTimestamp();
+                    String column = new String(CellUtil.cloneQualifier(c));
+                    if (column.equalsIgnoreCase("0:VAL3") && indexTS == 
dataFullRowTS) {
+                        String value = new String(CellUtil.cloneValue(c));
+                        assertEquals("yuio", value); // if the ts is from full 
rebuild row , value should also be from full rebuild row
+                    }
+                }
 
 Review comment:
   Good to have an assertion going through Phoenix APIs that all is well too. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to