-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathdb_call_factor_example.dos
More file actions
32 lines (28 loc) · 1.39 KB
/
Copy pathdb_call_factor_example.dos
File metadata and controls
32 lines (28 loc) · 1.39 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
login("admin","123456")
dropFunctionView(`simple_cal)
def simple_cal(input,start_date, end_date){
return select tradetime,securityid, open -close as factor_value from input where date(tradetime) between date(start_date): date(end_date) map
}
addFunctionView(simple_cal)
//save factor result method
def write_in_wide_database(funcN,factorN,start_date, end_date){
input =loadTable("dfs://k_minute_level","k_minute")
res = funcByName(funcN)(input,start_date, end_date)
if(res.size()==0) return
pivot_res = select factor_value from res pivot by tradetime,securityid
pivot_res[`factorname]=string(factorN)
reorderColumns!(pivot_res,`tradetime`factorname)
res_t = loadTable("dfs://K_FACTOR_WIDE","factor_k_wide")
res_t.append!(pivot_res)
}
func_table = table(take(`simple_cal,20) as func_name, string(1..20) as factorname, 2020.01.01..2020.01.20 as start_date,2020.01.02..2020.01.21 as end_date)
//
for (i in 0..(size(func_table)-1)){
funcN=func_table[`func_name][i]
factorN=func_table[`factorname][i]
start_date =func_table[`start_date][i]
end_date=func_table[`end_date][i]
submitJob("submitjob_"+funcN+factorN, "write_in_wide_database"+funcN+factorN+start_date, write_in_wide_database,funcN,factorN,start_date, end_date)
}
t=getRecentJobs()
select * from t where jobId like '%submitjob_%'