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

michaelsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new f2904b162 IMPALA-12918: Validate numeric values for table stats 
properties
f2904b162 is described below

commit f2904b1627e3e735eca3ccccd2658780360ea4c5
Author: Kunal Siyag <[email protected]>
AuthorDate: Wed Jan 21 16:15:48 2026 +0530

    IMPALA-12918: Validate numeric values for table stats properties
    
    Added validation to ensure that table stats properties (numRows, totalSize,
    rawDataSize) contain valid numeric values in ALTER TABLE SET TBLPROPERTIES
    statements. Empty strings and non-numeric values will now cause an
    AnalysisException to be thrown.
    
    Testing:
    - Added tests in AnalyzeDDLTest.java to verify validation logic
    
    Change-Id: I5e8f2a9784edc86838a375d373e2095dd674d63d
    Reviewed-on: http://gerrit.cloudera.org:8080/23857
    Reviewed-by: Noemi Pap-Takacs <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 .../analysis/AlterTableSetTblProperties.java       | 34 ++++++++++++++++++++++
 .../org/apache/impala/analysis/AnalyzeDDLTest.java | 17 +++++++++++
 2 files changed, 51 insertions(+)

diff --git 
a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java 
b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
index 1706ae5ae..e8bf8dfe6 100644
--- 
a/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
+++ 
b/fe/src/main/java/org/apache/impala/analysis/AlterTableSetTblProperties.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.avro.SchemaParseException;
+import org.apache.hadoop.hive.common.StatsSetupConst;
 import org.apache.hadoop.hive.metastore.api.hive_metastoreConstants;
 import org.apache.hadoop.hive.serde.serdeConstants;
 import org.apache.hadoop.hive.serde2.avro.AvroSerdeUtils;
@@ -145,6 +146,9 @@ public class AlterTableSetTblProperties extends 
AlterTableSetStmt {
 
     // Analyze 'serialization.encoding' property
     analyzeSerializationEncoding(tblProperties_);
+
+    // Analyze numeric table stats properties
+    analyzeTableStatsProperties(tblProperties_);
   }
 
   private void analyzeKuduTable(Analyzer analyzer) throws AnalysisException {
@@ -437,4 +441,34 @@ public class AlterTableSetTblProperties extends 
AlterTableSetStmt {
     return new Pair<>(TableDef.analyzeSortColumns(sortCols, table, 
sortingOrder),
         sortingOrder);
   }
+
+  /**
+   * Validates that table stats properties (numRows, totalSize, rawDataSize) 
contain
+   * valid numeric values. These properties must be parseable as long values.
+   */
+  public static void analyzeTableStatsProperties(Map<String, String> 
tblProperties)
+      throws AnalysisException {
+    String[] statsProperties = {
+      StatsSetupConst.ROW_COUNT,
+      StatsSetupConst.TOTAL_SIZE,
+      StatsSetupConst.RAW_DATA_SIZE
+    };
+    for (String prop : statsProperties) {
+      if (tblProperties.containsKey(prop)) {
+        String value = tblProperties.get(prop);
+        if (value == null || value.trim().isEmpty()) {
+          throw new AnalysisException(String.format(
+              "Table property '%s' must have a valid numeric value, got empty 
value.",
+              prop));
+        }
+        try {
+          Long.parseLong(value.trim());
+        } catch (NumberFormatException e) {
+          throw new AnalysisException(String.format(
+              "Table property '%s' must have a valid numeric value, got '%s'.",
+              prop, value));
+        }
+      }
+    }
+  }
 }
diff --git a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java 
b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
index d832d48fb..412e930a6 100644
--- a/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
+++ b/fe/src/test/java/org/apache/impala/analysis/AnalyzeDDLTest.java
@@ -1188,6 +1188,23 @@ public class AnalyzeDDLTest extends FrontendTestBase {
     AnalysisError("create table " + tmpTableName + " (id int) with 
serdeproperties(" +
         "'serialization.encoding'='NonexistentEncoding')",
         "Unsupported encoding: NonexistentEncoding.");
+
+    // Numeric table stats properties validation
+    AnalysisError("alter table functional.alltypes set 
tblproperties('numRows'='')",
+        "Table property 'numRows' must have a valid numeric value, got empty 
value.");
+    AnalysisError("alter table functional.alltypes set 
tblproperties('totalSize'='')",
+        "Table property 'totalSize' must have a valid numeric value, got empty 
value.");
+    AnalysisError("alter table functional.alltypes set 
tblproperties('rawDataSize'='')",
+        "Table property 'rawDataSize' must have a valid numeric value, got 
empty value.");
+    AnalysisError("alter table functional.alltypes set 
tblproperties('numRows'='abc')",
+        "Table property 'numRows' must have a valid numeric value, got 
'abc'.");
+    AnalysisError("alter table functional.alltypes set 
tblproperties('totalSize'='xyz')",
+        "Table property 'totalSize' must have a valid numeric value, got 
'xyz'.");
+    AnalyzesOk("alter table functional.alltypes set 
tblproperties('numRows'='100')");
+    AnalyzesOk("alter table functional.alltypes set 
tblproperties('numRows'='0')");
+    AnalyzesOk("alter table functional.alltypes set 
tblproperties('numRows'='-1')");
+    AnalyzesOk("alter table functional.alltypes set 
tblproperties('totalSize'='1000')");
+    AnalyzesOk("alter table functional.alltypes set 
tblproperties('rawDataSize'='500')");
   }
 
   @Test

Reply via email to