Hi,
I'd like to put this out here in case there are some helpful suggestions to be found.
What am I trying to achieve?
Generate a hash of certain columns in a dataframe (as in a row hash, but not the whole row) where currently one of the columns is an array of struct. Without explicitly referencing the column(s) by name.
Where have I got to?
I have achieved what I want to do... sort of. By specifying the columns and using the sha2() and to_json() functions to convert the array of structs in to a string, enabling me to use sha2.
What's the problem?
I don't want to specify the column (or columns) by name. The data is coming from an API, it's JSON format, and I want to safeguard against changes in schema. If the API payload changes without warning, my aim is for our process to adjust without intervention. So, if the current array of nested objects column changes name, I don't want it to break.
What have I tried?
I've tried playing around with dataframe.schema and dataframe.dtypes. I can't get a simple conditional true/false return if the column is an array. The datatypes seem to be ArrayType, yes, but following from that, listing the schema, so all the nested columns etc. So I haven't got something like if dataType is array: true else false working.
Source format example:
{
"name":"value",
"Array"
[
{
"Id":1234
"Name":"some name"
...
},
{
...
}
]
}
Anyone have any ideas?