Skip to content

Instantly share code, notes, and snippets.

@ragingbal
Last active June 18, 2020 23:26
Show Gist options
  • Save ragingbal/a6e4017187fe09336acb4d2c057076a9 to your computer and use it in GitHub Desktop.
Save ragingbal/a6e4017187fe09336acb4d2c057076a9 to your computer and use it in GitHub Desktop.
from pyhive import hive
def getHiveConn(host, username, port=10000, schema="db_user1"):
return hive.connect(host=host, port=port, username=username, database=schema, auth=None)
def getHiveData(table, conn = None):
if (conn is None):
conn = getHiveConn("localhost", "user1")
dfRaw = pd.read_sql(f"SELECT * FROM {table}", conn)
return dfRaw
def saveHiveData(conn = None):
if (conn is None):
conn = getHiveConn("localhost", "user1")
query = ("select * from some_table")
cur = conn.cursor()
cur.execute(query)
conn.commit()
conn = getHiveConn(
host =os.getenv("HIVE_SERVER_2_HOSTNAME", "localhost"),
username =os.getenv("HIVE_SERVER_2_USERNAME", "user1"),
schema =os.getenv("HIVE_SERVER_2_SCHEMA", "db_user1")
)
saveHiveData(data, "sample_data", conn)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment