-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfinamic_graph.py
37 lines (31 loc) · 1.6 KB
/
finamic_graph.py
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
#
# Copyright 2016 Sotera Defense Solutions Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
from subprocess import call
database = sys.argv[1]
table = sys.argv[2]
last_table = sys.argv[3]
number = int(sys.argv[4])
source_string = ''
target_string = ''
while number > 1:
source_string = source_string + ', t2.comm_' + str(number) + ' as comm_' + str(number) + '_source'
target_string = target_string + ', t3.comm_' + str(number) + ' as comm_' + str(number) + '_destination'
number = number - 1
call("hive -e \"drop table " + database + "." + table + "_dynamic_graph_w_comms;\"",shell=True)
table_string = "hive -e \"create table " + database + "." + table + "_dynamic_graph_w_comms as select t1.source, t2.comm_1 as comm_1_source" + source_string + ', t1.destination, t3.comm_1 as comm_1_destination' + target_string + ', t1.firstdate, t1.lastdate, t1.value from ' + database + "." + last_table + ' t2 join ' + database + "." + table + '_dynamic_graph t1 on (t2.node = t1.source) join ' + database + "." + last_table + ' t3 on (t3.node = t1.destination);\"'
print table_string
call(table_string, shell=True)