Reputation: 17676
In spark a
df.printSchema()
will print something like
root
|-- value: int (nullable = true)
|-- square: int (nullable = true)
|-- cube: int (nullable = true)
|-- key: int (nullable = true)
How can I achieve similar behaviour for the result of a SELECT table without materializing the select? I.e.
SELECT a.a, a.b , dd.d FROM a JOIN dd on a.id = dd.id
I would simply want to write something like
describe schema (SELECT a.a, a.b , dd.d FROM a JOIN dd on a.id = dd.id)
and receive output of at leat the column names, optionally nullability and data types.
Upvotes: 0
Views: 51
Reputation: 15258
you can use desc
but only on a table, which means you have to create the table result of your query first.
You can create the table without data, therefore, you only have the schema. Then you extract it. And you can drop the table. That's a workaround but not really pretty.
If you really don't want to materialize anything, it means you have to get the schema of each column where they are. you have a table all_tab_columns
which contains the schema. Just combine the content according to your query.
Upvotes: 2