def pit_col_at_date(table_name, col_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 code, report_period, m_nDate from ej(source_table, query_table, `report_period) where partition(code, code_partition_id); col_list = ['code', 'report_period', 'appear_in_period', 'appear_at_date', col_name] from_tbl = where_conditions = [] source_table_part = sql(select=col_list, from=from_tbl, where=where_conditions); return select * from aj(query_table_exp, source_table_part, `report_period`m_nDate, `report_period`appear_at_date) } addFunctionView(pit_col_at_date)