# # # raw_graphs_table_util.cfv # # include "templates.statistics.util.get_xref_table_exists_info"; subroutine(get_raw_graph_table_info( string session_id, string profile_name, node query_fields, string report_element_type, node base_query_header, node used_database_fields, bool is_report_field_expression, bool is_table_filter_expression, bool is_sort_by_before_expression_evaluation, string sort_by_before_expression_evaluation, string sort_direction_before_expression_evaluation, bool use_overview_for_totals, string root_table_id, string combined_filter_expression, string sort_by_report_field_name, string sort_direction, int max_variables, int first_weekday, int number_of_days, bool allow_xref_table, # I.e., set to false for chrono graph table where xref tables are not useful. bool get_total_rows, # Only set when we need to return the total rows node progress_substep_info, node collected_whitelist_objects), ( debug_message("\n\n#### get_raw_graphs_table_info() \n\n"); # This returns table information for the requested sorted table. # If the table does not exist then it is created here. bool is_pivot_table = false; string sorted_table_id = root_table_id; # This is overriden if the table becomes sorted. int total_rows; bool got_total_rows_from_ssql_table_update = false; # # Check if the root_table exists # bool root_table_exists = get_table_exists(profile_name, root_table_id, collected_whitelist_objects); bool is_xref_table = false; string xref_source_table_id = ""; if (!root_table_exists) then ( # # # Check if we have a sorted xref table # # if (allow_xref_table and !is_report_field_expression and !is_table_filter_expression and combined_filter_expression eq "") then ( string sort_by_database_field_name = ""; if (sort_by_report_field_name ne "") then ( sort_by_database_field_name = @query_fields{sort_by_report_field_name}{"database_field_name"}; ); node xref_table_exists_info = get_xref_table_exists_info( session_id, profile_name, used_database_fields, root_table_id, sort_by_database_field_name, sort_direction, 1, # starting_row max_variables, # ending_row first_weekday, collected_whitelist_objects); debug_message("#### xref_table_exists_info:\n" . node_as_string(xref_table_exists_info) . "\n"); is_xref_table = @xref_table_exists_info{"is_xref_table"}; if (is_xref_table) then ( # Set special sorted_table_id sorted_table_id = @xref_table_exists_info{"xref_root_table_id"}; # xref_source_table_id is the original xref table with all rows, we need this for total rows and the sum xref_source_table_id = @xref_table_exists_info{"xref_source_table_id"}; # # Delete rows with zero values ??? # ToDO - we cannot do this for xref tables where the rows are exactly defined, check with Greg! # # if (!is_log_detail) then ( # delete_table_rows_with_zero_values(base_query_header, root_table_id); # ); ); ); debug_message("#### is_xref_table: " . is_xref_table . "\n"); if (!is_xref_table) then ( # # Get a regular root table # # # Set the final filter expression # volatile.filters = if (combined_filter_expression ne "") then (combined_filter_expression) else ("nofilters"); # # # Set query_info and query_result # # delete_node("v.query_info"); v.query_info = ""; v.query_info.report_element_type = report_element_type; v.query_info.number_of_days = number_of_days; # required in expressions v.query_info.is_sort_by_before_expression_evaluation = is_sort_by_before_expression_evaluation; v.query_info.sort_by_before_expression_evaluation = sort_by_before_expression_evaluation; v.query_info.sort_direction_before_expression_evaluation = sort_direction_before_expression_evaluation; v.query_info.header = ""; delete_node("v.query_result"); v.query_result = ""; clone_node(base_query_header, "v.query_info.header"); # # Execute the query # query_db_for_report("v.query_info", "v.query_result", root_table_id); increment_progress_substep(progress_substep_info); # # # Delete rows with zero values # # delete_table_rows_with_zero_values(base_query_header, root_table_id); # # # Handle table filter expression # # if (is_table_filter_expression) then ( bool is_handle_progress = true; total_rows = expression_handling_apply_table_filter_expression( profile_name, base_query_header, root_table_id, use_overview_for_totals, number_of_days, is_handle_progress, progress_substep_info ); # total_rows = @update_ssql_table_result{"total_rows"}; # row_visibility_cutoff_filter_expression = @update_ssql_table_result{"row_visibility_cutoff_filter_expression"}; got_total_rows_from_ssql_table_update = true; ); # Add new table to collected_whitelist_objects @collected_whitelist_objects{"tables"}{root_table_id} = true; ); ); # # # Handle sorted root table # # if (!is_xref_table and sort_by_report_field_name ne "") then ( sorted_table_id = get_sorted_table_id(root_table_id, sort_by_report_field_name, sort_direction, first_weekday); if (!get_table_exists(profile_name, sorted_table_id, collected_whitelist_objects)) then ( string qs = "CREATE TABLE " . sorted_table_id . " "; qs .= "SELECT * "; qs .= "FROM " . root_table_id . " "; qs .= "ORDER BY " . sort_by_report_field_name; if (sort_direction eq "descending") then ( qs .= " DESC"; ); ssql_query(qs); # Add new table to collected_whitelist_objects @collected_whitelist_objects{"tables"}{sorted_table_id} = true; ); ); # # # Get number of total rows # # if (get_total_rows) then ( if (is_xref_table) then ( # Get rows from xref_source_table table xref_source_table = load_table(xref_source_table_id); total_rows = table_get_num_rows(xref_source_table); unload_table(xref_source_table); ) else if (!got_total_rows_from_ssql_table_update) then ( table root_table = load_table(root_table_id); total_rows = table_get_num_rows(root_table); unload_table(root_table); ); ); debug_message("#### get_total_rows: " . get_total_rows . "\n"); debug_message("#### total_rows: " . total_rows . "\n"); # Set return values node n = new_node(); @n{"is_xref_table"} = is_xref_table; @n{"xref_source_table_id"} = xref_source_table_id; @n{"sorted_table_id"} = sorted_table_id; @n{"total_rows"} = total_rows; # Return n; ));