Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

How to connect Hive database using baseline from python?

Please help me whether any alternate way to connect Hive database.

I have hive database in HDFS platform, on daily bases I connect the database using below method.

Open putty >> Connect Jump host server >> connect SSH with my user id/pwd >> impersonate our service account with my login password >> pass KERBROS auth file through KNIT >> connect hiv DB with baseline >> finally entered to my project database/tables

Is there any way to connect same method in Python? I used Jumpssh and connected till using my user id/pwd.

question from:https://stackoverflow.com/questions/65919004/how-to-connect-hive-database-using-baseline-from-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes you can using python. I am showing one way using pyodbc. So, step 1 - you need to create a odbc DSN in your windows or linux. step 2 - you can use pyodbc to connect to hdfs.

import pyodbc 
# Configuration settings for the ODBC connection
cfg = {'DSN': 'hivedb', 'host': 'abc.com','port': 0050,'username': 'foo', 'password': 'bar'}
# Create connection
conn_string='DSN=%s;  database=default;AuthMech=3;UseSASL=1; UID=%s; PWD=%s; SSL=1;AllowSelfSignedServerCert=1;CAIssuedCertNamesMismatch=1' %(cfg['DSN'], cfg['username'], cfg['password'])
cursor = conn1.cursor()
cursor.execute("Truncate Table default.temp")

You can use pandas to store the selected data.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...