FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
e6data-python-connector/tests_grpc.py at dataframeForML · e6data/e6data-python-connector · GitHub
e6data
/
e6data-python-connector
Public
Notifications
You must be signed in to change notification settings
Fork
4
Star
32
Code
Issues
0
Pull requests
8
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
e6data-python-connector
/
tests_grpc.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
151 lines (135 loc) · 5.79 KB
Breadcrumbs
e6data-python-connector
/
tests_grpc.py
Copy path
File metadata and controls
151 lines (135 loc) · 5.79 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import
csv
import
os
import
time
from
unittest
import
TestCase
from
e6data_python_connector
import
Connection
import
logging
logging
.
getLogger
(
__name__
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
class
TestE6X
(
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
_host
=
"127.0.0.1"
self
.
_database
=
"tpcds_1000"
self
.
catalog_name
=
'perfhive'
logging
.
debug
(
'Trying to connect to engine host {}, database {}.'
.
format
(
self
.
_host
,
self
.
_database
))
self
.
e6x_connection
=
Connection
(
host
=
self
.
_host
,
port
=
4000
,
username
=
'shubham@e6x.io'
,
database
=
self
.
_database
,
password
=
'w3aSShTYPGt12Z8QuCXcxuAggKB4INyEzDwg1WFj0THDgJRMuwryt5dt'
,
)
logging
.
debug
(
'Successfully to connect to engine.'
)
def
test_connection
(
self
):
self
.
assertIsNotNone
(
self
.
e6x_connection
,
'Unable to connect.'
)
def
disconnect
(
self
):
self
.
e6x_connection
.
close
()
self
.
assertFalse
(
self
.
e6x_connection
.
check_connection
())
def
test_query_1
(
self
):
sql
=
'select 1'
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
self
.
assertIsNotNone
(
query_id
)
records
=
cursor
.
fetchall
()
self
.
assertIn
(
1
,
records
[
0
])
cursor
.
clear
()
self
.
e6x_connection
.
close
()
def
test_query_2
(
self
):
sql
=
"select timestamp_add('year',2,current_date())"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
self
.
assertIsNotNone
(
query_id
)
records
=
cursor
.
fetchall
()
cursor
.
clear
()
self
.
assertEqual
(
1
,
len
(
records
))
self
.
e6x_connection
.
close
()
def
test_query_3_fetch_one
(
self
):
sql
=
"select * from date_dim limit 3"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
self
.
assertIsNotNone
(
query_id
)
records
=
cursor
.
fetchone
()
cursor
.
clear
()
self
.
assertEqual
(
1
,
len
(
records
))
self
.
e6x_connection
.
close
()
def
test_query_4_fetch_many
(
self
):
sql
=
"select * from date_dim limit 3"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
self
.
assertIsNotNone
(
query_id
)
records
=
cursor
.
fetchmany
(
1
)
cursor
.
clear
()
self
.
assertEqual
(
1
,
len
(
records
))
self
.
e6x_connection
.
close
()
def
test_query_5_dry_run
(
self
):
sql
=
"select * from date_dim limit 3"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
response
=
self
.
e6x_connection
.
dry_run
(
sql
)
self
.
assertIsNotNone
(
response
)
self
.
e6x_connection
.
close
()
def
test_query_5_caches
(
self
):
sql
=
"select * from date_dim limit 3"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
# self.e6x_connection.set_or_update_caches(True)
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
self
.
assertIsNotNone
(
query_id
)
records
=
cursor
.
fetchall
()
# self.e6x_connection.set_or_update_caches(False)
now
=
time
.
time
()
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
records
=
cursor
.
fetchall
()
print
(
'After cache, execution time'
,
time
.
time
()
-
now
)
cursor
.
clear
()
self
.
e6x_connection
.
close
()
def
test_query_6_explain_analyse
(
self
):
sql
=
"select * from date_dim limit 3"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
cursor
.
explain_analyse
()
self
.
e6x_connection
.
close
()
def
test_query_7_explain
(
self
):
sql
=
"select * from date_dim limit 3"
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
(
catalog_name
=
self
.
catalog_name
)
query_id
=
cursor
.
execute
(
sql
)
cursor
.
explain
()
self
.
e6x_connection
.
close
()
def
tearDown
(
self
)
->
None
:
self
.
disconnect
()
def
test_get_query_list_from_csv_file
(
self
):
query_path
=
os
.
getenv
(
"QUERY_PATH"
)
or
'./query_file.csv'
query_column_name
=
os
.
getenv
(
"QUERY_CSV_COLUMN_NAME"
)
or
'QUERY'
logging
.
debug
(
'Query path found: {}'
.
format
(
query_path
))
if
query_path
:
if
not
query_path
.
endswith
(
'.csv'
):
raise
Exception
(
'Invalid QUERY_PATH: Only CSV file is supported.'
)
local_file_path
=
query_path
data
=
list
()
with
open
(
local_file_path
,
'r'
)
as
fh
:
reader
=
csv
.
DictReader
(
fh
)
for
row
in
reader
:
data
.
append
({
'query'
:
row
.
get
(
query_column_name
),
'query_id'
:
row
.
get
(
'QUERY_ID'
)
or
None
,
})
for
row
in
data
:
sql
=
row
.
get
(
"query"
)
logging
.
debug
(
'Executing query: {}'
.
format
(
sql
))
cursor
=
self
.
e6x_connection
.
cursor
()
query_id
=
cursor
.
execute
(
sql
)
logging
.
debug
(
'Query Id {}'
.
format
(
query_id
))
self
.
assertIsNotNone
(
query_id
)
records
=
cursor
.
fetchall
()
self
.
assertGreater
(
len
(
records
[
0
]),
0
)
Back
|
FazBrowse Home
|
New Git URL