sparkSession.sql("select struct(col1,col2) as myStruct from table1")
return the dataframe with following schema
root
|-- myStruct : struct (nullable = false)
| |-- col1: string (nullable = true)
| |-- col2: string (nullable = true)
But I need col1 as myCol1 and col2 as myCol2?
When I use as keyword inside struct function, it fails
sparkSession.sql("select struct(col1 as myCol1,col2 as myCol2) as myStruct from table1")
gives the below error message
mismatched input 'as' expecting {')', ','}(line 1, pos 19)
How to get column alias in struct field?