//dropFunctionView('pit_report_period_at_date') def pit_at_date(table_name, date, report_period_list, code_partition_id) { source_table = loadTable("dfs://pit_stock_ts", table_name); m_nDate = take(date, size(report_period_list)); report_period = report_period_list; query_table = table(report_period, m_nDate); query_table_exp = select * from cj(query_table, select code from source_table where partition(code, code_partition_id) group by code map); source_table_part = select source_table.* from ej(source_table, query_table_exp, `code`report_period) where partition(code, code_partition_id); return select * from aj(query_table_exp, source_table_part, `code`report_period`m_nDate, `code`report_period`appear_at_date) } addFunctionView(pit_at_date)