-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
42 lines (35 loc) · 1.01 KB
/
test.py
File metadata and controls
42 lines (35 loc) · 1.01 KB
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
import pandas as pd
import numpy as np
import cassandra
from cassandra.cluster import Cluster
from cql_queries import query1, query2, query3
def test_queries(session, query):
"""
Takes in a query and returns the output in a pandas dataframe.
"""
rows = session.execute(query)
output = pd.DataFrame(rows)
return output.head()
def main():
"""
Tests the queries in cql_queries.py on the tables in sparkify db
and prints the output as a dataframe.
- creates connection and session on cluster
- tests queries
- closes session and connection
"""
cluster = Cluster(['127.0.0.1'])
session = cluster.connect()
session.set_keyspace('sparkifydb')
print("Result Query 1")
print(test_queries(session, query1))
print("\n")
print("Result Query 2")
print(test_queries(session, query2))
print("\n")
print("Result Query 3")
print(test_queries(session, query3))
session.shutdown()
cluster.shutdown()
if __name__ == "__main__":
main()