How can we explode multiple array column in Spark? I have a dataframe with 5 stringified array columns and I want to explode on all 5 columns. Showing example with 3 columns for the sake of simplicity.
If I have the following input row:
col1 col2 col3 ["b_val1","b_val2"] ["at_val1","at_val2","at_val3"] ["male","female"] I want to explode on all 3 array columns, so the output should look like:
b_val1 at_val1 male b_val1 at_val1 female b_val2 at_val1 male b_val2 at_val1 female b_val1 at_val2 male b_val1 at_val2 female b_val2 at_val2 male b_val2 at_val2 female b_val1 at_val3 male b_val1 at_val3 female b_val2 at_val3 male b_val2 at_val3 female I tried the following:
SELECT timestamp, explode(from_json(brandList, 'array<string>')) AS brand, explode(from_json(articleTypeList, 'array<string>')) AS articleTypeList, explode(from_json(gender, 'array<string>')) AS gender, explode(from_json(masterCategoryList, 'array<string>')) AS masterCategoryList, explode(from_json(subCategoryList, 'array<string>')) AS subCategoryList, isLandingPage, ... from table but this is not allowed nd I get the following error - Exception in thread "main" org.apache.spark.sql.AnalysisException: Only one generator allowed per select clause but found 5: explode(jsontostructs(brandList)), explode(jsontostructs(articleTypeList)), explode(jsontostructs(gender)), explode(jsontostructs(masterCategoryList)), explode(jsontostructs(subCategoryList));