-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy path275impylaQuery
77 lines (60 loc) · 1.88 KB
/
275impylaQuery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
#!pip3 install pyspark
#
# for a new environment you'll need to
# add the userid to the groups that have permission to access ML
# update the id_broker mappings so you have write access to the S3 buckets
# XX do not do this - error when creating two roles for one user: update id_broker to allow ranger access
# sync to freeipa to fix HTTP ERROR 403 forbidden
# update Ranger policy so you can write to the default Hive database, commonly policy #14
# update Ranger policy so you can use URL commonly policy #13
#
from __future__ import print_function
import sys
from random import random
from operator import add
#from pyspark.sql import SparkSession
!pip3 install python-decouple
!pip3 install impyla
from decouple import config
userID = config('userID',default='')
password = config('password',default='')
#print (password)
# impyla
#!pip3 install impyla
#jdbc:impala://ipaddressfromthegetjdbclinktothecdw:443/default;yadayada
from impala.dbapi import connect
conn = connect( \
'ipaddressFromJDBCurlGoesHere', 443, \
auth_mechanism='LDAP',\
user=userID,\
password=password,\
use_ssl=True,\
use_http_transport=True,\
http_path='cliservice/cdp-proxy-api/impala' )
cursor = conn.cursor()
#cursor.close()
#conn.close()
def mylookup(args):
#accountcode = int(args.get('accountcode'))
accountcode = args.get('accountcode')
print (accountcode)
qstring="select salary, 'query from CML' from sample_07 where code='" +accountcode+"'"
print (qstring)
cursor.execute(qstring)
res = cursor.fetchall()
print(res)
#result = spark.sql(qstring).take(1)
return res[0][0]
# generate a bunch of queries
while True:
mylookup ( {"accountcode":"11-3021"} )
# hide password
#!pip3 install python-decouple
# create file called .env with
# [settings]
# userID=foo
# password=bar
#from decouple import config
#userID = config('userID',default='none')
#password = config('password',default='none')