-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetColumnCount.py
More file actions
33 lines (29 loc) · 1.09 KB
/
getColumnCount.py
File metadata and controls
33 lines (29 loc) · 1.09 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
# getting column count from a specified databases' table
import subprocess
def getColumnCount(database, table, column):
with open("gettingColumnCount.hql", "w") as hql:
hql.write("USE "+database+";"+"\n")
hql.write("SELECT COUNT("+column+") FROM "+table+";"+"\n")
hql.close()
process = subprocess.check_output(["beeline", "--showHeader=false", "--outputformat=dsv", "-u", "jdbc:hive2://localhost:10000/default", "-f", "gettingColumnCount.hql"]).split("\n")
results = []
for joe in process:
results.append(joe)
with open('resultsForColumnCount.txt', 'w') as resultsFile:
counter = 0
counter2 = 0
dummie = 0
for i in results[:-1]:
if counter < 2:
counter += 1
if counter2 < 4:
counter2 += 1
if counter2 == 3 and counter >= 2:
resultsFile.write(i+"\n")
else:
dummie = 1
resultsFile.close()
dbName = "tpcds_parquet"
tableName = "et_customer"
columnName = "c_customer_id"
getColumnCount(dbName, tableName, columnName)