I am working on Query Service in Adobe Experience Platform. It uses limited Spark SQL functions which are listed here.
I have the following table
Name AddressType CustomerDetails
------------------------------------------------------------------------------------------
John home [{"acctType":"Mortgage loan","acctID":101},{"acctType":"Home Equity loan","acctID":104},{"acctType":"Checking Account","acctID":105,}]
John work [{"acctType":"Mortgage loan","acctID":101},{"acctType":"Home Equity loan","acctID":104},{"acctType":"Checking Account","acctID":105,}]
John office [{"acctType":"Mortgage loan","acctID":101},{"acctType":"Home Equity loan","acctID":104},{"acctType":"Checking Account","acctID":105,}]
Here Name and AddressType are String where as CustomerDetails has the schema type array<struct<acctType:string, acctID:string>>
I need to add AddressType column to the CustomerDetails column and the final output should look like the below format
Name AddressType CustomerDetails
--------------------------------------
John home [{"AddressType":"home","acctType":"Mortgage loan","acctID":101}, {"AddressType":"home","acctType":"Home Equity loan","acctID":104}, {"AddressType":"home","acctType":"Checking Account","acctID":105}]
John work [{"AddressType":"work","acctType":"Mortgage loan","acctID":101}, {"AddressType":"work","acctType":"Home Equity loan","acctID":104}, {"AddressType":"work","acctType":"Checking Account","acctID":105}]
John office [{"AddressType":"office","acctType":"Mortgage loan","acctID":101}, {"AddressType":"office","acctType":"Home Equity loan","acctID":104}, {"AddressType":"office","acctType":"Checking Account","acctID":105}]
I am using the below query to add an extra field to the CustomerDetails column. But I am not able to figure out how to add the value of AddressType column to col3
SELECT Name, addressType,
(from_json(CustomerDetails, 'ARRAY<STRUCT<addressType: STRING, acctType: STRING, acctID: STRING>>')) AS col3
FROM CustomerTable
I have also looked at TRANSFORM function but not getting the SQL specific syntax to use it. Any help on this would be appreciated.