Hi Team,
I need to validate XML file values with hive table values.
The XML values inject into HDFS using Nifi job & created a table in Hive.
We need to validate the values. can any one help me how to do validation?
Thanks
Raghav
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amira BedhiafiRank #601 · 4K reputationPosted Mar 18, 2025, 6:08 PM EDT
To process XML in NiFi
If the XML is already in HDFS, use CREATE EXTERNAL TABLE with
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'or convert it into ORC/Parquet.CREATE EXTERNAL TABLE xml_data_table ( id STRING, name STRING, value STRING ) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION '/path/to/hdfs/xml_data';Use
EXCEPTorJOINto compare XML-loaded data with reference Hive table:SELECT * FROM xml_data_table EXCEPT SELECT * FROM reference_hive_table;or
SELECT x.id, x.value, r.value FROM xml_data_table x LEFT JOIN reference_hive_table r ON x.id = r.id WHERE x.value != r.value OR r.id IS NULL;You can use ExecuteSQL in NiFi to query both tables and check for mismatches and compare datasets using RouteOnAttribute or QueryRecord.
If the dataset is large, you can use PySpark for efficient validation:
from pyspark.sql import SparkSession spark = SparkSession.builder.appName("Validation").enableHiveSupport().getOrCreate() xml_df = spark.sql("SELECT * FROM xml_data_table") hive_df = spark.sql("SELECT * FROM reference_hive_table") mismatch_df = xml_df.join(hive_df, "id", "left_anti") mismatch_df.show()