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

tkhurana pushed a commit to branch 5.2
in repository https://gitbox.apache.org/repos/asf/phoenix.git


The following commit(s) were added to refs/heads/5.2 by this push:
     new c21b08cef1 PHOENIX-7468 NPE in SchemaExtractionTool on salted table 
(#2028)
c21b08cef1 is described below

commit c21b08cef1d0a120d4c456deebf897e27468d38f
Author: tkhurana <[email protected]>
AuthorDate: Sat Nov 23 16:56:52 2024 -0800

    PHOENIX-7468 NPE in SchemaExtractionTool on salted table (#2028)
    
    PHOENIX-7468 NPE in SchemaExtractionTool on salted table
---
 .../schema/tool/SchemaExtractionProcessor.java     |  3 +-
 .../schema/tool/SchemaToolExtractionIT.java        | 32 +++++++++++++++++++++-
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaExtractionProcessor.java
 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaExtractionProcessor.java
index 416387bb67..1c239ba041 100644
--- 
a/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaExtractionProcessor.java
+++ 
b/phoenix-core-client/src/main/java/org/apache/phoenix/schema/tool/SchemaExtractionProcessor.java
@@ -499,7 +499,8 @@ public class SchemaExtractionProcessor implements 
SchemaProcessor {
     private String getColumnInfoStringForTable(PTable table) {
         StringBuilder colInfo = new StringBuilder();
         List<PColumn> columns = table.getBucketNum() == null ? 
table.getColumns() : table.getColumns().subList(1, table.getColumns().size());
-        List<PColumn> pkColumns = table.getBucketNum() == null ? 
table.getPKColumns() : table.getColumns().subList(1, 
table.getPKColumns().size());
+        List<PColumn> pkColumns = table.getBucketNum() == null ? 
table.getPKColumns()
+                : table.getPKColumns().subList(1, table.getPKColumns().size());
 
         return getColumnInfoString(table, colInfo, columns, pkColumns);
     }
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolExtractionIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolExtractionIT.java
index 6844328376..d165ffe67f 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolExtractionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/schema/tool/SchemaToolExtractionIT.java
@@ -633,6 +633,33 @@ public class SchemaToolExtractionIT extends 
ParallelStatsEnabledIT {
         compareOrdinalPositions(indexName, newIndex);
     }
 
+    @Test
+    public void testSaltingWithOOOPKDefinitions() throws Exception {
+        String schemaName = generateUniqueName();
+        String tableName = generateUniqueName();
+        String fullTableName = SchemaUtil.getQualifiedTableName(schemaName, 
tableName);
+        // Order of definition of columns in create table is different from PK 
constraint
+        String ddl = "CREATE TABLE IF NOT EXISTS " + fullTableName +
+                "(ID1 CHAR(15) NOT NULL,\n" +
+                "ID2 INTEGER NOT NULL,\n" +
+                "TEXT VARCHAR,\n" +
+                "INT INTEGER,\n" +
+                "DOUBLE DECIMAL(12,3),\n" +
+                "CREATED_DATE DATE NOT NULL,\n" +
+                "TS TIMESTAMP\n" +
+                "CONSTRAINT PK PRIMARY KEY (ID1, ID2, CREATED_DATE))\n" +
+                "SALT_BUCKETS=16,MULTI_TENANT=true";
+
+        List<String> queries = new ArrayList();
+        queries.add(ddl);
+        String result = runSchemaExtractionTool(schemaName, tableName, null, 
queries);
+        String expected = "CREATE TABLE %s(ID1 CHAR(15) NOT NULL, ID2 INTEGER 
NOT NULL, TEXT VARCHAR, " +
+                "INT INTEGER, DOUBLE DECIMAL(12,3), CREATED_DATE DATE NOT 
NULL, TS TIMESTAMP " +
+                "CONSTRAINT PK PRIMARY KEY (ID1, ID2, CREATED_DATE)) " +
+                "IMMUTABLE_STORAGE_SCHEME='ONE_CELL_PER_COLUMN', 
SALT_BUCKETS=16, MULTI_TENANT=true";
+        Assert.assertEquals(String.format(expected, fullTableName), result);
+    }
+
     private Connection getTenantConnection(String url, String tenantId) throws 
SQLException {
         Properties props = new Properties();
         props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, tenantId);
@@ -671,7 +698,10 @@ public class SchemaToolExtractionIT extends 
ParallelStatsEnabledIT {
         if(conn!=null) {
             
set.setConf(conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration());
         }
-        set.run(args);
+        int ret = set.run(args);
+        if (ret != 0) {
+            throw new RuntimeException(String.format("Schema tool failed with 
error %d", ret));
+        }
         return set.getOutput();
     }
 

Reply via email to