Last active
November 28, 2018 16:41
-
-
Save hakanilter/a5781b4fb00469dcfe62f270d412b781 to your computer and use it in GitHub Desktop.
Fastest way to get Hive definition for a given Json file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def json_hive_def(path): | |
spark.read.json(path).createOrReplaceTempView("temp_view") | |
spark.sql("CREATE TABLE temp_table AS SELECT * FROM temp_view LIMIT 0") | |
script = spark.sql("SHOW CREATE TABLE temp_table").take(1)[0].createtab_stmt.replace('\n', '') | |
spark.sql("DROP TABLE temp_table") | |
return script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment