text
stringlengths 1
93.6k
|
|---|
def get_job_state(self, job_id):
|
return
|
@abc.abstractmethod
|
def list_tables(self, database_name, table_prefix):
|
return
|
@abc.abstractmethod
|
def load_table(self, table_name, file_path):
|
return
|
@abc.abstractmethod
|
def query(self, query):
|
return
|
class Hive(DataWarehouse):
|
host = None
|
port = None
|
hive_serdes_path = None
|
def __init__(self, host, port, hive_serdes_path):
|
print '-- Initializing Hive Util --'
|
self.host = host
|
self.port = port
|
self.hive_serdes_path = hive_serdes_path
|
def execute_sql (self, database_name, sql, fetch_result = False):
|
import pyhs2
|
conn = pyhs2.connect(host=self.host, port=self.port, authMechanism="NOSASL", database='default')
|
# turn on tez and add serde jar
|
c = conn.cursor()
|
c.execute("set hive.execution.engine=tez")
|
c.execute("set hive.cache.expr.evaluation=false")
|
c.execute("add jar %s" % self.hive_serdes_path)
|
if database_name != None:
|
c.execute("use %s" % database_name)
|
# run actual command command
|
print "Executing HiveQL: %s" % (sql)
|
c.execute(sql)
|
output = []
|
if fetch_result:
|
rows = c.fetchall()
|
for row in rows:
|
output.append(row)
|
c.close()
|
conn.close()
|
return output
|
def create_dataset(self, database_name):
|
pass
|
def delete_dataset(self, database_name):
|
pass
|
def create_table(self, database_name, table_name, schema_fields, process_array = "child_table"):
|
# used to keep track of table_name -> column list
|
table_columns = {}
|
for field in schema_fields:
|
data_type = None
|
if field['data_type'] == 'string':
|
data_type = 'string'
|
elif field['data_type'] in ('timestamp', 'boolean'):
|
data_type = field['type']
|
elif field['data_type'] == 'float':
|
data_type = 'double'
|
elif field['data_type'] == 'integer':
|
data_type = 'int'
|
elif field['data_type'] in ('record'):
|
# ignore record
|
pass
|
else:
|
raise Exception("Unsupported data type %s for column %s" % (field['data_type'], field['key']))
|
if data_type is not None:
|
if field['mode'] == 'repeated':
|
if process_array == "child_table":
|
child_table_name = table_name + "_" + re.sub("[^0-9a-zA-Z_]", '_', field['key']).lower()
|
column_name = "value"
|
else:
|
continue
|
else:
|
if "." in field['key']:
|
if process_array == "child_table":
|
child_table_name = table_name + "_" + re.sub("[^0-9a-zA-Z_]", '_', field['key'].rsplit(".",1)[0]).lower()
|
column_name = field['key'].rsplit(".",1)[1]
|
print " Child Table column:" + column_name
|
else:
|
child_table_name = table_name
|
column_name = field['key'].split(".",1)[0]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.