Skip to content

Instantly share code, notes, and snippets.

@drorata
Created November 11, 2020 16:00
Show Gist options
  • Save drorata/0e311961a81057863d5e4a122f2058d9 to your computer and use it in GitHub Desktop.
Save drorata/0e311961a81057863d5e4a122f2058d9 to your computer and use it in GitHub Desktop.
Basic querying example
HIVE_HOST=my.location.com
HIVE_USERNAME=user.name
HIVE_PASSWORD=my_passWord
name: my_env
channels:
- conda-forge
dependencies:
- pip
- ipykernel
- "pandas<1.1"
- python-dotenv
- pip:
- thrift-sasl~=0.4.2
- impyla~=0.16
import os
from impala.dbapi import connect
from dotenv import load_dotenv
import pandas as pd
load_dotenv(override=True)
conn = connect(
host=os.getenv("HIVE_HOST"),
port=21050,
auth_mechanism='PLAIN',
use_ssl=True,
user=os.getenv("HIVE_USERNAME"),
password=os.getenv("HIVE_PASSWORD"),
)
cursor = conn.cursor()
with open("my_query.sql", "r") as f:
query = " ".join(f.readlines())
df = pd.read_sql(
query,
conn
)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment