· 9 years ago · Jan 03, 2017, 08:22 AM
1# Dictionary to map Spark data types to Hive
2d = {'StringType':'STRING', 'DoubleType':'DOUBLE', 'IntegerType': 'INT', 'DateType':'DATE', 'LongType': 'BIGINT'}
3
4# Convert to Hive schema
5schemastring = ', '.join([field.name + ' ' + d[str(field.dataType)] for field in df.schema.fields])
6hivetablename='mortgage_all'
7output_path='path'
8filename='filename'
9# Create Hive table
10ddl = """CREATE EXTERNAL TABLE IF NOT EXISTS %s(%s) STORED AS ORC LOCATION '%s'""" % (hivetablename, schemastring, output_path + filename)