Member since
02-12-2025
11
Posts
0
Kudos Received
0
Solutions
04-04-2025
09:43 AM
I need to extract a parent JSON column present in Hadoop: This is an example of my JSOn.Here I need to extract only values products class but not of offer. I cant use index of product as the the number of occurrences might change in future. Have used the following regex regexp_replace(regexp_replace(get_json_object(xml_data, '$.customer.products'),'\\}\\,\\{','\\}\\\n\\{'),'\\[|\\]','') AS prd_JSON But is is only giving all values in a row , not in multiple rows. Have also tried something like below, but it doesnt give correct result: regexp_replace(regexp_replace(get_json_object(xml_data, '$.customer.products'),'\\}\\,\\{','\\}\\\n\\{'),'\\[|\\]','') AS prd_JSON from prd_table ) select get_json_object(prd_item,'$.productCode') as productCode, get_json_object(prd_item,'$.type') as Ttype from prd LATERAL VIEW OUTER EXPLODE(split(prd_JSON, ';')) p AS prd_item) a { "Customer": { "CustomerId": "19900101", "appl": [ { ***Some values } ] "products": [ { "ProductCOde": ABC, "Type": C1, "Offer": 16575.0, "Offer": [ { "ProductCOde": A1, "Offer": 2000.0 "Type": CBA, } { "ProductCOde": A2, "Offer": 2000.0 "Type": DBA, } { "ProductCOde": A3, "Offer": 3000.0 "Type": BBA, } ] } { "ProductCOde": XYZ, "Type": C2, "Offer": 2001, "Offer": [ { "ProductCOde": B1, "Offer": 2000.0 "Type": BBA, } { "ProductCOde": B2, "Offer": 2000.0 "Type": BBA, } ] } ] } } Can anyone point out what I am doing wrong here
... View more
Labels:
- Labels:
-
Apache Hive
-
Apache Knox
-
Cloudera Hue
04-04-2025
08:29 AM
Thanks for the help and sorry for late reply @Shelton I am getting the output here but the values for parent class are not getting populated, they are displayed as NULL
... View more
02-19-2025
07:41 AM
I have a table with one column as JSON file. I am using lateral explode to parse values.The code is working fine for classes except for one where subclasses have similar variable name : Json: { "Customer": { "CustomerId": "19900101", "appl": [ { ***Some values } ] "products": [ { "ProductCOde": ABC, "Type": C1, "Offer": 16575.0, "Offer": [ { "ProductCOde": A1, "Offer": 2000.0 "Type": CBA, } { "ProductCOde": A2, "Offer": 2000.0 "Type": DBA, } { "ProductCOde": A3, "Offer": 3000.0 "Type": BBA, } ] } { "ProductCOde": XYZ, "Type": C2, "Offer": 2001, "Offer": [ { "ProductCOde": B1, "Offer": 2000.0 "Type": BBA, } { "ProductCOde": B2, "Offer": 2000.0 "Type": BBA, } ] } ] } } Code: with product as ( select xml_data, get_json_object(xml_data,'$.customer.customerid')as applicationid, regexp_replace(regexp_replace(get_json_object(xml_data, '$.customer.products'), '\\[|\\]', ''), '\\}\\,\\{', '\\}\\;\\{') AS product_JSOn from Custome_info ) select applicationid, get_json_object(prod_item,'$.ProductCOde') as ProductCOde, get_json_object(prod_item,'$.type') as ttype from product LATERAL VIEW OUTER EXPLODE(split(product_JSOn, ';')) p AS prod_item; Output ApplicationID ProductCode ttype 19900101 ABC NULL 19900101 A1 NULL 19900101 A2 NULL 19900101 B1 NULL I am not able to figure why values of subclasses are populating here
... View more
Labels:
- Labels:
-
Apache Hive
02-19-2025
03:36 AM
I am getting the following error in sas FAILED: ParseException line 1:760 cannot recognize input near ';' '<EOF>' '<EOF>' in lateral view
... View more
02-18-2025
05:19 AM
I have few tables in hive which I need to access in my SAS platform. I have created a Pass through query present below (marked some paths in *) but it is throwing error. PROC SQL; CONNECT TO HADOOP( host = "bigdataplatform-gcg-&amb..lac.nsroot.net" schema = &ESQUEMA. HDFS_TEMPDIR = "/data/&HDFS./work/hive/&HDFS._ofc/" DBMAX_TEXT = ***** uri = "jdbc:hive2://bigdataplatform-gcg-&amb..lac.nsroot.net:10000/&ESQUEMA.;principal=hive/*****T;ssl=true" scratch_db = "&HDFS._ofc" subchar=questionmark ); CREATE TABLE Applicant AS SELECT * FROM CONNECTION TO HADOOP ( WITH json_extract AS ( SELECT get_json_object(xml_data, '$.app.Id') AS ID, get_json_object(xml_data, '$.app.apply[0].flag') AS Flag, get_json_object(xml_data, '$.app.apply[0].Product') AS products FROM check ) SELECT ID, Flag, get_json_object(product_data, '$.Code') AS Code, get_json_object(product_data, '$.Line') AS Line, get_json_object(product_data, '$.status') AS Status FROM json_extract LATERAL VIEW OUTER EXPLODE(SPLIT(products, '},')) p AS product_data; ); disconnect from hadoop; quit;
... View more
Labels:
- Labels:
-
Apache Hive
-
HDFS
02-17-2025
07:55 AM
Thanks a lot.. It worked like magic 😄
... View more
02-14-2025
06:53 AM
Thanks @smruti . I am getting 3 rows now but the first two values as populated as NULL only the last values is correctly populated.
... View more
02-13-2025
05:18 AM
Here Phonetype and Phone availabilityflag are my array which I want in rows
... View more
02-13-2025
04:11 AM
Thanks for the solution. Right the code is creating separate columns . But I am getting around 143 rows whereas technically there should be 3 rows and value is coming as NULL. here consider first column as id
... View more
02-13-2025
01:48 AM
Hi I am attaching the result for a similar example: column xml_data contains json
... View more