├── .devcontainer ├── Dockerfile ├── demo_startup.sh └── devcontainer.json ├── .github └── workflows │ ├── build_pip.yml │ └── pr_testing.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── demos ├── README.md ├── images │ └── tpc_h_schema.png ├── metadata │ └── tpch_demo_graph.json ├── notebooks │ ├── 1_introduction.ipynb │ ├── 2_pydough_operations.ipynb │ ├── 3_exploration.ipynb │ ├── 4_tpch.ipynb │ └── 5_what_if.ipynb └── setup_tpch.sh ├── documentation ├── dsl.md ├── functions.md ├── metadata.md └── usage.md ├── meta_visualizer ├── DEVELOPER_DOCS.md ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── css │ │ └── styles.css │ ├── index.html │ └── js │ │ └── graph │ │ ├── README.md │ │ ├── core │ │ ├── README.md │ │ ├── dataProcessor.js │ │ ├── graphCreator.js │ │ └── graphInitializer.js │ │ ├── index.js │ │ ├── interactions │ │ ├── README.md │ │ ├── dragHandler.js │ │ ├── highlightHandler.js │ │ ├── tooltipHandler.js │ │ └── zoomHandler.js │ │ ├── layouts │ │ ├── README.md │ │ ├── forceLayout.js │ │ └── treeLayout.js │ │ ├── renderers │ │ ├── README.md │ │ ├── linkRenderer.js │ │ ├── markerRenderer.js │ │ └── nodeRenderer.js │ │ ├── styles │ │ ├── README.md │ │ └── graphStyles.js │ │ └── utils │ │ ├── README.md │ │ └── geometryUtils.js ├── serve.sh └── server.js ├── pydough ├── __init__.py ├── configs │ ├── README.md │ ├── __init__.py │ ├── pydough_configs.py │ └── session.py ├── conversion │ ├── README.md │ ├── __init__.py │ ├── agg_removal.py │ ├── agg_split.py │ ├── filter_pushdown.py │ ├── hybrid_decorrelater.py │ ├── hybrid_tree.py │ ├── merge_projects.py │ └── relational_converter.py ├── database_connectors │ ├── README.md │ ├── __init__.py │ ├── builtin_databases.py │ ├── database_connector.py │ └── empty_connection.py ├── evaluation │ ├── README.md │ ├── __init__.py │ └── evaluate_unqualified.py ├── exploration │ ├── README.md │ ├── __init__.py │ ├── explain.py │ ├── structure.py │ └── term.py ├── jupyter_extensions │ ├── README.md │ ├── __init__.py │ └── pydough_magic.py ├── logger │ ├── README.md │ ├── __init__.py │ └── logger.py ├── metadata │ ├── README.md │ ├── __init__.py │ ├── abstract_metadata.py │ ├── collections │ │ ├── README.md │ │ ├── __init__.py │ │ ├── collection_metadata.py │ │ └── simple_table_metadata.py │ ├── errors.py │ ├── graphs │ │ ├── README.md │ │ ├── __init__.py │ │ └── graph_metadata.py │ ├── parse.py │ └── properties │ │ ├── README.md │ │ ├── __init__.py │ │ ├── cartesian_product_metadata.py │ │ ├── general_join_metadata.py │ │ ├── property_metadata.py │ │ ├── reversible_property_metadata.py │ │ ├── scalar_attribute_metadata.py │ │ ├── simple_join_metadata.py │ │ ├── subcollection_relationship_metadata.py │ │ └── table_column_metadata.py ├── pydough_operators │ ├── README.md │ ├── __init__.py │ ├── base_operator.py │ ├── expression_operators │ │ ├── README.md │ │ ├── __init__.py │ │ ├── binary_operators.py │ │ ├── expression_function_operators.py │ │ ├── expression_operator.py │ │ ├── expression_window_operators.py │ │ ├── keyword_branching_operators.py │ │ └── registered_expression_operators.py │ ├── operator_registry.py │ └── type_inference │ │ ├── README.md │ │ ├── __init__.py │ │ ├── expression_type_deducer.py │ │ └── type_verifier.py ├── qdag │ ├── README.md │ ├── __init__.py │ ├── abstract_pydough_qdag.py │ ├── collections │ │ ├── README.md │ │ ├── __init__.py │ │ ├── augmenting_child_operator.py │ │ ├── calculate.py │ │ ├── child_access.py │ │ ├── child_operator.py │ │ ├── child_operator_child_access.py │ │ ├── child_reference_collection.py │ │ ├── collection_access.py │ │ ├── collection_qdag.py │ │ ├── collection_tree_form.py │ │ ├── global_context.py │ │ ├── order_by.py │ │ ├── partition_by.py │ │ ├── partition_child.py │ │ ├── singular.py │ │ ├── sub_collection.py │ │ ├── table_collection.py │ │ ├── top_k.py │ │ └── where.py │ ├── errors.py │ ├── expressions │ │ ├── README.md │ │ ├── __init__.py │ │ ├── back_reference_expression.py │ │ ├── child_reference_expression.py │ │ ├── collation_expression.py │ │ ├── column_property.py │ │ ├── expression_function_call.py │ │ ├── expression_qdag.py │ │ ├── hidden_back_reference_expression.py │ │ ├── literal.py │ │ ├── partition_key.py │ │ ├── reference.py │ │ ├── sided_reference.py │ │ └── window_call.py │ ├── has_hasnot_rewrite.py │ └── node_builder.py ├── relational │ ├── README.md │ ├── __init__.py │ ├── rel_util.py │ ├── relational_expressions │ │ ├── README.md │ │ ├── __init__.py │ │ ├── abstract_expression.py │ │ ├── call_expression.py │ │ ├── column_reference.py │ │ ├── column_reference_finder.py │ │ ├── column_reference_input_name_modifier.py │ │ ├── column_reference_input_name_remover.py │ │ ├── correlated_reference.py │ │ ├── correlated_reference_finder.py │ │ ├── expression_sort_info.py │ │ ├── literal_expression.py │ │ ├── relational_expression_shuttle.py │ │ ├── relational_expression_visitor.py │ │ └── window_call_expression.py │ └── relational_nodes │ │ ├── README.md │ │ ├── __init__.py │ │ ├── abstract_node.py │ │ ├── aggregate.py │ │ ├── column_pruner.py │ │ ├── empty_singleton.py │ │ ├── filter.py │ │ ├── join.py │ │ ├── join_type_relational_visitor.py │ │ ├── limit.py │ │ ├── project.py │ │ ├── relational_expression_dispatcher.py │ │ ├── relational_root.py │ │ ├── relational_visitor.py │ │ ├── scan.py │ │ ├── single_relational.py │ │ └── tree_string_visitor.py ├── sqlglot │ ├── README.md │ ├── __init__.py │ ├── execute_relational.py │ ├── sqlglot_helpers.py │ ├── sqlglot_identifier_finder.py │ ├── sqlglot_relational_expression_visitor.py │ ├── sqlglot_relational_visitor.py │ └── transform_bindings │ │ ├── README.md │ │ ├── __init__.py │ │ ├── base_transform_bindings.py │ │ ├── sqlglot_transform_utils.py │ │ └── sqlite_transform_bindings.py ├── types │ ├── README.md │ ├── __init__.py │ ├── array_type.py │ ├── boolean_type.py │ ├── date_type.py │ ├── datetime_type.py │ ├── errors.py │ ├── map_type.py │ ├── numeric_type.py │ ├── parse_types.py │ ├── pydough_type.py │ ├── string_type.py │ ├── struct_type.py │ └── unknown_type.py └── unqualified │ ├── README.md │ ├── __init__.py │ ├── errors.py │ ├── qualification.py │ ├── unqualified_node.py │ └── unqualified_transform.py ├── pyproject.toml ├── pytest.ini └── tests ├── README.md ├── bad_pydough_functions.py ├── conftest.py ├── correlated_pydough_functions.py ├── defog_outputs.py ├── defog_test_functions.py ├── epoch_pydough_functions.py ├── exploration_examples.py ├── gen_data ├── __init__.py └── gen_technograph.py ├── init_defog.sql ├── init_epoch.sql ├── init_technograph.sql ├── setup_defog.sh ├── simple_pydough_functions.py ├── technograph_pydough_functions.py ├── test_documentation.py ├── test_exploration.py ├── test_expression_type_deducer.py ├── test_expression_type_deducer_errors.py ├── test_logging.py ├── test_metadata.py ├── test_metadata ├── defog_graphs.json ├── invalid_graphs.json └── sample_graphs.json ├── test_metadata_errors.py ├── test_pipeline_correl.py ├── test_pipeline_defog.py ├── test_pipeline_defog_custom.py ├── test_pipeline_epoch.py ├── test_pipeline_tpch.py ├── test_pipeline_tpch_custom.py ├── test_plan_refsols ├── access_partition_child_after_filter.txt ├── access_partition_child_backref_calc.txt ├── access_partition_child_filter_backref_filter.txt ├── agg_max_ranking.txt ├── agg_orders_by_year_month_basic.txt ├── agg_orders_by_year_month_just_europe.txt ├── agg_orders_by_year_month_vs_europe.txt ├── agg_partition.txt ├── agg_parts_by_type_backref_global.txt ├── agg_parts_by_type_simple.txt ├── aggregate_anti.txt ├── aggregate_mixed_levels_simple.txt ├── aggregate_on_function_call.txt ├── aggregate_semi.txt ├── aggregate_then_backref.txt ├── anti_aggregate.txt ├── anti_aggregate_alternate.txt ├── anti_singular.txt ├── asian_nations.txt ├── avg_acctbal_wo_debt.txt ├── avg_gap_prev_urgent_same_clerk.txt ├── avg_order_diff_per_customer.txt ├── correl_1.txt ├── correl_10.txt ├── correl_11.txt ├── correl_12.txt ├── correl_13.txt ├── correl_14.txt ├── correl_15.txt ├── correl_16.txt ├── correl_17.txt ├── correl_18.txt ├── correl_19.txt ├── correl_2.txt ├── correl_20.txt ├── correl_21.txt ├── correl_22.txt ├── correl_23.txt ├── correl_24.txt ├── correl_25.txt ├── correl_26.txt ├── correl_27.txt ├── correl_28.txt ├── correl_29.txt ├── correl_3.txt ├── correl_30.txt ├── correl_31.txt ├── correl_32.txt ├── correl_33.txt ├── correl_4.txt ├── correl_5.txt ├── correl_6.txt ├── correl_7.txt ├── correl_8.txt ├── correl_9.txt ├── count_at_most_100_suppliers_per_nation.txt ├── count_cust_supplier_nation_combos.txt ├── count_multiple_subcollections_alongside_aggs.txt ├── count_single_subcollection.txt ├── cumulative_stock_analysis.txt ├── customer_largest_order_deltas.txt ├── customer_most_recent_orders.txt ├── customers_sum_line_price.txt ├── datetime_current.txt ├── datetime_relative.txt ├── double_partition.txt ├── dumb_aggregation.txt ├── epoch_culture_events_info.txt ├── epoch_event_gap_per_era.txt ├── epoch_events_per_season.txt ├── epoch_first_event_per_era.txt ├── epoch_intra_season_searches.txt ├── epoch_most_popular_search_engine_per_tod.txt ├── epoch_most_popular_topic_per_region.txt ├── epoch_num_predawn_cold_war.txt ├── epoch_overlapping_event_search_other_users_per_user.txt ├── epoch_overlapping_event_searches_per_user.txt ├── epoch_pct_searches_per_tod.txt ├── epoch_search_results_by_tod.txt ├── epoch_summer_events_per_type.txt ├── epoch_unique_users_per_engine.txt ├── epoch_users_most_cold_war_searches.txt ├── exponentiation.txt ├── find.txt ├── first_order_in_year.txt ├── first_order_per_customer.txt ├── function_sampler.txt ├── global_acctbal_breakdown.txt ├── global_aggfunc_backref.txt ├── global_aggfuncs.txt ├── global_aggfuncs_multiple_children.txt ├── global_calc_backref.txt ├── global_calc_multiple.txt ├── global_calc_simple.txt ├── highest_priority_per_year.txt ├── hour_minute_day.txt ├── join_asia_region_nations.txt ├── join_order_by.txt ├── join_order_by_back_reference.txt ├── join_order_by_pruned_back_reference.txt ├── join_region_nations.txt ├── join_region_nations_customers.txt ├── join_topk.txt ├── lineitem_regional_shipments.txt ├── lineitem_regional_shipments2.txt ├── lineitem_regional_shipments3.txt ├── lineitems_access_cust_supplier_nations.txt ├── lines_german_supplier_economy_part.txt ├── lines_shipping_vs_customer_region.txt ├── minutes_seconds_datediff.txt ├── month_year_sliding_windows.txt ├── mostly_positive_accounts_per_nation1.txt ├── mostly_positive_accounts_per_nation2.txt ├── mostly_positive_accounts_per_nation3.txt ├── multi_partition_access_1.txt ├── multi_partition_access_2.txt ├── multi_partition_access_3.txt ├── multi_partition_access_4.txt ├── multi_partition_access_5.txt ├── multi_partition_access_6.txt ├── multiple_has_hasnot.txt ├── multiple_simple_aggregations_multiple_calcs.txt ├── multiple_simple_aggregations_single_calc.txt ├── n_orders_first_day.txt ├── nation_acctbal_breakdown.txt ├── nation_best_order.txt ├── nation_name_contains_region_name.txt ├── nation_window_aggs.txt ├── nations_access_region.txt ├── nations_order_by_num_suppliers.txt ├── nations_region_order_by_name.txt ├── nations_sum_line_price.txt ├── num_positive_accounts_per_nation.txt ├── odate_and_rdate_avggap.txt ├── order_by_before_join.txt ├── order_by_expression.txt ├── order_info_per_priority.txt ├── order_quarter_test.txt ├── ordered_asian_nations.txt ├── ordering_name_overload.txt ├── orders_sum_line_price.txt ├── orders_sum_vs_count_line_price.txt ├── orders_versus_first_orders.txt ├── padding_functions.txt ├── part_reduced_size.txt ├── parts_quantity_increase_95_96.txt ├── percentile_customers_per_region.txt ├── percentile_nations.txt ├── prev_next_regions.txt ├── quarter_function_test.txt ├── rank_customers.txt ├── rank_customers_per_nation.txt ├── rank_customers_per_region.txt ├── rank_nations_by_region.txt ├── rank_nations_per_region_by_customers.txt ├── rank_parts_per_supplier_region_by_size.txt ├── rank_with_filters_a.txt ├── rank_with_filters_b.txt ├── rank_with_filters_c.txt ├── region_acctbal_breakdown.txt ├── region_nation_window_aggs.txt ├── region_nations_backref.txt ├── region_orders_from_nations_richest.txt ├── regional_first_order_best_line_part.txt ├── regional_suppliers_percentile.txt ├── regions_sum_line_price.txt ├── replace.txt ├── replace_order_by.txt ├── richest_customer_per_region.txt ├── scan_calc.txt ├── scan_calc_calc.txt ├── scan_customer_call_functions.txt ├── scan_nations.txt ├── scan_regions.txt ├── semi_aggregate.txt ├── semi_singular.txt ├── sign.txt ├── simple_anti_1.txt ├── simple_anti_2.txt ├── simple_filter_top_five.txt ├── simple_int_float_string_cast.txt ├── simple_order_by.txt ├── simple_scan_top_five.txt ├── simple_semi_1.txt ├── simple_semi_2.txt ├── simple_smallest_or_largest.txt ├── simple_topk.txt ├── simple_var_std.txt ├── simple_var_std_with_nulls.txt ├── singular1.txt ├── singular2.txt ├── singular3.txt ├── singular4.txt ├── singular5.txt ├── singular6.txt ├── singular7.txt ├── singular_anti.txt ├── singular_semi.txt ├── step_slicing.txt ├── string_format_specifiers_sqlite.txt ├── strip.txt ├── supplier_best_part.txt ├── supplier_pct_national_qty.txt ├── suppliers_bal_diffs.txt ├── technograph_battery_failure_rates_anomalies.txt ├── technograph_country_cartesian_oddball.txt ├── technograph_country_combination_analysis.txt ├── technograph_country_incident_rate_analysis.txt ├── technograph_error_percentages_sun_set_by_error.txt ├── technograph_error_rate_sun_set_by_factory_country.txt ├── technograph_global_incident_rate.txt ├── technograph_hot_purchase_window.txt ├── technograph_incident_rate_by_release_year.txt ├── technograph_incident_rate_per_brand.txt ├── technograph_monthly_incident_rate.txt ├── technograph_most_unreliable_products.txt ├── technograph_year_cumulative_incident_rate_goldcopperstar.txt ├── technograph_year_cumulative_incident_rate_overall.txt ├── time_threshold_reached.txt ├── top_5_nations_balance_by_num_suppliers.txt ├── top_5_nations_by_num_supplierss.txt ├── top_customers_by_orders.txt ├── topk_order_by.txt ├── topk_order_by_calc.txt ├── topk_replace_order_by.txt ├── topk_root_different_order_by.txt ├── tpch_q1.txt ├── tpch_q10.txt ├── tpch_q11.txt ├── tpch_q12.txt ├── tpch_q13.txt ├── tpch_q14.txt ├── tpch_q15.txt ├── tpch_q16.txt ├── tpch_q17.txt ├── tpch_q18.txt ├── tpch_q19.txt ├── tpch_q2.txt ├── tpch_q20.txt ├── tpch_q21.txt ├── tpch_q22.txt ├── tpch_q3.txt ├── tpch_q4.txt ├── tpch_q5.txt ├── tpch_q6.txt ├── tpch_q7.txt ├── tpch_q8.txt ├── tpch_q9.txt ├── triple_partition.txt ├── various_aggfuncs_global.txt ├── various_aggfuncs_simple.txt ├── wealthiest_supplier.txt ├── week_offset.txt ├── window_sliding_frame_relsize.txt ├── window_sliding_frame_relsum.txt ├── year_month_nation_orders.txt ├── years_months_days_hours_datediff.txt └── yoy_change_in_num_orders.txt ├── test_pydough_to_sql.py ├── test_qdag_collection.py ├── test_qdag_collection_errors.py ├── test_qdag_conversion.py ├── test_qdag_expression.py ├── test_qdag_expression_errors.py ├── test_qualification.py ├── test_qualification_errors.py ├── test_relational.py ├── test_relational_column_pruner.py ├── test_relational_execution.py ├── test_relational_execution_tpch.py ├── test_relational_expressions.py ├── test_relational_nodes_to_sqlglot.py ├── test_relational_to_sql.py ├── test_session.py ├── test_sql_refsols ├── cumulative_stock_analysis_ansi.sql ├── cumulative_stock_analysis_sqlite.sql ├── datediff_ansi.sql ├── datediff_sqlite.sql ├── datetime_sampler_ansi.sql ├── datetime_sampler_sqlite.sql ├── defog_broker_adv10_ansi.sql ├── defog_broker_adv10_sqlite.sql ├── defog_broker_adv11_ansi.sql ├── defog_broker_adv11_sqlite.sql ├── defog_broker_adv12_ansi.sql ├── defog_broker_adv12_sqlite.sql ├── defog_broker_adv13_ansi.sql ├── defog_broker_adv13_sqlite.sql ├── defog_broker_adv14_ansi.sql ├── defog_broker_adv14_sqlite.sql ├── defog_broker_adv15_ansi.sql ├── defog_broker_adv15_sqlite.sql ├── defog_broker_adv16_ansi.sql ├── defog_broker_adv16_sqlite.sql ├── defog_broker_adv1_ansi.sql ├── defog_broker_adv1_sqlite.sql ├── defog_broker_adv2_ansi.sql ├── defog_broker_adv2_sqlite.sql ├── defog_broker_adv3_ansi.sql ├── defog_broker_adv3_sqlite.sql ├── defog_broker_adv4_ansi.sql ├── defog_broker_adv4_sqlite.sql ├── defog_broker_adv5_ansi.sql ├── defog_broker_adv5_sqlite.sql ├── defog_broker_adv6_ansi.sql ├── defog_broker_adv6_sqlite.sql ├── defog_broker_adv7_ansi.sql ├── defog_broker_adv7_sqlite.sql ├── defog_broker_adv8_ansi.sql ├── defog_broker_adv8_sqlite.sql ├── defog_broker_adv9_ansi.sql ├── defog_broker_adv9_sqlite.sql ├── defog_broker_basic10_ansi.sql ├── defog_broker_basic10_sqlite.sql ├── defog_broker_basic1_ansi.sql ├── defog_broker_basic1_sqlite.sql ├── defog_broker_basic2_ansi.sql ├── defog_broker_basic2_sqlite.sql ├── defog_broker_basic3_ansi.sql ├── defog_broker_basic3_sqlite.sql ├── defog_broker_basic4_ansi.sql ├── defog_broker_basic4_sqlite.sql ├── defog_broker_basic5_ansi.sql ├── defog_broker_basic5_sqlite.sql ├── defog_broker_basic6_ansi.sql ├── defog_broker_basic6_sqlite.sql ├── defog_broker_basic7_ansi.sql ├── defog_broker_basic7_sqlite.sql ├── defog_broker_basic8_ansi.sql ├── defog_broker_basic8_sqlite.sql ├── defog_broker_basic9_ansi.sql ├── defog_broker_basic9_sqlite.sql ├── defog_broker_gen1_ansi.sql ├── defog_broker_gen1_sqlite.sql ├── defog_broker_gen2_ansi.sql ├── defog_broker_gen2_sqlite.sql ├── defog_broker_gen3_ansi.sql ├── defog_broker_gen3_sqlite.sql ├── defog_broker_gen4_ansi.sql ├── defog_broker_gen4_sqlite.sql ├── defog_broker_gen5_ansi.sql ├── defog_broker_gen5_sqlite.sql ├── defog_dealership_adv10_ansi.sql ├── defog_dealership_adv10_sqlite.sql ├── defog_dealership_adv11_ansi.sql ├── defog_dealership_adv11_sqlite.sql ├── defog_dealership_adv12_ansi.sql ├── defog_dealership_adv12_sqlite.sql ├── defog_dealership_adv14_ansi.sql ├── defog_dealership_adv14_sqlite.sql ├── defog_dealership_adv15_ansi.sql ├── defog_dealership_adv15_sqlite.sql ├── defog_dealership_adv16_ansi.sql ├── defog_dealership_adv16_sqlite.sql ├── defog_dealership_adv1_ansi.sql ├── defog_dealership_adv1_sqlite.sql ├── defog_dealership_adv2_ansi.sql ├── defog_dealership_adv2_sqlite.sql ├── defog_dealership_adv3_ansi.sql ├── defog_dealership_adv3_sqlite.sql ├── defog_dealership_adv4_ansi.sql ├── defog_dealership_adv4_sqlite.sql ├── defog_dealership_adv5_ansi.sql ├── defog_dealership_adv5_sqlite.sql ├── defog_dealership_adv6_ansi.sql ├── defog_dealership_adv6_sqlite.sql ├── defog_dealership_adv7_ansi.sql ├── defog_dealership_adv7_sqlite.sql ├── defog_dealership_adv9_ansi.sql ├── defog_dealership_adv9_sqlite.sql ├── defog_dealership_basic10_ansi.sql ├── defog_dealership_basic10_sqlite.sql ├── defog_dealership_basic1_ansi.sql ├── defog_dealership_basic1_sqlite.sql ├── defog_dealership_basic2_ansi.sql ├── defog_dealership_basic2_sqlite.sql ├── defog_dealership_basic3_ansi.sql ├── defog_dealership_basic3_sqlite.sql ├── defog_dealership_basic4_ansi.sql ├── defog_dealership_basic4_sqlite.sql ├── defog_dealership_basic5_ansi.sql ├── defog_dealership_basic5_sqlite.sql ├── defog_dealership_basic6_ansi.sql ├── defog_dealership_basic6_sqlite.sql ├── defog_dealership_basic7_ansi.sql ├── defog_dealership_basic7_sqlite.sql ├── defog_dealership_basic8_ansi.sql ├── defog_dealership_basic8_sqlite.sql ├── defog_dealership_basic9_ansi.sql ├── defog_dealership_basic9_sqlite.sql ├── defog_dealership_gen1_ansi.sql ├── defog_dealership_gen1_sqlite.sql ├── defog_dealership_gen2_ansi.sql ├── defog_dealership_gen2_sqlite.sql ├── defog_dealership_gen3_ansi.sql ├── defog_dealership_gen3_sqlite.sql ├── defog_dealership_gen4_ansi.sql ├── defog_dealership_gen4_sqlite.sql ├── defog_dealership_gen5_ansi.sql ├── defog_dealership_gen5_sqlite.sql ├── defog_ewallet_adv10_ansi.sql ├── defog_ewallet_adv10_sqlite.sql ├── defog_ewallet_adv11_ansi.sql ├── defog_ewallet_adv11_sqlite.sql ├── defog_ewallet_adv12_ansi.sql ├── defog_ewallet_adv12_sqlite.sql ├── defog_ewallet_adv13_ansi.sql ├── defog_ewallet_adv13_sqlite.sql ├── defog_ewallet_adv14_ansi.sql ├── defog_ewallet_adv14_sqlite.sql ├── defog_ewallet_adv15_ansi.sql ├── defog_ewallet_adv15_sqlite.sql ├── defog_ewallet_adv16_ansi.sql ├── defog_ewallet_adv16_sqlite.sql ├── defog_ewallet_adv1_ansi.sql ├── defog_ewallet_adv1_sqlite.sql ├── defog_ewallet_adv2_ansi.sql ├── defog_ewallet_adv2_sqlite.sql ├── defog_ewallet_adv3_ansi.sql ├── defog_ewallet_adv3_sqlite.sql ├── defog_ewallet_adv4_ansi.sql ├── defog_ewallet_adv4_sqlite.sql ├── defog_ewallet_adv5_ansi.sql ├── defog_ewallet_adv5_sqlite.sql ├── defog_ewallet_adv6_ansi.sql ├── defog_ewallet_adv6_sqlite.sql ├── defog_ewallet_adv7_ansi.sql ├── defog_ewallet_adv7_sqlite.sql ├── defog_ewallet_adv8_ansi.sql ├── defog_ewallet_adv8_sqlite.sql ├── defog_ewallet_adv9_ansi.sql ├── defog_ewallet_adv9_sqlite.sql ├── defog_ewallet_basic10_ansi.sql ├── defog_ewallet_basic10_sqlite.sql ├── defog_ewallet_basic1_ansi.sql ├── defog_ewallet_basic1_sqlite.sql ├── defog_ewallet_basic2_ansi.sql ├── defog_ewallet_basic2_sqlite.sql ├── defog_ewallet_basic3_ansi.sql ├── defog_ewallet_basic3_sqlite.sql ├── defog_ewallet_basic4_ansi.sql ├── defog_ewallet_basic4_sqlite.sql ├── defog_ewallet_basic5_ansi.sql ├── defog_ewallet_basic5_sqlite.sql ├── defog_ewallet_basic6_ansi.sql ├── defog_ewallet_basic6_sqlite.sql ├── defog_ewallet_basic7_ansi.sql ├── defog_ewallet_basic7_sqlite.sql ├── defog_ewallet_basic8_ansi.sql ├── defog_ewallet_basic8_sqlite.sql ├── defog_ewallet_basic9_ansi.sql ├── defog_ewallet_basic9_sqlite.sql ├── defog_ewallet_gen1_ansi.sql ├── defog_ewallet_gen1_sqlite.sql ├── defog_ewallet_gen2_ansi.sql ├── defog_ewallet_gen2_sqlite.sql ├── defog_ewallet_gen3_ansi.sql ├── defog_ewallet_gen3_sqlite.sql ├── defog_ewallet_gen4_ansi.sql ├── defog_ewallet_gen4_sqlite.sql ├── defog_ewallet_gen5_ansi.sql ├── defog_ewallet_gen5_sqlite.sql ├── duplicate_limit_different_ordering_sqlite.sql ├── duplicate_limit_min_inner_sqlite.sql ├── duplicate_limit_min_outer_sqlite.sql ├── epoch_culture_events_info_ansi.sql ├── epoch_culture_events_info_sqlite.sql ├── epoch_event_gap_per_era_ansi.sql ├── epoch_event_gap_per_era_sqlite.sql ├── epoch_events_per_season_ansi.sql ├── epoch_events_per_season_sqlite.sql ├── epoch_first_event_per_era_ansi.sql ├── epoch_first_event_per_era_sqlite.sql ├── epoch_intra_season_searches_ansi.sql ├── epoch_intra_season_searches_sqlite.sql ├── epoch_most_popular_search_engine_per_tod_ansi.sql ├── epoch_most_popular_search_engine_per_tod_sqlite.sql ├── epoch_most_popular_topic_per_region_ansi.sql ├── epoch_most_popular_topic_per_region_sqlite.sql ├── epoch_num_predawn_cold_war_ansi.sql ├── epoch_num_predawn_cold_war_sqlite.sql ├── epoch_overlapping_event_search_other_users_per_user_ansi.sql ├── epoch_overlapping_event_search_other_users_per_user_sqlite.sql ├── epoch_overlapping_event_searches_per_user_ansi.sql ├── epoch_overlapping_event_searches_per_user_sqlite.sql ├── epoch_pct_searches_per_tod_ansi.sql ├── epoch_pct_searches_per_tod_sqlite.sql ├── epoch_search_results_by_tod_ansi.sql ├── epoch_search_results_by_tod_sqlite.sql ├── epoch_summer_events_per_type_ansi.sql ├── epoch_summer_events_per_type_sqlite.sql ├── epoch_unique_users_per_engine_ansi.sql ├── epoch_unique_users_per_engine_sqlite.sql ├── epoch_users_most_cold_war_searches_ansi.sql ├── epoch_users_most_cold_war_searches_sqlite.sql ├── func_contains_ansi.sql ├── func_ends_with_ansi.sql ├── func_iff_iif_ansi.sql ├── func_isin_ansi.sql ├── func_like_ansi.sql ├── func_rank_with_filters_a_ansi.sql ├── func_rank_with_filters_b_ansi.sql ├── func_starts_with_ansi.sql ├── func_year_ansi.sql ├── global_acctbal_breakdown_ansi.sql ├── global_acctbal_breakdown_sqlite.sql ├── hour_minute_day_ansi.sql ├── hour_minute_day_sqlite.sql ├── multi_join_sqlite.sql ├── nation_acctbal_breakdown_ansi.sql ├── nation_acctbal_breakdown_sqlite.sql ├── nested_binary_functions_sqlite.sql ├── nested_join_sqlite.sql ├── ordering_function_sqlite.sql ├── project_scan_with_ordering_sqlite.sql ├── rank_a_ansi.sql ├── rank_a_sqlite.sql ├── rank_b_ansi.sql ├── rank_b_sqlite.sql ├── rank_c_ansi.sql ├── rank_c_sqlite.sql ├── region_acctbal_breakdown_ansi.sql ├── region_acctbal_breakdown_sqlite.sql ├── simple_anti_join_sqlite.sql ├── simple_distinct_sqlite.sql ├── simple_filter_ansi.sql ├── simple_filter_sqlite.sql ├── simple_filter_test_sqlite.sql ├── simple_full_outer_join_sqlite.sql ├── simple_groupby_sum_sqlite.sql ├── simple_inner_join_sqlite.sql ├── simple_left_join_sqlite.sql ├── simple_limit_sqlite.sql ├── simple_limit_with_ordering_sqlite.sql ├── simple_right_join_sqlite.sql ├── simple_scan_ansi.sql ├── simple_scan_sqlite.sql ├── simple_scan_test_sqlite.sql ├── simple_scan_with_ordering_sqlite.sql ├── simple_semi_join_sqlite.sql ├── simple_smallest_or_largest_ansi.sql ├── simple_smallest_or_largest_sqlite.sql ├── simple_sum_sqlite.sql ├── simple_values_sqlite.sql ├── simple_var_std_ansi.sql ├── simple_var_std_sqlite.sql ├── sql_transaction_week_sampler_friday_one_ansi.sql ├── sql_transaction_week_sampler_friday_one_sqlite.sql ├── sql_transaction_week_sampler_friday_zero_ansi.sql ├── sql_transaction_week_sampler_friday_zero_sqlite.sql ├── sql_transaction_week_sampler_monday_one_ansi.sql ├── sql_transaction_week_sampler_monday_one_sqlite.sql ├── sql_transaction_week_sampler_monday_zero_ansi.sql ├── sql_transaction_week_sampler_monday_zero_sqlite.sql ├── sql_transaction_week_sampler_saturday_one_ansi.sql ├── sql_transaction_week_sampler_saturday_one_sqlite.sql ├── sql_transaction_week_sampler_saturday_zero_ansi.sql ├── sql_transaction_week_sampler_saturday_zero_sqlite.sql ├── sql_transaction_week_sampler_sunday_one_ansi.sql ├── sql_transaction_week_sampler_sunday_one_sqlite.sql ├── sql_transaction_week_sampler_sunday_zero_ansi.sql ├── sql_transaction_week_sampler_sunday_zero_sqlite.sql ├── sql_transaction_week_sampler_thursday_one_ansi.sql ├── sql_transaction_week_sampler_thursday_one_sqlite.sql ├── sql_transaction_week_sampler_thursday_zero_ansi.sql ├── sql_transaction_week_sampler_thursday_zero_sqlite.sql ├── sql_transaction_week_sampler_tuesday_one_ansi.sql ├── sql_transaction_week_sampler_tuesday_one_sqlite.sql ├── sql_transaction_week_sampler_tuesday_zero_ansi.sql ├── sql_transaction_week_sampler_tuesday_zero_sqlite.sql ├── sql_transaction_week_sampler_wednesday_one_ansi.sql ├── sql_transaction_week_sampler_wednesday_one_sqlite.sql ├── sql_transaction_week_sampler_wednesday_zero_ansi.sql ├── sql_transaction_week_sampler_wednesday_zero_sqlite.sql ├── technograph_battery_failure_rates_anomalies_ansi.sql ├── technograph_battery_failure_rates_anomalies_sqlite.sql ├── technograph_country_cartesian_oddball_ansi.sql ├── technograph_country_cartesian_oddball_sqlite.sql ├── technograph_country_combination_analysis_ansi.sql ├── technograph_country_combination_analysis_sqlite.sql ├── technograph_country_incident_rate_analysis_ansi.sql ├── technograph_country_incident_rate_analysis_sqlite.sql ├── technograph_error_percentages_sun_set_by_error_ansi.sql ├── technograph_error_percentages_sun_set_by_error_sqlite.sql ├── technograph_error_rate_sun_set_by_factory_country_ansi.sql ├── technograph_error_rate_sun_set_by_factory_country_sqlite.sql ├── technograph_global_incident_rate_ansi.sql ├── technograph_global_incident_rate_sqlite.sql ├── technograph_hot_purchase_window_ansi.sql ├── technograph_hot_purchase_window_sqlite.sql ├── technograph_incident_rate_by_release_year_ansi.sql ├── technograph_incident_rate_by_release_year_sqlite.sql ├── technograph_incident_rate_per_brand_ansi.sql ├── technograph_incident_rate_per_brand_sqlite.sql ├── technograph_monthly_incident_rate_ansi.sql ├── technograph_monthly_incident_rate_sqlite.sql ├── technograph_most_unreliable_products_ansi.sql ├── technograph_most_unreliable_products_sqlite.sql ├── technograph_year_cumulative_incident_rate_goldcopperstar_ansi.sql ├── technograph_year_cumulative_incident_rate_goldcopperstar_sqlite.sql ├── technograph_year_cumulative_incident_rate_overall_ansi.sql ├── technograph_year_cumulative_incident_rate_overall_sqlite.sql ├── time_threshold_reached_ansi.sql ├── time_threshold_reached_sqlite.sql ├── tpch_q10_ansi.sql ├── tpch_q10_sqlite.sql ├── tpch_q11_ansi.sql ├── tpch_q11_sqlite.sql ├── tpch_q12_ansi.sql ├── tpch_q12_sqlite.sql ├── tpch_q13_ansi.sql ├── tpch_q13_sqlite.sql ├── tpch_q14_ansi.sql ├── tpch_q14_sqlite.sql ├── tpch_q15_ansi.sql ├── tpch_q15_sqlite.sql ├── tpch_q16_ansi.sql ├── tpch_q16_sqlite.sql ├── tpch_q17_ansi.sql ├── tpch_q17_sqlite.sql ├── tpch_q18_ansi.sql ├── tpch_q18_sqlite.sql ├── tpch_q19_ansi.sql ├── tpch_q19_sqlite.sql ├── tpch_q1_ansi.sql ├── tpch_q1_sqlite.sql ├── tpch_q20_ansi.sql ├── tpch_q20_sqlite.sql ├── tpch_q21_ansi.sql ├── tpch_q21_sqlite.sql ├── tpch_q22_ansi.sql ├── tpch_q22_sqlite.sql ├── tpch_q2_ansi.sql ├── tpch_q2_sqlite.sql ├── tpch_q3_ansi.sql ├── tpch_q3_sqlite.sql ├── tpch_q4_ansi.sql ├── tpch_q4_sqlite.sql ├── tpch_q5_ansi.sql ├── tpch_q5_sqlite.sql ├── tpch_q6_ansi.sql ├── tpch_q6_sqlite.sql ├── tpch_q7_ansi.sql ├── tpch_q7_sqlite.sql ├── tpch_q8_ansi.sql ├── tpch_q8_sqlite.sql ├── tpch_q9_ansi.sql ├── tpch_q9_sqlite.sql ├── week_offset_ansi.sql ├── week_offset_sqlite.sql ├── window_sliding_frame_relsize_ansi.sql ├── window_sliding_frame_relsize_sqlite.sql ├── window_sliding_frame_relsum_ansi.sql └── window_sliding_frame_relsum_sqlite.sql ├── test_sqlite_connection.py ├── test_technograph.py ├── test_tpch_download.py ├── test_type_verifier.py ├── test_type_verifier_errors.py ├── test_types.py ├── test_unqualified_node.py ├── test_utils.py ├── tpch_outputs.py ├── tpch_relational_plans.py └── tpch_test_functions.py /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/devcontainers/universal:2 2 | 3 | COPY /demos/setup_tpch.sh setup_tpch.sh 4 | 5 | # Install uv for command line editing. 6 | RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates 7 | 8 | ADD https://astral.sh/uv/install.sh /uv-installer.sh 9 | 10 | ENV HOME=/root 11 | 12 | RUN sh /uv-installer.sh && rm /uv-installer.sh 13 | 14 | ENV PATH="/root/.local/bin/:$PATH" 15 | 16 | # Download the TPC-H database. 17 | RUN ./setup_tpch.sh /usr/local/share/tpch.db 18 | -------------------------------------------------------------------------------- /.devcontainer/demo_startup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eo pipefail 4 | 5 | # Link the TPC-H database. Use a symlink to 6 | # avoid copying the data at launch. 7 | ln -s /usr/local/share/tpch.db ./tpch.db 8 | 9 | # Build the PyDough project 10 | python -m pip install . 11 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | ci: 2 | autoupdate_schedule: monthly 3 | 4 | repos: 5 | - repo: https://github.com/astral-sh/ruff-pre-commit 6 | rev: v0.11.8 7 | hooks: 8 | - id: ruff 9 | args: [ --fix, --exit-non-zero-on-fix ] 10 | - id: ruff-format 11 | - repo: https://github.com/pre-commit/mirrors-mypy 12 | rev: 'v1.15.0' 13 | hooks: 14 | - id: mypy 15 | args: [--check-untyped-defs, --ignore-missing-imports] 16 | additional_dependencies: [types-pytz] 17 | - repo: https://github.com/aio-libs/sort-all 18 | rev: 'v1.3.0' 19 | hooks: 20 | - id: sort-all 21 | -------------------------------------------------------------------------------- /demos/images/tpc_h_schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bodo-ai/PyDough/c55397cf88a19757824f15631dd558fd5ad5b8b0/demos/images/tpc_h_schema.png -------------------------------------------------------------------------------- /demos/setup_tpch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -eo pipefail 4 | 5 | if [ -e $1 ]; then 6 | echo "FOUND" 7 | exit 0 8 | else 9 | wget https://github.com/lovasoa/TPCH-sqlite/releases/download/v1.0/TPC-H.db -O $1 10 | fi 11 | -------------------------------------------------------------------------------- /meta_visualizer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "knowledge-graph-viewer", 3 | "version": "1.0.0", 4 | "description": "A visualization tool for knowledge graphs using D3.js", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js", 8 | "dev": "nodemon server.js" 9 | }, 10 | "dependencies": { 11 | "express": "^4.18.2", 12 | "d3": "^7.8.5" 13 | }, 14 | "devDependencies": { 15 | "nodemon": "^3.0.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /meta_visualizer/public/js/graph/index.js: -------------------------------------------------------------------------------- 1 | // Graph Visualization - Main Entry Point 2 | import { initGraphVisualization } from "./core/graphInitializer.js"; 3 | 4 | document.addEventListener("DOMContentLoaded", () => { 5 | console.log("DOM loaded, initializing graph visualization..."); 6 | initGraphVisualization(); 7 | }); 8 | -------------------------------------------------------------------------------- /meta_visualizer/server.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const path = require("path"); 3 | const fs = require("fs"); 4 | const app = express(); 5 | const PORT = process.env.PORT || 3001; 6 | 7 | const publicDir = path.join(__dirname, "public"); 8 | 9 | // Serve static files from the public directory 10 | app.use(express.static(publicDir)); 11 | 12 | // Serve the index.html file for the root route 13 | app.get("/", (req, res) => { 14 | res.sendFile(path.join(publicDir, "index.html")); 15 | }); 16 | 17 | 18 | // Start the server 19 | app.listen(PORT, () => { 20 | console.log(`Server is running on http://localhost:${PORT}`); 21 | console.log(`View the knowledge graph at http://localhost:${PORT}`); 22 | }); 23 | -------------------------------------------------------------------------------- /pydough/configs/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module of PyDough dealing with configurations and sessions. 3 | """ 4 | 5 | __all__ = ["ConfigProperty", "DayOfWeek", "PyDoughConfigs", "PyDoughSession"] 6 | 7 | from .pydough_configs import ConfigProperty, DayOfWeek, PyDoughConfigs 8 | from .session import PyDoughSession 9 | -------------------------------------------------------------------------------- /pydough/conversion/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module of PyDough dealing with converting the qualified PyDough QDAG nodes into 3 | Relational nodes. 4 | """ 5 | 6 | __all__ = ["convert_ast_to_relational"] 7 | 8 | from .relational_converter import convert_ast_to_relational 9 | -------------------------------------------------------------------------------- /pydough/database_connectors/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = [ 2 | "DatabaseConnection", 3 | "DatabaseContext", 4 | "DatabaseDialect", 5 | "empty_connection", 6 | "load_database_context", 7 | "load_sqlite_connection", 8 | ] 9 | 10 | from .builtin_databases import load_database_context, load_sqlite_connection 11 | from .database_connector import DatabaseConnection, DatabaseContext, DatabaseDialect 12 | from .empty_connection import empty_connection 13 | -------------------------------------------------------------------------------- /pydough/evaluation/README.md: -------------------------------------------------------------------------------- 1 | # Evaluation 2 | 3 | This subdirectory of the PyDough directory deals with the evaluation of PyDough expressions end to end. 4 | 5 | The evaluation module provides functionality to convert unqualified trees into actual evaluated formats, such as SQL text or the actual result of code execution. 6 | 7 | ## Available APIs 8 | 9 | The evaluation module has the following notable APIs available for use: 10 | 11 | - `to_sql`: Converts an unqualified tree to a SQL string. 12 | - `to_df`: Executes an unqualified tree and returns the results as a Pandas DataFrame. 13 | 14 | See [evaluate_unqualified.py](evaluate_unqualified.py) for more details. 15 | -------------------------------------------------------------------------------- /pydough/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module responsible for the actual evaluation of PyDough expressions 3 | end to end. 4 | """ 5 | 6 | __all__ = ["to_df", "to_sql"] 7 | 8 | 9 | from .evaluate_unqualified import to_df, to_sql 10 | -------------------------------------------------------------------------------- /pydough/exploration/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module of PyDough dealing with APIs used for user explanation & exploration 3 | of PyDough metadata and code. 4 | """ 5 | 6 | __all__ = ["explain", "explain_structure", "explain_term"] 7 | 8 | from .explain import explain 9 | from .structure import explain_structure 10 | from .term import explain_term 11 | -------------------------------------------------------------------------------- /pydough/jupyter_extensions/__init__.py: -------------------------------------------------------------------------------- 1 | from .pydough_magic import PyDoughMagic 2 | 3 | 4 | def load_ipython_extension(ipython): 5 | """ 6 | Register the magics with IPython 7 | """ 8 | ipython.register_magics(PyDoughMagic) 9 | -------------------------------------------------------------------------------- /pydough/logger/README.md: -------------------------------------------------------------------------------- 1 | # Logger 2 | 3 | This directory of PyDough deals with logger utilities. 4 | 5 | ## Available APIs 6 | 7 | - `get_logger`: The main function to get a logger as defined in `./logger.py`. You can find more details at [Logging Documentation](../../documentation/usage.md#logging) -------------------------------------------------------------------------------- /pydough/logger/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module of PyDough dealing with logging across the library 3 | """ 4 | 5 | __all__ = ["get_logger"] 6 | 7 | from .logger import get_logger 8 | -------------------------------------------------------------------------------- /pydough/metadata/collections/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Submodule of the PyDough metadata module defining metadata for collections. 3 | """ 4 | 5 | __all__ = ["CollectionMetadata", "SimpleTableMetadata"] 6 | 7 | from .collection_metadata import CollectionMetadata 8 | from .simple_table_metadata import SimpleTableMetadata 9 | -------------------------------------------------------------------------------- /pydough/metadata/graphs/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Submodule of the PyDough metadata module defining metadata for graphs. 3 | """ 4 | 5 | __all__ = ["GraphMetadata"] 6 | 7 | from .graph_metadata import GraphMetadata 8 | -------------------------------------------------------------------------------- /pydough/pydough_operators/type_inference/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Submodule of PyDough operators module dealing with type checking and return 3 | type inference. 4 | """ 5 | 6 | __all__ = [ 7 | "AllowAny", 8 | "ConstantType", 9 | "ExpressionTypeDeducer", 10 | "RequireArgRange", 11 | "RequireArgRange", 12 | "RequireCollection", 13 | "RequireMinArgs", 14 | "RequireNumArgs", 15 | "SelectArgumentType", 16 | "TypeVerifier", 17 | ] 18 | 19 | from .expression_type_deducer import ( 20 | ConstantType, 21 | ExpressionTypeDeducer, 22 | SelectArgumentType, 23 | ) 24 | from .type_verifier import ( 25 | AllowAny, 26 | RequireArgRange, 27 | RequireCollection, 28 | RequireMinArgs, 29 | RequireNumArgs, 30 | TypeVerifier, 31 | ) 32 | -------------------------------------------------------------------------------- /pydough/qdag/errors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definitions of the exception type used in the PyDough QDAG module. 3 | """ 4 | 5 | __all__ = ["PyDoughQDAGException"] 6 | 7 | 8 | class PyDoughQDAGException(Exception): 9 | """Exception raised when there is an error relating to a PyDough QDAG, such 10 | as malformed arguments/structure. 11 | """ 12 | -------------------------------------------------------------------------------- /pydough/sqlglot/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = [ 2 | "SQLGlotRelationalExpressionVisitor", 3 | "SQLGlotRelationalVisitor", 4 | "convert_dialect_to_sqlglot", 5 | "convert_relation_to_sql", 6 | "execute_df", 7 | "find_identifiers", 8 | "find_identifiers_in_list", 9 | "get_glot_name", 10 | "set_glot_alias", 11 | "unwrap_alias", 12 | ] 13 | from .execute_relational import ( 14 | convert_dialect_to_sqlglot, 15 | convert_relation_to_sql, 16 | execute_df, 17 | ) 18 | from .sqlglot_helpers import get_glot_name, set_glot_alias, unwrap_alias 19 | from .sqlglot_identifier_finder import find_identifiers, find_identifiers_in_list 20 | from .sqlglot_relational_expression_visitor import SQLGlotRelationalExpressionVisitor 21 | from .sqlglot_relational_visitor import SQLGlotRelationalVisitor 22 | -------------------------------------------------------------------------------- /pydough/types/boolean_type.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of the PyDough type for booleans. 3 | """ 4 | 5 | __all__ = ["BooleanType"] 6 | 7 | 8 | from .pydough_type import PyDoughType 9 | 10 | 11 | class BooleanType(PyDoughType): 12 | """ 13 | The PyDough type representing true/false data. 14 | """ 15 | 16 | def __init__(self): 17 | pass 18 | 19 | def __repr__(self): 20 | return "BooleanType()" 21 | 22 | @property 23 | def json_string(self) -> str: 24 | return "bool" 25 | 26 | @staticmethod 27 | def parse_from_string(type_string: str) -> PyDoughType | None: 28 | return BooleanType() if type_string == "bool" else None 29 | -------------------------------------------------------------------------------- /pydough/types/date_type.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of the PyDough type for dates. 3 | """ 4 | 5 | __all__ = ["DatetimeType"] 6 | 7 | 8 | from .pydough_type import PyDoughType 9 | 10 | 11 | class DatetimeType(PyDoughType): 12 | """ 13 | The PyDough type representing dates with a year/month/day. 14 | """ 15 | 16 | def __init__(self): 17 | pass 18 | 19 | def __repr__(self): 20 | return "DatetimeType()" 21 | 22 | @property 23 | def json_string(self) -> str: 24 | return "date" 25 | 26 | @staticmethod 27 | def parse_from_string(type_string: str) -> PyDoughType | None: 28 | return DatetimeType() if type_string == "date" else None 29 | -------------------------------------------------------------------------------- /pydough/types/datetime_type.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of the PyDough type for the datetime type. 3 | """ 4 | 5 | __all__ = ["DatetimeType"] 6 | 7 | 8 | from .pydough_type import PyDoughType 9 | 10 | 11 | class DatetimeType(PyDoughType): 12 | """ 13 | The PyDough type for date/timestamp values. 14 | """ 15 | 16 | def __init__(self): 17 | pass 18 | 19 | def __repr__(self): 20 | return "DatetimeType()" 21 | 22 | @property 23 | def json_string(self) -> str: 24 | return "datetime" 25 | 26 | @staticmethod 27 | def parse_from_string(type_string: str) -> PyDoughType | None: 28 | return DatetimeType() if type_string == "datetime" else None 29 | -------------------------------------------------------------------------------- /pydough/types/errors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Error-handling definitions for the types module. 3 | """ 4 | 5 | __all__ = ["PyDoughTypeException"] 6 | 7 | 8 | class PyDoughTypeException(Exception): 9 | """Exception raised when there is an error relating to PyDough types, such 10 | as malformed inputs to a parametrized type or a string that cannot be 11 | parsed into a type. 12 | """ 13 | -------------------------------------------------------------------------------- /pydough/types/numeric_type.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of the PyDough types for numeric types. 3 | """ 4 | 5 | __all__ = ["NumericType"] 6 | 7 | 8 | from .pydough_type import PyDoughType 9 | 10 | 11 | class NumericType(PyDoughType): 12 | """ 13 | The PyDough type superclass for integers. 14 | """ 15 | 16 | def __init__(self): 17 | pass 18 | 19 | def __repr__(self): 20 | return "NumericType()" 21 | 22 | @property 23 | def json_string(self) -> str: 24 | return "numeric" 25 | 26 | @staticmethod 27 | def parse_from_string(type_string: str) -> PyDoughType | None: 28 | return NumericType() if type_string == "numeric" else None 29 | -------------------------------------------------------------------------------- /pydough/types/string_type.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of the PyDough type for a string type. 3 | """ 4 | 5 | __all__ = ["StringType"] 6 | 7 | 8 | from .pydough_type import PyDoughType 9 | 10 | 11 | class StringType(PyDoughType): 12 | """ 13 | The PyDough type representing strings. 14 | """ 15 | 16 | def __init__(self): 17 | pass 18 | 19 | def __repr__(self): 20 | return "StringType()" 21 | 22 | @property 23 | def json_string(self) -> str: 24 | return "string" 25 | 26 | @staticmethod 27 | def parse_from_string(type_string: str) -> PyDoughType | None: 28 | return StringType() if type_string == "string" else None 29 | -------------------------------------------------------------------------------- /pydough/types/unknown_type.py: -------------------------------------------------------------------------------- 1 | """ 2 | Definition of the PyDough type for an unknown type. 3 | """ 4 | 5 | __all__ = ["UnknownType"] 6 | 7 | 8 | from .pydough_type import PyDoughType 9 | 10 | 11 | class UnknownType(PyDoughType): 12 | """ 13 | The PyDough type representing an unknown type. 14 | """ 15 | 16 | def __init__(self): 17 | pass 18 | 19 | def __repr__(self): 20 | return "UnknownType()" 21 | 22 | @property 23 | def json_string(self) -> str: 24 | return "unknown" 25 | 26 | @staticmethod 27 | def parse_from_string(type_string: str) -> PyDoughType | None: 28 | return UnknownType() if type_string == "unknown" else None 29 | -------------------------------------------------------------------------------- /pydough/unqualified/errors.py: -------------------------------------------------------------------------------- 1 | """ 2 | Error handling definitions used for the unqualified module. 3 | """ 4 | 5 | __all__ = ["PyDoughUnqualifiedException"] 6 | 7 | 8 | class PyDoughUnqualifiedException(Exception): 9 | """Exception raised when there is an error relating to the PyDough 10 | unqualified form, such as a Python object that cannot be coerced. 11 | """ 12 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | markers = 3 | execute: marks tests that do runtime execution (deselect with '-m "not execute"') 4 | -------------------------------------------------------------------------------- /tests/gen_data/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | Subdirectory for generating test data. 3 | """ 4 | 5 | __all__ = ["gen_technograph_records"] 6 | 7 | from .gen_technograph import gen_technograph_records 8 | -------------------------------------------------------------------------------- /tests/setup_defog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Script should be run from within the `tests` directory to set up the defog.ai 4 | # database with the tables that are used by the various schemas. The e2e 5 | # defog tests cannot be run unless this commmand has already been used to set 6 | # up the sqlite database. 7 | 8 | set -eo pipefail 9 | 10 | rm -fv defog.db 11 | sqlite3 defog.db < init_defog.sql 12 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/access_partition_child_after_filter.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('part_name', part_name), ('part_type', part_type_3), ('retail_price', retail_price)], orderings=[]) 2 | JOIN(conditions=[t0.part_type == t1.part_type], types=['inner'], columns={'part_name': t1.part_name, 'part_type_3': t1.part_type_3, 'retail_price': t1.retail_price}) 3 | FILTER(condition=agg_0 > 27.5:numeric, columns={'part_type': part_type}) 4 | AGGREGATE(keys={'part_type': part_type}, aggregations={'agg_0': AVG(retail_price)}) 5 | SCAN(table=tpch.PART, columns={'part_type': p_type, 'retail_price': p_retailprice}) 6 | SCAN(table=tpch.PART, columns={'part_name': p_name, 'part_type': p_type, 'part_type_3': p_type, 'retail_price': p_retailprice}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/access_partition_child_backref_calc.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('part_name', name), ('part_type', part_type_1), ('retail_price_versus_avg', retail_price - avg_price)], orderings=[]) 2 | JOIN(conditions=[t0.part_type == t1.part_type], types=['inner'], columns={'avg_price': t0.avg_price, 'name': t1.name, 'part_type_1': t1.part_type, 'retail_price': t1.retail_price}) 3 | PROJECT(columns={'avg_price': agg_0, 'part_type': part_type}) 4 | AGGREGATE(keys={'part_type': part_type}, aggregations={'agg_0': AVG(retail_price)}) 5 | SCAN(table=tpch.PART, columns={'part_type': p_type, 'retail_price': p_retailprice}) 6 | SCAN(table=tpch.PART, columns={'name': p_name, 'part_type': p_type, 'retail_price': p_retailprice}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/access_partition_child_filter_backref_filter.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('part_name', name), ('part_type', part_type_1), ('retail_price', retail_price)], orderings=[]) 2 | FILTER(condition=retail_price < avg_price, columns={'name': name, 'part_type_1': part_type_1, 'retail_price': retail_price}) 3 | JOIN(conditions=[t0.part_type == t1.part_type], types=['inner'], columns={'avg_price': t0.avg_price, 'name': t1.name, 'part_type_1': t1.part_type, 'retail_price': t1.retail_price}) 4 | PROJECT(columns={'avg_price': agg_0, 'part_type': part_type}) 5 | AGGREGATE(keys={'part_type': part_type}, aggregations={'agg_0': AVG(retail_price)}) 6 | SCAN(table=tpch.PART, columns={'part_type': p_type, 'retail_price': p_retailprice}) 7 | SCAN(table=tpch.PART, columns={'name': p_name, 'part_type': p_type, 'retail_price': p_retailprice}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/agg_max_ranking.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', name), ('highest_rank', agg_0)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['left'], columns={'agg_0': t1.agg_0, 'name': t0.name}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name}) 4 | AGGREGATE(keys={'nation_key': nation_key}, aggregations={'agg_0': MAX(cust_rank)}) 5 | PROJECT(columns={'cust_rank': RANKING(args=[], partition=[], order=[(account_balance):desc_first], allow_ties=True), 'nation_key': nation_key}) 6 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'nation_key': c_nationkey}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/agg_orders_by_year_month_basic.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('year', year), ('month', month), ('total_orders', DEFAULT_TO(agg_0, 0:numeric))], orderings=[]) 2 | AGGREGATE(keys={'month': month, 'year': year}, aggregations={'agg_0': COUNT()}) 3 | PROJECT(columns={'month': MONTH(order_date), 'year': YEAR(order_date)}) 4 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/agg_partition.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('best_year', agg_0)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': MAX(n_orders)}) 3 | PROJECT(columns={'n_orders': DEFAULT_TO(agg_0, 0:numeric)}) 4 | AGGREGATE(keys={'year': year}, aggregations={'agg_0': COUNT()}) 5 | PROJECT(columns={'year': YEAR(order_date)}) 6 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/agg_parts_by_type_simple.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('part_type', part_type), ('num_parts', DEFAULT_TO(agg_1, 0:numeric)), ('avg_price', agg_0)], orderings=[]) 2 | AGGREGATE(keys={'part_type': part_type}, aggregations={'agg_0': AVG(retail_price), 'agg_1': COUNT()}) 3 | SCAN(table=tpch.PART, columns={'part_type': p_type, 'retail_price': p_retailprice}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/aggregate_anti.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('num_10parts', DEFAULT_TO(NULL_2, 0:numeric)), ('avg_price_of_10parts', NULL_2), ('sum_price_of_10parts', DEFAULT_TO(NULL_2, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.supplier_key], types=['anti'], columns={'NULL_2': None:unknown, 'name': t0.name}) 3 | SCAN(table=tpch.SUPPLIER, columns={'key': s_suppkey, 'name': s_name}) 4 | JOIN(conditions=[t0.part_key == t1.key], types=['inner'], columns={'supplier_key': t0.supplier_key}) 5 | SCAN(table=tpch.PARTSUPP, columns={'part_key': ps_partkey, 'supplier_key': ps_suppkey}) 6 | FILTER(condition=size == 10:numeric, columns={'key': key}) 7 | SCAN(table=tpch.PART, columns={'key': p_partkey, 'size': p_size}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/aggregate_on_function_call.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', key), ('avg_consumer_value', agg_0)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['left'], columns={'agg_0': t1.agg_0, 'key': t0.key}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey}) 4 | AGGREGATE(keys={'nation_key': nation_key}, aggregations={'agg_0': MAX(expr_1)}) 5 | PROJECT(columns={'expr_1': IFF(account_balance < 0.0:numeric, 0.0:numeric, account_balance), 'nation_key': nation_key}) 6 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'nation_key': c_nationkey}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/anti_aggregate.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('num_10parts', DEFAULT_TO(NULL_2, 0:numeric)), ('avg_price_of_10parts', NULL_2), ('sum_price_of_10parts', DEFAULT_TO(NULL_2, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.supplier_key], types=['anti'], columns={'NULL_2': None:unknown, 'name': t0.name}) 3 | SCAN(table=tpch.SUPPLIER, columns={'key': s_suppkey, 'name': s_name}) 4 | JOIN(conditions=[t0.part_key == t1.key], types=['inner'], columns={'supplier_key': t0.supplier_key}) 5 | SCAN(table=tpch.PARTSUPP, columns={'part_key': ps_partkey, 'supplier_key': ps_suppkey}) 6 | FILTER(condition=size == 10:numeric, columns={'key': key}) 7 | SCAN(table=tpch.PART, columns={'key': p_partkey, 'size': p_size}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/anti_aggregate_alternate.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('num_10parts', DEFAULT_TO(NULL_2, 0:numeric)), ('avg_price_of_10parts', DEFAULT_TO(NULL_2, 0:numeric)), ('sum_price_of_10parts', NULL_2)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.supplier_key], types=['anti'], columns={'NULL_2': None:unknown, 'name': t0.name}) 3 | SCAN(table=tpch.SUPPLIER, columns={'key': s_suppkey, 'name': s_name}) 4 | JOIN(conditions=[t0.part_key == t1.key], types=['inner'], columns={'supplier_key': t0.supplier_key}) 5 | SCAN(table=tpch.PARTSUPP, columns={'part_key': ps_partkey, 'supplier_key': ps_suppkey}) 6 | FILTER(condition=size == 10:numeric, columns={'key': key}) 7 | SCAN(table=tpch.PART, columns={'key': p_partkey, 'size': p_size}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/anti_singular.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('region_name', NULL_1)], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['anti'], columns={'NULL_1': None:unknown, 'name': t0.name}) 3 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 4 | FILTER(condition=name != 'ASIA':string, columns={'key': key}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/asian_nations.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('region_key', region_key), ('name', name), ('comment', comment)], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'comment': t0.comment, 'key': t0.key, 'name': t0.name, 'region_key': t0.region_key}) 3 | SCAN(table=tpch.NATION, columns={'comment': n_comment, 'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 4 | FILTER(condition=name == 'ASIA':string, columns={'key': key}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/avg_gap_prev_urgent_same_clerk.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('avg_delta', agg_0)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': AVG(delta)}) 3 | PROJECT(columns={'delta': DATEDIFF('days':string, PREV(args=[order_date], partition=[clerk], order=[(order_date):asc_last]), order_date)}) 4 | FILTER(condition=order_priority == '1-URGENT':string, columns={'clerk': clerk, 'order_date': order_date}) 5 | SCAN(table=tpch.ORDERS, columns={'clerk': o_clerk, 'order_date': o_orderdate, 'order_priority': o_orderpriority}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_10.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('rname', NULL_2)], orderings=[(name):asc_first]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['anti'], columns={'NULL_2': None:unknown, 'name': t0.name}, correl_name='corr1') 3 | SCAN(table=tpch.NATION, columns={'name': n_name, 'nation_name': n_name, 'region_key': n_regionkey}) 4 | FILTER(condition=SLICE(name, None:unknown, 1:numeric, None:unknown) == SLICE(corr1.nation_name, None:unknown, 1:numeric, None:unknown), columns={'key': key}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_11.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('brand', brand)], orderings=[(brand):asc_first]) 2 | JOIN(conditions=[t0.brand == t1.brand], types=['semi'], columns={'brand': t0.brand}, correl_name='corr1') 3 | PROJECT(columns={'avg_price': agg_0, 'brand': brand}) 4 | AGGREGATE(keys={'brand': brand}, aggregations={'agg_0': AVG(retail_price)}) 5 | SCAN(table=tpch.PART, columns={'brand': p_brand, 'retail_price': p_retailprice}) 6 | FILTER(condition=retail_price > 1.4:numeric * corr1.avg_price, columns={'brand': brand}) 7 | SCAN(table=tpch.PART, columns={'brand': p_brand, 'retail_price': p_retailprice}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_17.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('fullname', fname)], orderings=[(fname):asc_first]) 2 | PROJECT(columns={'fname': JOIN_STRINGS('-':string, LOWER(name_3), lname)}) 3 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'lname': t0.lname, 'name_3': t1.name}) 4 | PROJECT(columns={'lname': LOWER(name), 'region_key': region_key}) 5 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 6 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_33.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('n', agg_1)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_1': COUNT()}) 3 | FILTER(condition=MONTH(order_date) == MONTH(first_order_date) & YEAR(order_date) == YEAR(first_order_date), columns={}) 4 | JOIN(conditions=[True:bool], types=['inner'], columns={'first_order_date': t0.first_order_date, 'order_date': t1.order_date}) 5 | PROJECT(columns={'first_order_date': agg_0}) 6 | AGGREGATE(keys={}, aggregations={'agg_0': MIN(order_date)}) 7 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 8 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 9 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_4.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name)], orderings=[(name):asc_first]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['anti'], columns={'name': t0.name}, correl_name='corr1') 3 | JOIN(conditions=[True:bool], types=['inner'], columns={'key': t1.key, 'name': t1.name, 'smallest_bal': t0.smallest_bal}) 4 | PROJECT(columns={'smallest_bal': agg_0}) 5 | AGGREGATE(keys={}, aggregations={'agg_0': MIN(account_balance)}) 6 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal}) 7 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name}) 8 | FILTER(condition=account_balance <= corr1.smallest_bal + 5.0:numeric, columns={'nation_key': nation_key}) 9 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'nation_key': c_nationkey}) 10 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_6.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', agg_3), ('n_prefix_nations', agg_0)], orderings=[]) 2 | AGGREGATE(keys={'key': key}, aggregations={'agg_0': COUNT(), 'agg_3': ANYTHING(name)}) 3 | FILTER(condition=SLICE(name_3, None:unknown, 1:numeric, None:unknown) == SLICE(region_name, None:unknown, 1:numeric, None:unknown), columns={'key': key, 'name': name}) 4 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'key': t0.key, 'name': t0.name, 'name_3': t1.name, 'region_name': t0.region_name}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name, 'region_name': r_name}) 6 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_7.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('n_prefix_nations', DEFAULT_TO(NULL_2, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['anti'], columns={'NULL_2': None:unknown, 'name': t0.name}, correl_name='corr1') 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name, 'region_name': r_name}) 4 | FILTER(condition=SLICE(name, None:unknown, 1:numeric, None:unknown) == SLICE(corr1.region_name, None:unknown, 1:numeric, None:unknown), columns={'region_key': region_key}) 5 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_8.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('rname', name_3)], orderings=[(name):asc_first]) 2 | JOIN(conditions=[t0.key == t1.key], types=['left'], columns={'name': t0.name, 'name_3': t1.name_3}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name}) 4 | FILTER(condition=SLICE(name_3, None:unknown, 1:numeric, None:unknown) == SLICE(nation_name, None:unknown, 1:numeric, None:unknown), columns={'key': key, 'name_3': name_3}) 5 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'key': t0.key, 'name_3': t1.name, 'nation_name': t0.nation_name}) 6 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'nation_name': n_name, 'region_key': n_regionkey}) 7 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/correl_9.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('rname', name_3)], orderings=[(name):asc_first]) 2 | FILTER(condition=SLICE(name_3, None:unknown, 1:numeric, None:unknown) == SLICE(nation_name, None:unknown, 1:numeric, None:unknown), columns={'name': name, 'name_3': name_3}) 3 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'name': t0.name, 'name_3': t1.name, 'nation_name': t0.nation_name}) 4 | SCAN(table=tpch.NATION, columns={'name': n_name, 'nation_name': n_name, 'region_key': n_regionkey}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/count_at_most_100_suppliers_per_nation.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('n_top_suppliers', DEFAULT_TO(agg_0, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['left'], columns={'agg_0': t1.agg_0, 'name': t0.name}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name}) 4 | AGGREGATE(keys={'nation_key': nation_key}, aggregations={'agg_0': COUNT(key)}) 5 | LIMIT(limit=Literal(value=100, type=NumericType()), columns={'key': key, 'nation_key': nation_key}, orderings=[(account_balance):asc_last]) 6 | SCAN(table=tpch.SUPPLIER, columns={'account_balance': s_acctbal, 'key': s_suppkey, 'nation_key': s_nationkey}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/count_single_subcollection.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', key), ('num_customers', DEFAULT_TO(agg_0, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['left'], columns={'agg_0': t1.agg_0, 'key': t0.key}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey}) 4 | AGGREGATE(keys={'nation_key': nation_key}, aggregations={'agg_0': COUNT()}) 5 | SCAN(table=tpch.CUSTOMER, columns={'nation_key': c_nationkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/customers_sum_line_price.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('okey', key), ('lsum', DEFAULT_TO(agg_0, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.customer_key], types=['left'], columns={'agg_0': t1.agg_0, 'key': t0.key}) 3 | SCAN(table=tpch.CUSTOMER, columns={'key': c_custkey}) 4 | AGGREGATE(keys={'customer_key': customer_key}, aggregations={'agg_0': SUM(agg_0)}) 5 | JOIN(conditions=[t0.key == t1.order_key], types=['inner'], columns={'agg_0': t1.agg_0, 'customer_key': t0.customer_key}) 6 | SCAN(table=tpch.ORDERS, columns={'customer_key': o_custkey, 'key': o_orderkey}) 7 | AGGREGATE(keys={'order_key': order_key}, aggregations={'agg_0': SUM(extended_price)}) 8 | SCAN(table=tpch.LINEITEM, columns={'extended_price': l_extendedprice, 'order_key': l_orderkey}) 9 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/datetime_current.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('d1', DATETIME('now':string, 'start of year':string, '5 months':string, '-1 DAY':string)), ('d2', DATETIME('current_date':string, 'start of mm':string, '+24 hours':string)), ('d3', DATETIME(' Current Timestamp ':string, 'start of day':string, '+12 hours':string, '-150 minutes':string, '+2 s':string))], orderings=[]) 2 | EMPTYSINGLETON() 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/double_partition.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('year', year), ('best_month', agg_0)], orderings=[]) 2 | AGGREGATE(keys={'year': year}, aggregations={'agg_0': MAX(n_orders)}) 3 | PROJECT(columns={'n_orders': DEFAULT_TO(agg_0, 0:numeric), 'year': year}) 4 | AGGREGATE(keys={'month': month, 'year': year}, aggregations={'agg_0': COUNT()}) 5 | PROJECT(columns={'month': MONTH(order_date), 'year': YEAR(order_date)}) 6 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/epoch_first_event_per_era.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('era_name', name), ('event_name', name_1)], orderings=[(start_year):asc_first]) 2 | FILTER(condition=RANKING(args=[], partition=[name], order=[(date_time):asc_last], allow_ties=False) == 1:numeric, columns={'name': name, 'name_1': name_1, 'start_year': start_year}) 3 | JOIN(conditions=[t0.start_year <= YEAR(t1.date_time) & YEAR(t1.date_time) < t0.end_year], types=['inner'], columns={'date_time': t1.date_time, 'name': t0.name, 'name_1': t1.name, 'start_year': t0.start_year}) 4 | SCAN(table=ERAS, columns={'end_year': er_end_year, 'name': er_name, 'start_year': er_start_year}) 5 | SCAN(table=EVENTS, columns={'date_time': ev_dt, 'name': ev_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/exponentiation.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('low_square', low_square), ('low_sqrt', low_sqrt), ('low_cbrt', low_cbrt)], orderings=[(low_square):asc_first]) 2 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'low_cbrt': low_cbrt, 'low_sqrt': low_sqrt, 'low_square': low_square}, orderings=[(low_square):asc_first]) 3 | PROJECT(columns={'low_cbrt': POWER(low, 0.3333333333333333:numeric), 'low_sqrt': SQRT(low), 'low_square': low ** 2:numeric}) 4 | SCAN(table=main.sbDailyPrice, columns={'low': sbDpLow}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/find.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('idx_Alex', FIND(name, 'Alex':string)), ('idx_Rodriguez', FIND(name, 'Rodriguez':string)), ('idx_bob', FIND(name, 'bob':string)), ('idx_e', FIND(name, 'e':string)), ('idx_space', FIND(name, ' ':string)), ('idx_of_R', FIND(name, 'R':string)), ('idx_of_Alex_Rodriguez', FIND(name, 'Alex Rodriguez':string))], orderings=[]) 2 | FILTER(condition=name == 'Alex Rodriguez':string, columns={'name': name}) 3 | SCAN(table=main.sbCustomer, columns={'name': sbCustName}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/first_order_in_year.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('order_date', order_date), ('key', key)], orderings=[(order_date):asc_first]) 2 | FILTER(condition=ABSENT(PREV(args=[order_date], partition=[], order=[(order_date):asc_last, (key):asc_last])) | YEAR(PREV(args=[order_date], partition=[], order=[(order_date):asc_last, (key):asc_last])) != YEAR(order_date), columns={'key': key, 'order_date': order_date}) 3 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey, 'order_date': o_orderdate}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_acctbal_breakdown.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('n_red_acctbal', agg_4), ('n_black_acctbal', agg_3), ('median_red_acctbal', agg_2), ('median_black_acctbal', agg_0), ('median_overall_acctbal', agg_1)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': MEDIAN(non_negative_acctbal), 'agg_1': MEDIAN(account_balance), 'agg_2': MEDIAN(negative_acctbal), 'agg_3': COUNT(non_negative_acctbal), 'agg_4': COUNT(negative_acctbal)}) 3 | PROJECT(columns={'account_balance': account_balance, 'negative_acctbal': KEEP_IF(account_balance, account_balance < 0:numeric), 'non_negative_acctbal': KEEP_IF(account_balance, account_balance >= 0:numeric)}) 4 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_aggfunc_backref.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('part_name', name), ('is_above_avg', retail_price > avg_price)], orderings=[]) 2 | JOIN(conditions=[True:bool], types=['inner'], columns={'avg_price': t0.avg_price, 'name': t1.name, 'retail_price': t1.retail_price}) 3 | PROJECT(columns={'avg_price': agg_0}) 4 | AGGREGATE(keys={}, aggregations={'agg_0': AVG(retail_price)}) 5 | SCAN(table=tpch.PART, columns={'retail_price': p_retailprice}) 6 | SCAN(table=tpch.PART, columns={'name': p_name, 'retail_price': p_retailprice}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_aggfuncs.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('total_bal', DEFAULT_TO(agg_5, 0:numeric)), ('num_bal', agg_3), ('avg_bal', agg_0), ('min_bal', agg_2), ('max_bal', agg_1), ('num_cust', agg_4)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': AVG(account_balance), 'agg_1': MAX(account_balance), 'agg_2': MIN(account_balance), 'agg_3': COUNT(account_balance), 'agg_4': COUNT(), 'agg_5': SUM(account_balance)}) 3 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_aggfuncs_multiple_children.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('num_cust', agg_0), ('num_supp', agg_2), ('num_part', agg_1)], orderings=[]) 2 | JOIN(conditions=[True:bool], types=['left'], columns={'agg_0': t0.agg_0, 'agg_1': t1.agg_1, 'agg_2': t0.agg_2}) 3 | JOIN(conditions=[True:bool], types=['left'], columns={'agg_0': t0.agg_0, 'agg_2': t1.agg_2}) 4 | AGGREGATE(keys={}, aggregations={'agg_0': COUNT()}) 5 | SCAN(table=tpch.CUSTOMER, columns={}) 6 | AGGREGATE(keys={}, aggregations={'agg_2': COUNT()}) 7 | SCAN(table=tpch.SUPPLIER, columns={}) 8 | AGGREGATE(keys={}, aggregations={'agg_1': COUNT()}) 9 | SCAN(table=tpch.PART, columns={}) 10 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_calc_backref.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('part_name', name), ('is_above_cutoff', retail_price > a), ('is_nickel', CONTAINS(part_type, b))], orderings=[]) 2 | JOIN(conditions=[True:bool], types=['inner'], columns={'a': t0.a, 'b': t0.b, 'name': t1.name, 'part_type': t1.part_type, 'retail_price': t1.retail_price}) 3 | PROJECT(columns={'a': 28.15:numeric, 'b': 'NICKEL':string}) 4 | EMPTYSINGLETON() 5 | SCAN(table=tpch.PART, columns={'name': p_name, 'part_type': p_type, 'retail_price': p_retailprice}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_calc_multiple.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('a', 0:numeric), ('b', 'X':string), ('c', 3.14:numeric), ('d', True:bool)], orderings=[]) 2 | EMPTYSINGLETON() 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/global_calc_simple.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('a', 0:numeric), ('b', 'X':string), ('c', 3.14:numeric), ('d', True:bool)], orderings=[]) 2 | EMPTYSINGLETON() 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/join_asia_region_nations.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key_6), ('region_key', region_key), ('name', name_7), ('comment', comment_5)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'comment_5': t1.comment_5, 'key_6': t1.key_6, 'name_7': t1.name_7, 'region_key': t1.region_key}) 3 | FILTER(condition=name == 'ASIA':string, columns={'key': key}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 5 | SCAN(table=tpch.NATION, columns={'comment_5': n_comment, 'key_6': n_nationkey, 'name_7': n_name, 'region_key': n_regionkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/join_order_by.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', name), ('nation_name', name_3)], orderings=[(name_3):desc_last]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'name': t0.name, 'name_3': t1.name_3}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 4 | SCAN(table=tpch.NATION, columns={'name_3': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/join_order_by_back_reference.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', region_name), ('nation_name', nation_name)], orderings=[(name):desc_last]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'name': t0.name, 'nation_name': t1.nation_name, 'region_name': t0.region_name}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name, 'region_name': r_name}) 4 | SCAN(table=tpch.NATION, columns={'nation_name': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/join_order_by_pruned_back_reference.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', nation_name)], orderings=[(name):desc_last]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'name': t0.name, 'nation_name': t1.nation_name}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 4 | SCAN(table=tpch.NATION, columns={'nation_name': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/join_region_nations.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key_6), ('region_key', region_key), ('name', name_7), ('comment', comment_5)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'comment_5': t1.comment_5, 'key_6': t1.key_6, 'name_7': t1.name_7, 'region_key': t1.region_key}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey}) 4 | SCAN(table=tpch.NATION, columns={'comment_5': n_comment, 'key_6': n_nationkey, 'name_7': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/join_topk.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', name), ('nation_name', name_3)], orderings=[(name_3):asc_last]) 2 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'name': name, 'name_3': name_3}, orderings=[(name_3):asc_last]) 3 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'name': t0.name, 'name_3': t1.name_3}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 5 | SCAN(table=tpch.NATION, columns={'name_3': n_name, 'region_key': n_regionkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/minutes_seconds_datediff.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('x', x), ('y', y), ('minutes_diff', minutes_diff), ('seconds_diff', seconds_diff)], orderings=[(x):desc_last]) 2 | LIMIT(limit=Literal(value=30, type=NumericType()), columns={'minutes_diff': minutes_diff, 'seconds_diff': seconds_diff, 'x': x, 'y': y}, orderings=[(x):desc_last]) 3 | PROJECT(columns={'minutes_diff': DATEDIFF('m':string, date_time, datetime.datetime(2023, 4, 3, 13, 16, 30):datetime), 'seconds_diff': DATEDIFF('s':string, date_time, datetime.datetime(2023, 4, 3, 13, 16, 30):datetime), 'x': date_time, 'y': datetime.datetime(2023, 4, 3, 13, 16, 30):datetime}) 4 | FILTER(condition=YEAR(date_time) <= 2024:numeric, columns={'date_time': date_time}) 5 | SCAN(table=main.sbTransaction, columns={'date_time': sbTxDateTime}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/multi_partition_access_1.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('symbol', symbol)], orderings=[(symbol):asc_first]) 2 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'symbol': symbol}, orderings=[(symbol):asc_first]) 3 | SCAN(table=main.sbTicker, columns={'symbol': sbTickerSymbol}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/n_orders_first_day.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('n_orders', agg_0)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': COUNT()}) 3 | FILTER(condition=RANKING(args=[], partition=[], order=[(order_date):asc_last], allow_ties=True) == 1:numeric, columns={}) 4 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/nation_name_contains_region_name.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key_2), ('region_key', region_key), ('name', name_3), ('comment', comment_1)], orderings=[]) 2 | FILTER(condition=CONTAINS(name_3, name), columns={'comment_1': comment_1, 'key_2': key_2, 'name_3': name_3, 'region_key': region_key}) 3 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'comment_1': t1.comment, 'key_2': t1.key, 'name': t0.name, 'name_3': t1.name, 'region_key': t1.region_key}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 5 | SCAN(table=tpch.NATION, columns={'comment': n_comment, 'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/nations_access_region.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', name), ('region_name', name_3)], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['left'], columns={'name': t0.name, 'name_3': t1.name}) 3 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/nations_order_by_num_suppliers.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('region_key', region_key), ('name', name), ('comment', comment)], orderings=[(ordering_0):asc_last]) 2 | PROJECT(columns={'comment': comment, 'key': key, 'name': name, 'ordering_0': DEFAULT_TO(agg_1, 0:numeric), 'region_key': region_key}) 3 | JOIN(conditions=[t0.key == t1.nation_key], types=['left'], columns={'agg_1': t1.agg_1, 'comment': t0.comment, 'key': t0.key, 'name': t0.name, 'region_key': t0.region_key}) 4 | SCAN(table=tpch.NATION, columns={'comment': n_comment, 'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 5 | AGGREGATE(keys={'nation_key': nation_key}, aggregations={'agg_1': COUNT(key)}) 6 | SCAN(table=tpch.SUPPLIER, columns={'key': s_suppkey, 'nation_key': s_nationkey}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/nations_region_order_by_name.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('region_key', region_key), ('name', name), ('comment', comment)], orderings=[(name):asc_last, (name_3):asc_last]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['left'], columns={'comment': t0.comment, 'key': t0.key, 'name': t0.name, 'name_3': t1.name, 'region_key': t0.region_key}) 3 | SCAN(table=tpch.NATION, columns={'comment': n_comment, 'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/odate_and_rdate_avggap.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('avg_gap', agg_0)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': AVG(day_gap)}) 3 | PROJECT(columns={'day_gap': DATEDIFF('days':string, order_date, SMALLEST(commit_date, receipt_date))}) 4 | JOIN(conditions=[t0.order_key == t1.key], types=['inner'], columns={'commit_date': t0.commit_date, 'order_date': t1.order_date, 'receipt_date': t0.receipt_date}) 5 | FILTER(condition=ship_mode == 'RAIL':string, columns={'commit_date': commit_date, 'order_key': order_key, 'receipt_date': receipt_date}) 6 | SCAN(table=tpch.LINEITEM, columns={'commit_date': l_commitdate, 'order_key': l_orderkey, 'receipt_date': l_receiptdate, 'ship_mode': l_shipmode}) 7 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey, 'order_date': o_orderdate}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/order_by_before_join.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key_6), ('region_key', region_key), ('name', name_7), ('comment', comment_5)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'comment_5': t1.comment_5, 'key_6': t1.key_6, 'name_7': t1.name_7, 'region_key': t1.region_key}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey}) 4 | SCAN(table=tpch.NATION, columns={'comment_5': n_comment, 'key_6': n_nationkey, 'name_7': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/order_by_expression.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[(ordering_1):asc_first]) 2 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'comment': comment, 'key': key, 'name': name, 'ordering_1': ordering_1}, orderings=[(ordering_1):asc_first]) 3 | PROJECT(columns={'comment': comment, 'key': key, 'name': name, 'ordering_1': LENGTH(name)}) 4 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/order_info_per_priority.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('order_priority', order_priority), ('order_key', key), ('order_total_price', total_price)], orderings=[(order_priority):asc_first]) 2 | FILTER(condition=RANKING(args=[], partition=[order_priority], order=[(total_price):desc_first]) == 1:numeric, columns={'key': key, 'order_priority': order_priority, 'total_price': total_price}) 3 | FILTER(condition=YEAR(order_date) == 1992:numeric, columns={'key': key, 'order_priority': order_priority, 'total_price': total_price}) 4 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey, 'order_date': o_orderdate, 'order_priority': o_orderpriority, 'total_price': o_totalprice}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/ordered_asian_nations.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('region_key', region_key), ('name', name), ('comment', comment)], orderings=[(name):asc_last]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'comment': t0.comment, 'key': t0.key, 'name': t0.name, 'region_key': t0.region_key}) 3 | SCAN(table=tpch.NATION, columns={'comment': n_comment, 'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 4 | FILTER(condition=name == 'ASIA':string, columns={'key': key}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/orders_sum_line_price.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('okey', key), ('lsum', DEFAULT_TO(agg_0, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.order_key], types=['left'], columns={'agg_0': t1.agg_0, 'key': t0.key}) 3 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey}) 4 | AGGREGATE(keys={'order_key': order_key}, aggregations={'agg_0': SUM(extended_price)}) 5 | SCAN(table=tpch.LINEITEM, columns={'extended_price': l_extendedprice, 'order_key': l_orderkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/orders_sum_vs_count_line_price.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('okey', key), ('lavg', DEFAULT_TO(agg_0, 0:numeric) / DEFAULT_TO(agg_1, 0:numeric))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.order_key], types=['left'], columns={'agg_0': t1.agg_0, 'agg_1': t1.agg_1, 'key': t0.key}) 3 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey}) 4 | AGGREGATE(keys={'order_key': order_key}, aggregations={'agg_0': SUM(extended_price), 'agg_1': COUNT(extended_price)}) 5 | SCAN(table=tpch.LINEITEM, columns={'extended_price': l_extendedprice, 'order_key': l_orderkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/percentile_nations.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('p1', PERCENTILE(args=[], partition=[], order=[(name):asc_last], n_buckets=5)), ('p2', PERCENTILE(args=[], partition=[], order=[(name):asc_last], n_buckets=5))], orderings=[]) 2 | SCAN(table=tpch.NATION, columns={'name': n_name}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/prev_next_regions.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('two_preceding', two_preceding), ('one_preceding', one_preceding), ('current', current), ('one_following', one_following), ('two_following', two_following)], orderings=[(current):asc_first]) 2 | PROJECT(columns={'current': name, 'one_following': NEXT(args=[name], partition=[], order=[(name):asc_last]), 'one_preceding': PREV(args=[name], partition=[], order=[(name):asc_last]), 'two_following': PREV(args=[name], partition=[], order=[(name):asc_last], n=-2), 'two_preceding': PREV(args=[name], partition=[], order=[(name):asc_last], n=2)}) 3 | SCAN(table=tpch.REGION, columns={'name': r_name}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_customers.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('cust_rank', RANKING(args=[], partition=[], order=[(account_balance):desc_first]))], orderings=[]) 2 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'name': c_name}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_customers_per_nation.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', name), ('name', name_3), ('cust_rank', RANKING(args=[], partition=[key], order=[(account_balance):desc_first], allow_ties=True))], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['inner'], columns={'account_balance': t1.account_balance, 'key': t0.key, 'name': t0.name, 'name_3': t1.name}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name}) 4 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'name': c_name, 'nation_key': c_nationkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_customers_per_region.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', name_3), ('name', name_6), ('cust_rank', RANKING(args=[], partition=[key], order=[(account_balance):desc_first], allow_ties=True, dense=True))], orderings=[]) 2 | JOIN(conditions=[t0.key_2 == t1.nation_key], types=['inner'], columns={'account_balance': t1.account_balance, 'key': t0.key, 'name_3': t0.name_3, 'name_6': t1.name}) 3 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'key': t0.key, 'key_2': t1.key, 'name_3': t1.name}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey}) 5 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 6 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'name': c_name, 'nation_key': c_nationkey}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_nations_by_region.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('rank', RANKING(args=[], partition=[], order=[(name_3):asc_last], allow_ties=True))], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['left'], columns={'name': t0.name, 'name_3': t1.name}) 3 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 4 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_with_filters_a.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('n', n), ('r', r)], orderings=[]) 2 | FILTER(condition=r <= 30:numeric & ENDSWITH(name, '0':string), columns={'n': n, 'r': r}) 3 | PROJECT(columns={'n': name, 'name': name, 'r': RANKING(args=[], partition=[], order=[(account_balance):desc_first])}) 4 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'name': c_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_with_filters_b.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('n', n), ('r', r)], orderings=[]) 2 | FILTER(condition=r <= 30:numeric & ENDSWITH(name, '0':string), columns={'n': n, 'r': r}) 3 | PROJECT(columns={'n': name, 'name': name, 'r': RANKING(args=[], partition=[], order=[(account_balance):desc_first])}) 4 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'name': c_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/rank_with_filters_c.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('pname', name), ('psize', size_3)], orderings=[]) 2 | FILTER(condition=RANKING(args=[], partition=[size], order=[(retail_price):desc_first]) == 1:numeric, columns={'name': name, 'size_3': size_3}) 3 | JOIN(conditions=[t0.size == t1.size], types=['inner'], columns={'name': t1.name, 'retail_price': t1.retail_price, 'size': t0.size, 'size_3': t1.size_3}) 4 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'size': size}, orderings=[(size):desc_last]) 5 | AGGREGATE(keys={'size': size}, aggregations={}) 6 | SCAN(table=tpch.PART, columns={'size': p_size}) 7 | SCAN(table=tpch.PART, columns={'name': p_name, 'retail_price': p_retailprice, 'size': p_size, 'size_3': p_size}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/region_nations_backref.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', region_name), ('nation_name', nation_name)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'nation_name': t1.nation_name, 'region_name': t0.region_name}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'region_name': r_name}) 4 | SCAN(table=tpch.NATION, columns={'nation_name': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/replace_order_by.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', name), ('nation_name', name_3)], orderings=[(name):desc_last]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['inner'], columns={'name': t0.name, 'name_3': t1.name_3}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 4 | SCAN(table=tpch.NATION, columns={'name_3': n_name, 'region_key': n_regionkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/scan_calc.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', name), ('magic_word', 'foo':string)], orderings=[]) 2 | SCAN(table=tpch.REGION, columns={'name': r_name}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/scan_calc_calc.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('fizz', name), ('buzz', key)], orderings=[]) 2 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/scan_customer_call_functions.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('lname', LOWER(name)), ('country_code', SLICE(phone, 0:numeric, 3:numeric, 1:numeric)), ('adjusted_account_balance', IFF(account_balance < 0:numeric, 0:numeric, account_balance)), ('is_named_john', LOWER(name) < 'john':string)], orderings=[]) 2 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal, 'name': c_name, 'phone': c_phone}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/scan_nations.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('region_key', region_key), ('name', name), ('comment', comment)], orderings=[]) 2 | SCAN(table=tpch.NATION, columns={'comment': n_comment, 'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/scan_regions.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[]) 2 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/semi_singular.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('region_name', region_name)], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'name': t0.name, 'region_name': t1.region_name}) 3 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 4 | PROJECT(columns={'key': key, 'region_name': name}) 5 | FILTER(condition=name != 'ASIA':string, columns={'key': key, 'name': name}) 6 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/sign.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('high', high), ('high_neg', high_neg), ('high_zero', high_zero), ('sign_high', sign_high), ('sign_high_neg', sign_high_neg), ('sign_high_zero', sign_high_zero)], orderings=[(high):asc_first]) 2 | PROJECT(columns={'high': high, 'high_neg': high_neg, 'high_zero': high_zero, 'sign_high': SIGN(high), 'sign_high_neg': SIGN(high_neg), 'sign_high_zero': SIGN(high_zero)}) 3 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'high': high, 'high_neg': high_neg, 'high_zero': high_zero}, orderings=[(high):asc_first]) 4 | PROJECT(columns={'high': high, 'high_neg': -1:numeric * high, 'high_zero': 0:numeric * high}) 5 | SCAN(table=main.sbDailyPrice, columns={'high': sbDpHigh}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_anti_1.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.customer_key], types=['anti'], columns={'name': t0.name}) 3 | SCAN(table=tpch.CUSTOMER, columns={'key': c_custkey, 'name': c_name}) 4 | SCAN(table=tpch.ORDERS, columns={'customer_key': o_custkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_anti_2.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.supplier_key], types=['anti'], columns={'name': t0.name}) 3 | SCAN(table=tpch.SUPPLIER, columns={'key': s_suppkey, 'name': s_name}) 4 | JOIN(conditions=[t0.part_key == t1.key], types=['inner'], columns={'supplier_key': t0.supplier_key}) 5 | SCAN(table=tpch.PARTSUPP, columns={'part_key': ps_partkey, 'supplier_key': ps_suppkey}) 6 | FILTER(condition=size < 10:numeric, columns={'key': key}) 7 | SCAN(table=tpch.PART, columns={'key': p_partkey, 'size': p_size}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_filter_top_five.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key)], orderings=[(key):desc_last]) 2 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'key': key}, orderings=[(key):desc_last]) 3 | FILTER(condition=total_price < 1000.0:numeric, columns={'key': key}) 4 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey, 'total_price': o_totalprice}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_int_float_string_cast.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('i1', INTEGER(1:numeric)), ('i2', INTEGER(2.2:numeric)), ('i3', INTEGER('3':string)), ('i4', INTEGER('4.3':string)), ('i5', INTEGER('-5.888':string)), ('i6', INTEGER(-6.0:numeric)), ('f1', FLOAT(1.0:numeric)), ('f2', FLOAT(2.2:numeric)), ('f3', FLOAT('3':string)), ('f4', FLOAT('4.3':string)), ('f5', FLOAT('-5.888':string)), ('f6', FLOAT(-6.0:numeric)), ('f7', FLOAT(0.0:numeric)), ('s1', STRING(1:numeric)), ('s2', STRING(2.2:numeric)), ('s3', STRING('3':string)), ('s4', STRING('4.3':string)), ('s5', STRING('-5.888':string)), ('s6', STRING(-6.0:numeric)), ('s7', STRING(0.0:numeric)), ('s8', STRING('0.0':string)), ('s9', STRING('abc def':string))], orderings=[]) 2 | EMPTYSINGLETON() 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_order_by.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[(name):asc_last]) 2 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 3 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_scan_top_five.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key)], orderings=[(key):asc_first]) 2 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'key': key}, orderings=[(key):asc_first]) 3 | SCAN(table=tpch.ORDERS, columns={'key': o_orderkey}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_semi_1.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.customer_key], types=['semi'], columns={'name': t0.name}) 3 | SCAN(table=tpch.CUSTOMER, columns={'key': c_custkey, 'name': c_name}) 4 | SCAN(table=tpch.ORDERS, columns={'customer_key': o_custkey}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_semi_2.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.supplier_key], types=['semi'], columns={'name': t0.name}) 3 | SCAN(table=tpch.SUPPLIER, columns={'key': s_suppkey, 'name': s_name}) 4 | JOIN(conditions=[t0.part_key == t1.key], types=['inner'], columns={'supplier_key': t0.supplier_key}) 5 | SCAN(table=tpch.PARTSUPP, columns={'part_key': ps_partkey, 'supplier_key': ps_suppkey}) 6 | FILTER(condition=size < 10:numeric, columns={'key': key}) 7 | SCAN(table=tpch.PART, columns={'key': p_partkey, 'size': p_size}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/simple_topk.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[(name):asc_last]) 2 | LIMIT(limit=Literal(value=2, type=NumericType()), columns={'comment': comment, 'key': key, 'name': name}, orderings=[(name):asc_last]) 3 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/singular1.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('nation_4_name', name_3)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.region_key], types=['left'], columns={'name': t0.name, 'name_3': t1.name}) 3 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 4 | FILTER(condition=key == 4:numeric, columns={'name': name, 'region_key': region_key}) 5 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name, 'region_key': n_regionkey}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/singular2.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('okey', key_2)], orderings=[]) 2 | JOIN(conditions=[t0.key == t1.nation_key], types=['left'], columns={'key_2': t1.key_2, 'name': t0.name}) 3 | SCAN(table=tpch.NATION, columns={'key': n_nationkey, 'name': n_name}) 4 | JOIN(conditions=[t0.key == t1.customer_key], types=['inner'], columns={'key_2': t1.key, 'nation_key': t0.nation_key}) 5 | FILTER(condition=key == 1:numeric, columns={'key': key, 'nation_key': nation_key}) 6 | SCAN(table=tpch.CUSTOMER, columns={'key': c_custkey, 'nation_key': c_nationkey}) 7 | FILTER(condition=key == 454791:numeric, columns={'customer_key': customer_key, 'key': key}) 8 | SCAN(table=tpch.ORDERS, columns={'customer_key': o_custkey, 'key': o_orderkey}) 9 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/singular3.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name)], orderings=[(order_date):asc_last]) 2 | JOIN(conditions=[t0.key == t1.customer_key], types=['left'], columns={'name': t0.name, 'order_date': t1.order_date}) 3 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'key': key, 'name': name}, orderings=[(name):asc_first]) 4 | SCAN(table=tpch.CUSTOMER, columns={'key': c_custkey, 'name': c_name}) 5 | FILTER(condition=RANKING(args=[], partition=[customer_key], order=[(total_price):desc_first]) == 1:numeric, columns={'customer_key': customer_key, 'order_date': order_date}) 6 | SCAN(table=tpch.ORDERS, columns={'customer_key': o_custkey, 'order_date': o_orderdate, 'total_price': o_totalprice}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/singular_anti.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', name), ('region_name', NULL_1)], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['anti'], columns={'NULL_1': None:unknown, 'name': t0.name}) 3 | SCAN(table=tpch.NATION, columns={'name': n_name, 'region_key': n_regionkey}) 4 | FILTER(condition=name != 'ASIA':string, columns={'key': key}) 5 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/singular_semi.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('nation_name', nation_name), ('region_name', region_name)], orderings=[]) 2 | JOIN(conditions=[t0.region_key == t1.key], types=['inner'], columns={'nation_name': t0.nation_name, 'region_name': t1.region_name}) 3 | SCAN(table=tpch.NATION, columns={'nation_name': n_name, 'region_key': n_regionkey}) 4 | PROJECT(columns={'key': key, 'region_name': name}) 5 | FILTER(condition=name != 'ASIA':string, columns={'key': key, 'name': name}) 6 | SCAN(table=tpch.REGION, columns={'key': r_regionkey, 'name': r_name}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/strip.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('stripped_name', STRIP(name, 'Alex Rodriguez':string)), ('stripped_name1', STRIP(name)), ('stripped_name_with_chars', STRIP(name, 'lAez':string)), ('stripped_alt_name1', STRIP(' Alex Rodriguez ':string)), ('stripped_alt_name2', STRIP('aeiAlex Rodriguezaeiou':string, 'aeiou':string)), ('stripped_alt_name3', STRIP(';;Alex Rodriguez;;':string, ';':string)), ('stripped_alt_name4', STRIP('\n Alex Rodriguez\n ':string))], orderings=[]) 2 | FILTER(condition=name == 'Alex Rodriguez':string, columns={'name': name}) 3 | SCAN(table=main.sbCustomer, columns={'name': sbCustName}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/technograph_country_cartesian_oddball.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('n_other_countries', n_other_countries)], orderings=[(name):asc_first]) 2 | PROJECT(columns={'n_other_countries': DEFAULT_TO(agg_0, 0:numeric), 'name': name}) 3 | JOIN(conditions=[True:bool], types=['left'], columns={'agg_0': t1.agg_0, 'name': t0.name}) 4 | SCAN(table=main.COUNTRIES, columns={'name': co_name}) 5 | AGGREGATE(keys={}, aggregations={'agg_0': COUNT()}) 6 | SCAN(table=main.COUNTRIES, columns={}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/technograph_global_incident_rate.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('ir', ROUND(agg_0 / agg_1, 2:numeric))], orderings=[]) 2 | JOIN(conditions=[True:bool], types=['left'], columns={'agg_0': t0.agg_0, 'agg_1': t1.agg_1}) 3 | AGGREGATE(keys={}, aggregations={'agg_0': COUNT()}) 4 | SCAN(table=main.INCIDENTS, columns={}) 5 | AGGREGATE(keys={}, aggregations={'agg_1': COUNT()}) 6 | SCAN(table=main.DEVICES, columns={}) 7 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/top_customers_by_orders.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('customer_key', customer_key_2), ('n_orders', n_orders)], orderings=[(ordering_1):desc_last, (customer_key_2):asc_first]) 2 | LIMIT(limit=Literal(value=5, type=NumericType()), columns={'customer_key_2': customer_key_2, 'n_orders': n_orders, 'ordering_1': ordering_1}, orderings=[(ordering_1):desc_last, (customer_key_2):asc_first]) 3 | PROJECT(columns={'customer_key_2': key, 'n_orders': DEFAULT_TO(agg_0, 0:numeric), 'ordering_1': DEFAULT_TO(agg_0, 0:numeric)}) 4 | JOIN(conditions=[t0.key == t1.customer_key], types=['left'], columns={'agg_0': t1.agg_0, 'key': t0.key}) 5 | SCAN(table=tpch.CUSTOMER, columns={'key': c_custkey}) 6 | AGGREGATE(keys={'customer_key': customer_key}, aggregations={'agg_0': COUNT()}) 7 | SCAN(table=tpch.ORDERS, columns={'customer_key': o_custkey}) 8 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/topk_order_by.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[(name):asc_last]) 2 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'comment': comment, 'key': key, 'name': name}, orderings=[(name):asc_last]) 3 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/topk_order_by_calc.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('region_name', region_name), ('name_length', name_length)], orderings=[(name):asc_last]) 2 | PROJECT(columns={'name': name, 'name_length': LENGTH(name), 'region_name': name}) 3 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'name': name}, orderings=[(name):asc_last]) 4 | SCAN(table=tpch.REGION, columns={'name': r_name}) 5 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/topk_replace_order_by.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[(name):desc_first]) 2 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'comment': comment, 'key': key, 'name': name}, orderings=[(name):desc_first]) 3 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/topk_root_different_order_by.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('key', key), ('name', name), ('comment', comment)], orderings=[(name):desc_first]) 2 | LIMIT(limit=Literal(value=10, type=NumericType()), columns={'comment': comment, 'key': key, 'name': name}, orderings=[(name):asc_first]) 3 | SCAN(table=tpch.REGION, columns={'comment': r_comment, 'key': r_regionkey, 'name': r_name}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/tpch_q6.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('REVENUE', DEFAULT_TO(agg_0, 0:numeric))], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': SUM(amt)}) 3 | PROJECT(columns={'amt': extended_price * discount}) 4 | FILTER(condition=discount <= 0.07:numeric & quantity < 24:numeric & ship_date < datetime.date(1995, 1, 1):datetime & discount >= 0.05:numeric & ship_date >= datetime.date(1994, 1, 1):datetime, columns={'discount': discount, 'extended_price': extended_price}) 5 | SCAN(table=tpch.LINEITEM, columns={'discount': l_discount, 'extended_price': l_extendedprice, 'quantity': l_quantity, 'ship_date': l_shipdate}) 6 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/various_aggfuncs_global.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('total_bal', agg_5), ('num_bal', agg_3), ('avg_bal', DEFAULT_TO(agg_0, 0:numeric)), ('min_bal', agg_2), ('max_bal', agg_1), ('num_cust', agg_4)], orderings=[]) 2 | AGGREGATE(keys={}, aggregations={'agg_0': AVG(account_balance), 'agg_1': MAX(account_balance), 'agg_2': MIN(account_balance), 'agg_3': COUNT(account_balance), 'agg_4': COUNT(), 'agg_5': SUM(account_balance)}) 3 | SCAN(table=tpch.CUSTOMER, columns={'account_balance': c_acctbal}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/wealthiest_supplier.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('name', name), ('account_balance', account_balance)], orderings=[]) 2 | FILTER(condition=RANKING(args=[], partition=[], order=[(account_balance):desc_first, (name):asc_last], allow_ties=False) == 1:numeric, columns={'account_balance': account_balance, 'name': name}) 3 | SCAN(table=tpch.SUPPLIER, columns={'account_balance': s_acctbal, 'name': s_name}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/week_offset.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('date_time', date_time), ('week_adj1', DATETIME(date_time, '1 week':string)), ('week_adj2', DATETIME(date_time, '-1 week':string)), ('week_adj3', DATETIME(date_time, '1 h':string, '2 w':string)), ('week_adj4', DATETIME(date_time, '-1 s':string, '2 w':string)), ('week_adj5', DATETIME(date_time, '1 d':string, '2 w':string)), ('week_adj6', DATETIME(date_time, '-1 m':string, '2 w':string)), ('week_adj7', DATETIME(date_time, '1 mm':string, '2 w':string)), ('week_adj8', DATETIME(date_time, '1 y':string, '2 w':string))], orderings=[]) 2 | FILTER(condition=YEAR(date_time) < 2025:numeric & DAY(date_time) > 1:numeric, columns={'date_time': date_time}) 3 | SCAN(table=main.sbTransaction, columns={'date_time': sbTxDateTime}) 4 | -------------------------------------------------------------------------------- /tests/test_plan_refsols/yoy_change_in_num_orders.txt: -------------------------------------------------------------------------------- 1 | ROOT(columns=[('year', year), ('current_year_orders', current_year_orders), ('pct_change', pct_change)], orderings=[(year):asc_first]) 2 | PROJECT(columns={'current_year_orders': DEFAULT_TO(agg_0, 0:numeric), 'pct_change': 100.0:numeric * DEFAULT_TO(agg_0, 0:numeric) - PREV(args=[DEFAULT_TO(agg_0, 0:numeric)], partition=[], order=[(year):asc_last]) / PREV(args=[DEFAULT_TO(agg_0, 0:numeric)], partition=[], order=[(year):asc_last]), 'year': year}) 3 | AGGREGATE(keys={'year': year}, aggregations={'agg_0': COUNT()}) 4 | PROJECT(columns={'year': YEAR(order_date)}) 5 | SCAN(table=tpch.ORDERS, columns={'order_date': o_orderdate}) 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv10_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustomer.sbcustid AS _id 5 | FROM main.sbcustomer AS sbcustomer 6 | JOIN main.sbtransaction AS sbtransaction 7 | ON EXTRACT(MONTH FROM sbcustomer.sbcustjoindate) = EXTRACT(MONTH FROM sbtransaction.sbtxdatetime) 8 | AND EXTRACT(YEAR FROM sbcustomer.sbcustjoindate) = EXTRACT(YEAR FROM sbtransaction.sbtxdatetime) 9 | AND sbcustomer.sbcustid = sbtransaction.sbtxcustid 10 | GROUP BY 11 | sbcustomer.sbcustid 12 | ) 13 | SELECT 14 | sbcustomer.sbcustid AS _id, 15 | sbcustomer.sbcustname AS name, 16 | COALESCE(_s3.agg_0, 0) AS num_transactions 17 | FROM main.sbcustomer AS sbcustomer 18 | LEFT JOIN _s3 AS _s3 19 | ON _s3._id = sbcustomer.sbcustid 20 | ORDER BY 21 | num_transactions DESC 22 | LIMIT 1 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv12_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS n_customers 3 | FROM main.sbcustomer 4 | WHERE 5 | ( 6 | LOWER(sbcustname) LIKE '%ez' OR LOWER(sbcustname) LIKE 'j%' 7 | ) 8 | AND LOWER(sbcuststate) LIKE '%a' 9 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv12_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS n_customers 3 | FROM main.sbcustomer 4 | WHERE 5 | ( 6 | LOWER(sbcustname) LIKE '%ez' OR LOWER(sbcustname) LIKE 'j%' 7 | ) 8 | AND LOWER(sbcuststate) LIKE '%a' 9 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv13_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustcountry AS country 5 | FROM main.sbcustomer 6 | WHERE 7 | sbcustjoindate >= CAST('2023-01-01' AS DATE) 8 | GROUP BY 9 | sbcustcountry 10 | ) 11 | SELECT 12 | country AS cust_country, 13 | COALESCE(agg_0, 0) AS TAC 14 | FROM _t0 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv13_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustcountry AS country 5 | FROM main.sbcustomer 6 | WHERE 7 | sbcustjoindate >= '2023-01-01' 8 | GROUP BY 9 | sbcustcountry 10 | ) 11 | SELECT 12 | country AS cust_country, 13 | COALESCE(agg_0, 0) AS TAC 14 | FROM _t0 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv14_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sbticker.sbtickertype AS ticker_type, 3 | AVG(sbdailyprice.sbdpclose) AS ACP 4 | FROM main.sbdailyprice AS sbdailyprice 5 | LEFT JOIN main.sbticker AS sbticker 6 | ON sbdailyprice.sbdptickerid = sbticker.sbtickerid 7 | WHERE 8 | DATEDIFF(CURRENT_TIMESTAMP(), sbdailyprice.sbdpdate, DAY) <= 7 9 | GROUP BY 10 | sbticker.sbtickertype 11 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv14_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sbticker.sbtickertype AS ticker_type, 3 | AVG(sbdailyprice.sbdpclose) AS ACP 4 | FROM main.sbdailyprice AS sbdailyprice 5 | LEFT JOIN main.sbticker AS sbticker 6 | ON sbdailyprice.sbdptickerid = sbticker.sbtickerid 7 | WHERE 8 | CAST(( 9 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(sbdailyprice.sbdpdate, 'start of day')) 10 | ) AS INTEGER) <= 7 11 | GROUP BY 12 | sbticker.sbtickertype 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv15_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(sbcuststatus = 'active') AS agg_0, 4 | COUNT() AS agg_1, 5 | sbcustcountry AS country 6 | FROM main.sbcustomer 7 | WHERE 8 | sbcustjoindate <= '2022-12-31' AND sbcustjoindate >= '2022-01-01' 9 | GROUP BY 10 | sbcustcountry 11 | ) 12 | SELECT 13 | country, 14 | 100 * COALESCE(COALESCE(agg_0, 0) / COALESCE(agg_1, 0), 0.0) AS ar 15 | FROM _t0 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv15_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(sbcuststatus = 'active') AS agg_0, 4 | COUNT() AS agg_1, 5 | sbcustcountry AS country 6 | FROM main.sbcustomer 7 | WHERE 8 | sbcustjoindate <= '2022-12-31' AND sbcustjoindate >= '2022-01-01' 9 | GROUP BY 10 | sbcustcountry 11 | ) 12 | SELECT 13 | country, 14 | 100 * COALESCE(CAST(COALESCE(agg_0, 0) AS REAL) / COALESCE(agg_1, 0), 0.0) AS ar 15 | FROM _t0 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv16_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sbtxamount) AS agg_0, 4 | SUM(sbtxtax + sbtxcommission) AS agg_1, 5 | sbtxtickerid AS ticker_id 6 | FROM main.sbtransaction 7 | WHERE 8 | sbtxdatetime >= DATE_ADD(CURRENT_TIMESTAMP(), -1, 'MONTH') AND sbtxtype = 'sell' 9 | GROUP BY 10 | sbtxtickerid 11 | ) 12 | SELECT 13 | sbticker.sbtickersymbol AS symbol, 14 | ( 15 | 100.0 * ( 16 | COALESCE(_s1.agg_0, 0) - COALESCE(_s1.agg_1, 0) 17 | ) 18 | ) / COALESCE(_s1.agg_0, 0) AS SPM 19 | FROM main.sbticker AS sbticker 20 | LEFT JOIN _s1 AS _s1 21 | ON _s1.ticker_id = sbticker.sbtickerid 22 | WHERE 23 | NOT ( 24 | 100.0 * ( 25 | COALESCE(_s1.agg_0, 0) - COALESCE(_s1.agg_1, 0) 26 | ) 27 | ) / COALESCE(_s1.agg_0, 0) IS NULL 28 | ORDER BY 29 | symbol 30 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv1_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sbtxamount) AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxcustid 8 | ) 9 | SELECT 10 | sbcustomer.sbcustname AS name, 11 | COALESCE(_s1.agg_0, 0) AS total_amount 12 | FROM main.sbcustomer AS sbcustomer 13 | LEFT JOIN _s1 AS _s1 14 | ON _s1.customer_id = sbcustomer.sbcustid 15 | ORDER BY 16 | total_amount DESC 17 | LIMIT 5 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv1_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sbtxamount) AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxcustid 8 | ) 9 | SELECT 10 | sbcustomer.sbcustname AS name, 11 | COALESCE(_s1.agg_0, 0) AS total_amount 12 | FROM main.sbcustomer AS sbcustomer 13 | LEFT JOIN _s1 AS _s1 14 | ON _s1.customer_id = sbcustomer.sbcustid 15 | ORDER BY 16 | total_amount DESC 17 | LIMIT 5 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbtxtickerid AS ticker_id 5 | FROM main.sbtransaction 6 | WHERE 7 | sbtxdatetime >= DATE_TRUNC('DAY', DATE_ADD(CURRENT_TIMESTAMP(), -10, 'DAY')) 8 | AND sbtxtype = 'buy' 9 | GROUP BY 10 | sbtxtickerid 11 | ) 12 | SELECT 13 | sbticker.sbtickersymbol AS symbol, 14 | COALESCE(_s1.agg_0, 0) AS tx_count 15 | FROM main.sbticker AS sbticker 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.ticker_id = sbticker.sbtickerid 18 | ORDER BY 19 | tx_count DESC 20 | LIMIT 2 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbtxtickerid AS ticker_id 5 | FROM main.sbtransaction 6 | WHERE 7 | sbtxdatetime >= DATE(DATETIME('now', '-10 day'), 'start of day') 8 | AND sbtxtype = 'buy' 9 | GROUP BY 10 | sbtxtickerid 11 | ) 12 | SELECT 13 | sbticker.sbtickersymbol AS symbol, 14 | COALESCE(_s1.agg_0, 0) AS tx_count 15 | FROM main.sbticker AS sbticker 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.ticker_id = sbticker.sbtickerid 18 | ORDER BY 19 | tx_count DESC 20 | LIMIT 2 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sbtxstatus = 'success') AS agg_1, 5 | sbtxcustid AS customer_id 6 | FROM main.sbtransaction 7 | GROUP BY 8 | sbtxcustid 9 | ) 10 | SELECT 11 | sbcustomer.sbcustname AS name, 12 | ( 13 | 100.0 * COALESCE(_s1.agg_1, 0) 14 | ) / COALESCE(_s1.agg_0, 0) AS success_rate 15 | FROM main.sbcustomer AS sbcustomer 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.customer_id = sbcustomer.sbcustid 18 | WHERE 19 | NOT _s1.agg_0 IS NULL AND _s1.agg_0 >= 5 20 | ORDER BY 21 | success_rate 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv3_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sbtxstatus = 'success') AS agg_1, 5 | sbtxcustid AS customer_id 6 | FROM main.sbtransaction 7 | GROUP BY 8 | sbtxcustid 9 | ) 10 | SELECT 11 | sbcustomer.sbcustname AS name, 12 | CAST(( 13 | 100.0 * COALESCE(_s1.agg_1, 0) 14 | ) AS REAL) / COALESCE(_s1.agg_0, 0) AS success_rate 15 | FROM main.sbcustomer AS sbcustomer 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.customer_id = sbcustomer.sbcustid 18 | WHERE 19 | NOT _s1.agg_0 IS NULL AND _s1.agg_0 >= 5 20 | ORDER BY 21 | success_rate 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | MAX(sbdphigh) AS agg_0, 4 | MIN(sbdplow) AS agg_1, 5 | sbdptickerid AS ticker_id 6 | FROM main.sbdailyprice 7 | WHERE 8 | sbdpdate <= CAST('2023-04-04' AS DATE) AND sbdpdate >= CAST('2023-04-01' AS DATE) 9 | GROUP BY 10 | sbdptickerid 11 | ) 12 | SELECT 13 | sbticker.sbtickersymbol AS symbol, 14 | _s1.agg_0 - _s1.agg_1 AS price_change 15 | FROM main.sbticker AS sbticker 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.ticker_id = sbticker.sbtickerid 18 | ORDER BY 19 | price_change DESC 20 | LIMIT 3 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | MAX(sbdphigh) AS agg_0, 4 | MIN(sbdplow) AS agg_1, 5 | sbdptickerid AS ticker_id 6 | FROM main.sbdailyprice 7 | WHERE 8 | sbdpdate <= '2023-04-04' AND sbdpdate >= '2023-04-01' 9 | GROUP BY 10 | sbdptickerid 11 | ) 12 | SELECT 13 | sbticker.sbtickersymbol AS symbol, 14 | _s1.agg_0 - _s1.agg_1 AS price_change 15 | FROM main.sbticker AS sbticker 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.ticker_id = sbticker.sbtickerid 18 | ORDER BY 19 | price_change DESC 20 | LIMIT 3 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sbtxamount) AS agg_0, 4 | COUNT() AS agg_1, 5 | sbtxcustid AS customer_id 6 | FROM main.sbtransaction 7 | GROUP BY 8 | sbtxcustid 9 | ) 10 | SELECT 11 | sbcustomer.sbcustname AS name, 12 | _s1.agg_1 AS num_tx, 13 | COALESCE(_s1.agg_0, 0) AS total_amount, 14 | RANK() OVER (ORDER BY COALESCE(_s1.agg_0, 0) DESC NULLS FIRST) AS cust_rank 15 | FROM main.sbcustomer AS sbcustomer 16 | JOIN _s1 AS _s1 17 | ON _s1.customer_id = sbcustomer.sbcustid 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_adv6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sbtxamount) AS agg_0, 4 | COUNT() AS agg_1, 5 | sbtxcustid AS customer_id 6 | FROM main.sbtransaction 7 | GROUP BY 8 | sbtxcustid 9 | ) 10 | SELECT 11 | sbcustomer.sbcustname AS name, 12 | _s1.agg_1 AS num_tx, 13 | COALESCE(_s1.agg_0, 0) AS total_amount, 14 | RANK() OVER (ORDER BY COALESCE(_s1.agg_0, 0) DESC) AS cust_rank 15 | FROM main.sbcustomer AS sbcustomer 16 | JOIN _s1 AS _s1 17 | ON _s1.customer_id = sbcustomer.sbcustid 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic10_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sbdailyprice.sbdptickerid AS ticker_id 4 | FROM main.sbdailyprice AS sbdailyprice 5 | ), _s0 AS ( 6 | SELECT 7 | sbticker.sbtickerid AS _id, 8 | sbticker.sbtickersymbol AS symbol 9 | FROM main.sbticker AS sbticker 10 | ) 11 | SELECT 12 | _s0._id AS _id, 13 | _s0.symbol AS symbol 14 | FROM _s0 AS _s0 15 | WHERE 16 | NOT EXISTS( 17 | SELECT 18 | 1 AS "1" 19 | FROM _s1 AS _s1 20 | WHERE 21 | _s0._id = _s1.ticker_id 22 | ) 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic10_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sbdailyprice.sbdptickerid AS ticker_id 4 | FROM main.sbdailyprice AS sbdailyprice 5 | ), _s0 AS ( 6 | SELECT 7 | sbticker.sbtickerid AS _id, 8 | sbticker.sbtickersymbol AS symbol 9 | FROM main.sbticker AS sbticker 10 | ) 11 | SELECT 12 | _s0._id AS _id, 13 | _s0.symbol AS symbol 14 | FROM _s0 AS _s0 15 | WHERE 16 | NOT EXISTS( 17 | SELECT 18 | 1 AS "1" 19 | FROM _s1 AS _s1 20 | WHERE 21 | _s0._id = _s1.ticker_id 22 | ) 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | AVG(sbtxshares) AS agg_0, 4 | COUNT(DISTINCT sbtxcustid) AS agg_1, 5 | sbtxtype AS transaction_type 6 | FROM main.sbtransaction 7 | WHERE 8 | sbtxdatetime <= CAST('2023-03-31' AS DATE) 9 | AND sbtxdatetime >= CAST('2023-01-01' AS DATE) 10 | GROUP BY 11 | sbtxtype 12 | ) 13 | SELECT 14 | transaction_type, 15 | COALESCE(agg_1, 0) AS num_customers, 16 | agg_0 AS avg_shares 17 | FROM _t1 18 | ORDER BY 19 | num_customers DESC 20 | LIMIT 3 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | AVG(sbtxshares) AS agg_0, 4 | COUNT(DISTINCT sbtxcustid) AS agg_1, 5 | sbtxtype AS transaction_type 6 | FROM main.sbtransaction 7 | WHERE 8 | sbtxdatetime <= '2023-03-31' AND sbtxdatetime >= '2023-01-01' 9 | GROUP BY 10 | sbtxtype 11 | ) 12 | SELECT 13 | transaction_type, 14 | COALESCE(agg_1, 0) AS num_customers, 15 | agg_0 AS avg_shares 16 | FROM _t1 17 | ORDER BY 18 | num_customers DESC 19 | LIMIT 3 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sbtxamount) AS agg_1, 5 | sbtxtickerid AS ticker_id 6 | FROM main.sbtransaction 7 | GROUP BY 8 | sbtxtickerid 9 | ) 10 | SELECT 11 | sbticker.sbtickersymbol AS symbol, 12 | COALESCE(_s1.agg_0, 0) AS num_transactions, 13 | COALESCE(_s1.agg_1, 0) AS total_amount 14 | FROM main.sbticker AS sbticker 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.ticker_id = sbticker.sbtickerid 17 | ORDER BY 18 | total_amount DESC 19 | LIMIT 10 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic3_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sbtxamount) AS agg_1, 5 | sbtxtickerid AS ticker_id 6 | FROM main.sbtransaction 7 | GROUP BY 8 | sbtxtickerid 9 | ) 10 | SELECT 11 | sbticker.sbtickersymbol AS symbol, 12 | COALESCE(_s1.agg_0, 0) AS num_transactions, 13 | COALESCE(_s1.agg_1, 0) AS total_amount 14 | FROM main.sbticker AS sbticker 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.ticker_id = sbticker.sbtickerid 17 | ORDER BY 18 | total_amount DESC 19 | LIMIT 10 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustomer.sbcuststate AS state, 5 | sbticker.sbtickertype AS ticker_type 6 | FROM main.sbcustomer AS sbcustomer 7 | JOIN main.sbtransaction AS sbtransaction 8 | ON sbcustomer.sbcustid = sbtransaction.sbtxcustid 9 | LEFT JOIN main.sbticker AS sbticker 10 | ON sbticker.sbtickerid = sbtransaction.sbtxtickerid 11 | GROUP BY 12 | sbcustomer.sbcuststate, 13 | sbticker.sbtickertype 14 | ) 15 | SELECT 16 | state, 17 | ticker_type, 18 | COALESCE(agg_0, 0) AS num_transactions 19 | FROM _t1 20 | ORDER BY 21 | num_transactions DESC 22 | LIMIT 5 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustomer.sbcuststate AS state, 5 | sbticker.sbtickertype AS ticker_type 6 | FROM main.sbcustomer AS sbcustomer 7 | JOIN main.sbtransaction AS sbtransaction 8 | ON sbcustomer.sbcustid = sbtransaction.sbtxcustid 9 | LEFT JOIN main.sbticker AS sbticker 10 | ON sbticker.sbtickerid = sbtransaction.sbtxtickerid 11 | GROUP BY 12 | sbcustomer.sbcuststate, 13 | sbticker.sbtickertype 14 | ) 15 | SELECT 16 | state, 17 | ticker_type, 18 | COALESCE(agg_0, 0) AS num_transactions 19 | FROM _t1 20 | ORDER BY 21 | num_transactions DESC 22 | LIMIT 5 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic5_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | sbtransaction.sbtxcustid AS customer_id, 4 | sbtransaction.sbtxtype AS transaction_type 5 | FROM main.sbtransaction AS sbtransaction 6 | WHERE 7 | sbtransaction.sbtxtype = 'buy' 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.customer_id AS customer_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | sbcustomer.sbcustid AS _id 15 | FROM main.sbcustomer AS sbcustomer 16 | ) 17 | SELECT 18 | _s0._id AS _id 19 | FROM _s0 AS _s0 20 | WHERE 21 | EXISTS( 22 | SELECT 23 | 1 AS "1" 24 | FROM _s1 AS _s1 25 | WHERE 26 | _s0._id = _s1.customer_id 27 | ) 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic5_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | sbtransaction.sbtxcustid AS customer_id, 4 | sbtransaction.sbtxtype AS transaction_type 5 | FROM main.sbtransaction AS sbtransaction 6 | WHERE 7 | sbtransaction.sbtxtype = 'buy' 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.customer_id AS customer_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | sbcustomer.sbcustid AS _id 15 | FROM main.sbcustomer AS sbcustomer 16 | ) 17 | SELECT 18 | _s0._id AS _id 19 | FROM _s0 AS _s0 20 | WHERE 21 | EXISTS( 22 | SELECT 23 | 1 AS "1" 24 | FROM _s1 AS _s1 25 | WHERE 26 | _s0._id = _s1.customer_id 27 | ) 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | sbdailyprice.sbdpdate AS date, 4 | sbdailyprice.sbdptickerid AS ticker_id 5 | FROM main.sbdailyprice AS sbdailyprice 6 | WHERE 7 | sbdailyprice.sbdpdate >= CAST('2023-04-01' AS DATE) 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.ticker_id AS ticker_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | sbticker.sbtickerid AS _id 15 | FROM main.sbticker AS sbticker 16 | ) 17 | SELECT 18 | _s0._id AS _id 19 | FROM _s0 AS _s0 20 | WHERE 21 | EXISTS( 22 | SELECT 23 | 1 AS "1" 24 | FROM _s1 AS _s1 25 | WHERE 26 | _s0._id = _s1.ticker_id 27 | ) 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | sbdailyprice.sbdpdate AS date, 4 | sbdailyprice.sbdptickerid AS ticker_id 5 | FROM main.sbdailyprice AS sbdailyprice 6 | WHERE 7 | sbdailyprice.sbdpdate >= '2023-04-01' 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.ticker_id AS ticker_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | sbticker.sbtickerid AS _id 15 | FROM main.sbticker AS sbticker 16 | ) 17 | SELECT 18 | _s0._id AS _id 19 | FROM _s0 AS _s0 20 | WHERE 21 | EXISTS( 22 | SELECT 23 | 1 AS "1" 24 | FROM _s1 AS _s1 25 | WHERE 26 | _s0._id = _s1.ticker_id 27 | ) 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic7_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbtxstatus AS status 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxstatus 8 | ) 9 | SELECT 10 | status, 11 | COALESCE(agg_0, 0) AS num_transactions 12 | FROM _t1 13 | ORDER BY 14 | num_transactions DESC 15 | LIMIT 3 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic7_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbtxstatus AS status 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxstatus 8 | ) 9 | SELECT 10 | status, 11 | COALESCE(agg_0, 0) AS num_transactions 12 | FROM _t1 13 | ORDER BY 14 | num_transactions DESC 15 | LIMIT 3 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic8_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustcountry AS country 5 | FROM main.sbcustomer 6 | GROUP BY 7 | sbcustcountry 8 | ) 9 | SELECT 10 | country, 11 | COALESCE(agg_0, 0) AS num_customers 12 | FROM _t1 13 | ORDER BY 14 | num_customers DESC 15 | LIMIT 5 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic8_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbcustcountry AS country 5 | FROM main.sbcustomer 6 | GROUP BY 7 | sbcustcountry 8 | ) 9 | SELECT 10 | country, 11 | COALESCE(agg_0, 0) AS num_customers 12 | FROM _t1 13 | ORDER BY 14 | num_customers DESC 15 | LIMIT 5 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic9_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sbtransaction.sbtxcustid AS customer_id 4 | FROM main.sbtransaction AS sbtransaction 5 | ), _s0 AS ( 6 | SELECT 7 | sbcustomer.sbcustid AS _id, 8 | sbcustomer.sbcustname AS name 9 | FROM main.sbcustomer AS sbcustomer 10 | ) 11 | SELECT 12 | _s0._id AS _id, 13 | _s0.name AS name 14 | FROM _s0 AS _s0 15 | WHERE 16 | NOT EXISTS( 17 | SELECT 18 | 1 AS "1" 19 | FROM _s1 AS _s1 20 | WHERE 21 | _s0._id = _s1.customer_id 22 | ) 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_basic9_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sbtransaction.sbtxcustid AS customer_id 4 | FROM main.sbtransaction AS sbtransaction 5 | ), _s0 AS ( 6 | SELECT 7 | sbcustomer.sbcustid AS _id, 8 | sbcustomer.sbcustname AS name 9 | FROM main.sbcustomer AS sbcustomer 10 | ) 11 | SELECT 12 | _s0._id AS _id, 13 | _s0.name AS name 14 | FROM _s0 AS _s0 15 | WHERE 16 | NOT EXISTS( 17 | SELECT 18 | 1 AS "1" 19 | FROM _s1 AS _s1 20 | WHERE 21 | _s0._id = _s1.customer_id 22 | ) 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen1_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | MIN(sbdpclose) AS agg_0, 4 | sbdptickerid AS ticker_id 5 | FROM main.sbdailyprice 6 | WHERE 7 | DATEDIFF(CURRENT_TIMESTAMP(), sbdpdate, DAY) <= 7 8 | GROUP BY 9 | sbdptickerid 10 | ) 11 | SELECT 12 | MIN(_s0.agg_0) AS lowest_price 13 | FROM _s0 AS _s0 14 | JOIN main.sbticker AS sbticker 15 | ON _s0.ticker_id = sbticker.sbtickerid AND sbticker.sbtickersymbol = 'VTI' 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen1_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | MIN(sbdpclose) AS agg_0, 4 | sbdptickerid AS ticker_id 5 | FROM main.sbdailyprice 6 | WHERE 7 | CAST(( 8 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(sbdpdate, 'start of day')) 9 | ) AS INTEGER) <= 7 10 | GROUP BY 11 | sbdptickerid 12 | ) 13 | SELECT 14 | MIN(_s0.agg_0) AS lowest_price 15 | FROM _s0 AS _s0 16 | JOIN main.sbticker AS sbticker 17 | ON _s0.ticker_id = sbticker.sbtickerid AND sbticker.sbtickersymbol = 'VTI' 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | COUNT(sbtxcustid) AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxcustid 8 | ), _t0 AS ( 9 | SELECT 10 | SUM(_s0.agg_0) AS agg_0 11 | FROM _s0 AS _s0 12 | JOIN main.sbcustomer AS sbcustomer 13 | ON _s0.customer_id = sbcustomer.sbcustid 14 | AND sbcustomer.sbcustjoindate >= DATE_ADD(CURRENT_TIMESTAMP(), -70, 'DAY') 15 | ) 16 | SELECT 17 | COALESCE(agg_0, 0) AS transaction_count 18 | FROM _t0 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | COUNT(sbtxcustid) AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxcustid 8 | ), _t0 AS ( 9 | SELECT 10 | SUM(_s0.agg_0) AS agg_0 11 | FROM _s0 AS _s0 12 | JOIN main.sbcustomer AS sbcustomer 13 | ON _s0.customer_id = sbcustomer.sbcustid 14 | AND sbcustomer.sbcustjoindate >= DATETIME('now', '-70 day') 15 | ) 16 | SELECT 17 | COALESCE(agg_0, 0) AS transaction_count 18 | FROM _t0 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | MIN(sbtxdatetime) AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | GROUP BY 7 | sbtxcustid 8 | ) 9 | SELECT 10 | sbcustomer.sbcustid AS cust_id, 11 | DATEDIFF(_s1.agg_0, sbcustomer.sbcustjoindate, SECOND) / 86400.0 AS DaysFromJoinToFirstTransaction 12 | FROM main.sbcustomer AS sbcustomer 13 | JOIN _s1 AS _s1 14 | ON _s1.customer_id = sbcustomer.sbcustid 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | WHERE 7 | CAST(sbtxdatetime AS TIMESTAMP) < CAST('2023-04-02' AS DATE) 8 | AND CAST(sbtxdatetime AS TIMESTAMP) >= CAST('2023-04-01' AS DATE) 9 | AND sbtxtype = 'sell' 10 | GROUP BY 11 | sbtxcustid 12 | ) 13 | SELECT 14 | sbcustomer.sbcustid AS _id, 15 | sbcustomer.sbcustname AS name, 16 | COALESCE(_s1.agg_0, 0) AS num_tx 17 | FROM main.sbcustomer AS sbcustomer 18 | LEFT JOIN _s1 AS _s1 19 | ON _s1.customer_id = sbcustomer.sbcustid 20 | ORDER BY 21 | num_tx DESC 22 | LIMIT 1 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | sbtxcustid AS customer_id 5 | FROM main.sbtransaction 6 | WHERE 7 | DATE(sbtxdatetime, 'start of day') = '2023-04-01' AND sbtxtype = 'sell' 8 | GROUP BY 9 | sbtxcustid 10 | ) 11 | SELECT 12 | sbcustomer.sbcustid AS _id, 13 | sbcustomer.sbcustname AS name, 14 | COALESCE(_s1.agg_0, 0) AS num_tx 15 | FROM main.sbcustomer AS sbcustomer 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.customer_id = sbcustomer.sbcustid 18 | ORDER BY 19 | num_tx DESC 20 | LIMIT 1 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen5_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATE_TRUNC('MONTH', CAST(sbtxdatetime AS TIMESTAMP)) AS month, 3 | AVG(sbtxprice) AS avg_price 4 | FROM main.sbtransaction 5 | WHERE 6 | sbtxdatetime <= CAST('2023-03-31' AS DATE) 7 | AND sbtxdatetime >= CAST('2023-01-01' AS DATE) 8 | AND sbtxstatus = 'success' 9 | GROUP BY 10 | DATE_TRUNC('MONTH', CAST(sbtxdatetime AS TIMESTAMP)) 11 | ORDER BY 12 | month 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_broker_gen5_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | DATE(sbtxdatetime, 'start of month') AS month, 3 | AVG(sbtxprice) AS avg_price 4 | FROM main.sbtransaction 5 | WHERE 6 | sbtxdatetime <= '2023-03-31' 7 | AND sbtxdatetime >= '2023-01-01' 8 | AND sbtxstatus = 'success' 9 | GROUP BY 10 | DATE(sbtxdatetime, 'start of month') 11 | ORDER BY 12 | month 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv10_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | MAX(payment_date) AS agg_0, 4 | sale_id 5 | FROM main.payments_received 6 | GROUP BY 7 | sale_id 8 | ), _t0 AS ( 9 | SELECT 10 | AVG(DATEDIFF(_s1.agg_0, sales.sale_date, DAY)) AS agg_0 11 | FROM main.sales AS sales 12 | LEFT JOIN _s1 AS _s1 13 | ON _s1.sale_id = sales._id 14 | ) 15 | SELECT 16 | ROUND(agg_0, 2) AS avg_days_to_payment 17 | FROM _t0 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv10_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | MAX(payment_date) AS agg_0, 4 | sale_id 5 | FROM main.payments_received 6 | GROUP BY 7 | sale_id 8 | ), _t0 AS ( 9 | SELECT 10 | AVG( 11 | CAST(( 12 | JULIANDAY(DATE(_s1.agg_0, 'start of day')) - JULIANDAY(DATE(sales.sale_date, 'start of day')) 13 | ) AS INTEGER) 14 | ) AS agg_0 15 | FROM main.sales AS sales 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.sale_id = sales._id 18 | ) 19 | SELECT 20 | ROUND(agg_0, 2) AS avg_days_to_payment 21 | FROM _t0 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv11_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(sales.sale_price) AS agg_0, 4 | SUM(cars.cost) AS agg_1 5 | FROM main.sales AS sales 6 | JOIN main.cars AS cars 7 | ON cars._id = sales.car_id 8 | WHERE 9 | EXTRACT(YEAR FROM sales.sale_date) = 2023 10 | ) 11 | SELECT 12 | ( 13 | ( 14 | COALESCE(agg_0, 0) - COALESCE(agg_1, 0) 15 | ) / COALESCE(agg_1, 0) 16 | ) * 100 AS GPM 17 | FROM _t0 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv11_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(sales.sale_price) AS agg_0, 4 | SUM(cars.cost) AS agg_1 5 | FROM main.sales AS sales 6 | JOIN main.cars AS cars 7 | ON cars._id = sales.car_id 8 | WHERE 9 | CAST(STRFTIME('%Y', sales.sale_date) AS INTEGER) = 2023 10 | ) 11 | SELECT 12 | ( 13 | CAST(( 14 | COALESCE(agg_0, 0) - COALESCE(agg_1, 0) 15 | ) AS REAL) / COALESCE(agg_1, 0) 16 | ) * 100 AS GPM 17 | FROM _t0 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv12_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | cars_2.make, 3 | cars_2.model, 4 | sales.sale_price 5 | FROM main.sales AS sales 6 | JOIN main.cars AS cars 7 | ON cars._id = sales.car_id 8 | JOIN main.inventory_snapshots AS inventory_snapshots 9 | ON cars._id = inventory_snapshots.car_id 10 | AND inventory_snapshots.is_in_inventory = 0 11 | AND inventory_snapshots.snapshot_date = sales.sale_date 12 | JOIN main.cars AS cars_2 13 | ON cars_2._id = inventory_snapshots.car_id 14 | ORDER BY 15 | sale_price DESC 16 | LIMIT 1 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv12_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | cars_2.make, 3 | cars_2.model, 4 | sales.sale_price 5 | FROM main.sales AS sales 6 | JOIN main.cars AS cars 7 | ON cars._id = sales.car_id 8 | JOIN main.inventory_snapshots AS inventory_snapshots 9 | ON cars._id = inventory_snapshots.car_id 10 | AND inventory_snapshots.is_in_inventory = 0 11 | AND inventory_snapshots.snapshot_date = sales.sale_date 12 | JOIN main.cars AS cars_2 13 | ON cars_2._id = inventory_snapshots.car_id 14 | ORDER BY 15 | sale_price DESC 16 | LIMIT 1 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv14_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS TSC 3 | FROM main.sales 4 | WHERE 5 | DATEDIFF(CURRENT_TIMESTAMP(), sale_date, DAY) <= 7 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv14_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS TSC 3 | FROM main.sales 4 | WHERE 5 | CAST(( 6 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(sale_date, 'start of day')) 7 | ) AS INTEGER) <= 7 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv15_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | AVG(sale_price) AS agg_0, 4 | salesperson_id 5 | FROM main.sales 6 | GROUP BY 7 | salesperson_id 8 | ) 9 | SELECT 10 | salespersons.first_name, 11 | salespersons.last_name, 12 | _s1.agg_0 AS ASP 13 | FROM main.salespersons AS salespersons 14 | LEFT JOIN _s1 AS _s1 15 | ON _s1.salesperson_id = salespersons._id 16 | ORDER BY 17 | asp DESC 18 | LIMIT 3 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv15_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | AVG(sale_price) AS agg_0, 4 | salesperson_id 5 | FROM main.sales 6 | GROUP BY 7 | salesperson_id 8 | ) 9 | SELECT 10 | salespersons.first_name, 11 | salespersons.last_name, 12 | _s1.agg_0 AS ASP 13 | FROM main.salespersons AS salespersons 14 | LEFT JOIN _s1 AS _s1 15 | ON _s1.salesperson_id = salespersons._id 16 | ORDER BY 17 | asp DESC 18 | LIMIT 3 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv16_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | salesperson_id 5 | FROM main.sales 6 | GROUP BY 7 | salesperson_id 8 | ) 9 | SELECT 10 | salespersons._id, 11 | salespersons.first_name, 12 | salespersons.last_name, 13 | COALESCE(_s1.agg_0, 0) AS total 14 | FROM main.salespersons AS salespersons 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.salesperson_id = salespersons._id 17 | ORDER BY 18 | total DESC 19 | LIMIT 5 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv16_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | salesperson_id 5 | FROM main.sales 6 | GROUP BY 7 | salesperson_id 8 | ) 9 | SELECT 10 | salespersons._id, 11 | salespersons.first_name, 12 | salespersons.last_name, 13 | COALESCE(_s1.agg_0, 0) AS total 14 | FROM main.salespersons AS salespersons 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.salesperson_id = salespersons._id 17 | ORDER BY 18 | total DESC 19 | LIMIT 5 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS num_sales, 4 | salesperson_id 5 | FROM main.sales 6 | WHERE 7 | DATEDIFF(CURRENT_TIMESTAMP(), sale_date, DAY) <= 30 8 | GROUP BY 9 | salesperson_id 10 | ) 11 | SELECT 12 | salespersons._id, 13 | salespersons.first_name, 14 | salespersons.last_name, 15 | _s1.num_sales 16 | FROM main.salespersons AS salespersons 17 | JOIN _s1 AS _s1 18 | ON _s1.salesperson_id = salespersons._id 19 | ORDER BY 20 | num_sales DESC 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS num_sales, 4 | salesperson_id 5 | FROM main.sales 6 | WHERE 7 | CAST(( 8 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(sale_date, 'start of day')) 9 | ) AS INTEGER) <= 30 10 | GROUP BY 11 | salesperson_id 12 | ) 13 | SELECT 14 | salespersons._id, 15 | salespersons.first_name, 16 | salespersons.last_name, 17 | _s1.num_sales 18 | FROM main.salespersons AS salespersons 19 | JOIN _s1 AS _s1 20 | ON _s1.salesperson_id = salespersons._id 21 | ORDER BY 22 | num_sales DESC 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | car_id 5 | FROM main.sales 6 | GROUP BY 7 | car_id 8 | ) 9 | SELECT 10 | cars.make, 11 | cars.model, 12 | COALESCE(_s1.agg_0, 0) AS num_sales 13 | FROM main.cars AS cars 14 | LEFT JOIN _s1 AS _s1 15 | ON _s1.car_id = cars._id 16 | WHERE 17 | LOWER(cars.vin_number) LIKE '%m5%' 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv3_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | car_id 5 | FROM main.sales 6 | GROUP BY 7 | car_id 8 | ) 9 | SELECT 10 | cars.make, 11 | cars.model, 12 | COALESCE(_s1.agg_0, 0) AS num_sales 13 | FROM main.cars AS cars 14 | LEFT JOIN _s1 AS _s1 15 | ON _s1.car_id = cars._id 16 | WHERE 17 | LOWER(cars.vin_number) LIKE '%m5%' 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sale_price) AS agg_1, 5 | car_id 6 | FROM main.sales 7 | WHERE 8 | sale_date >= DATE_ADD(CURRENT_TIMESTAMP(), -30, 'DAY') 9 | GROUP BY 10 | car_id 11 | ) 12 | SELECT 13 | COALESCE(_s1.agg_0, 0) AS num_sales, 14 | CASE 15 | WHEN ( 16 | NOT _s1.agg_0 IS NULL AND _s1.agg_0 > 0 17 | ) 18 | THEN COALESCE(_s1.agg_1, 0) 19 | ELSE NULL 20 | END AS total_revenue 21 | FROM main.cars AS cars 22 | LEFT JOIN _s1 AS _s1 23 | ON _s1.car_id = cars._id 24 | WHERE 25 | LOWER(cars.make) LIKE '%toyota%' 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sale_price) AS agg_1, 5 | car_id 6 | FROM main.sales 7 | WHERE 8 | sale_date >= DATETIME('now', '-30 day') 9 | GROUP BY 10 | car_id 11 | ) 12 | SELECT 13 | COALESCE(_s1.agg_0, 0) AS num_sales, 14 | CASE 15 | WHEN ( 16 | NOT _s1.agg_0 IS NULL AND _s1.agg_0 > 0 17 | ) 18 | THEN COALESCE(_s1.agg_1, 0) 19 | ELSE NULL 20 | END AS total_revenue 21 | FROM main.cars AS cars 22 | LEFT JOIN _s1 AS _s1 23 | ON _s1.car_id = cars._id 24 | WHERE 25 | LOWER(cars.make) LIKE '%toyota%' 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv5_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sale_price) AS agg_1, 5 | salesperson_id 6 | FROM main.sales 7 | GROUP BY 8 | salesperson_id 9 | ) 10 | SELECT 11 | salespersons.first_name, 12 | salespersons.last_name, 13 | COALESCE(_s1.agg_1, 0) AS total_sales, 14 | _s1.agg_0 AS num_sales, 15 | RANK() OVER (ORDER BY COALESCE(_s1.agg_1, 0) DESC NULLS FIRST) AS sales_rank 16 | FROM main.salespersons AS salespersons 17 | JOIN _s1 AS _s1 18 | ON _s1.salesperson_id = salespersons._id 19 | ORDER BY 20 | COALESCE(_s1.agg_1, 0) DESC 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv5_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(sale_price) AS agg_1, 5 | salesperson_id 6 | FROM main.sales 7 | GROUP BY 8 | salesperson_id 9 | ) 10 | SELECT 11 | salespersons.first_name, 12 | salespersons.last_name, 13 | COALESCE(_s1.agg_1, 0) AS total_sales, 14 | _s1.agg_0 AS num_sales, 15 | RANK() OVER (ORDER BY COALESCE(_s1.agg_1, 0) DESC) AS sales_rank 16 | FROM main.salespersons AS salespersons 17 | JOIN _s1 AS _s1 18 | ON _s1.salesperson_id = salespersons._id 19 | ORDER BY 20 | COALESCE(_s1.agg_1, 0) DESC 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | car_id 4 | FROM main.inventory_snapshots 5 | QUALIFY 6 | NOT is_in_inventory 7 | AND ROW_NUMBER() OVER (PARTITION BY car_id ORDER BY snapshot_date DESC NULLS FIRST) = 1 8 | ), _s3 AS ( 9 | SELECT 10 | MAX(sale_price) AS agg_0, 11 | car_id 12 | FROM main.sales 13 | GROUP BY 14 | car_id 15 | ) 16 | SELECT 17 | cars.make, 18 | cars.model, 19 | _s3.agg_0 AS highest_sale_price 20 | FROM main.cars AS cars 21 | JOIN _t1 AS _t1 22 | ON _t1.car_id = cars._id 23 | LEFT JOIN _s3 AS _s3 24 | ON _s3.car_id = cars._id 25 | ORDER BY 26 | _s3.agg_0 DESC 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t AS ( 2 | SELECT 3 | car_id, 4 | is_in_inventory, 5 | ROW_NUMBER() OVER (PARTITION BY car_id ORDER BY snapshot_date DESC) AS _w 6 | FROM main.inventory_snapshots 7 | ), _s3 AS ( 8 | SELECT 9 | MAX(sale_price) AS agg_0, 10 | car_id 11 | FROM main.sales 12 | GROUP BY 13 | car_id 14 | ) 15 | SELECT 16 | cars.make, 17 | cars.model, 18 | _s3.agg_0 AS highest_sale_price 19 | FROM main.cars AS cars 20 | JOIN _t AS _t 21 | ON NOT _t.is_in_inventory AND _t._w = 1 AND _t.car_id = cars._id 22 | LEFT JOIN _s3 AS _s3 23 | ON _s3.car_id = cars._id 24 | ORDER BY 25 | _s3.agg_0 DESC 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv7_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | AVG(sale_price) AS agg_0, 4 | car_id 5 | FROM main.sales 6 | GROUP BY 7 | car_id 8 | ) 9 | SELECT 10 | cars.make, 11 | cars.model, 12 | cars.year, 13 | cars.color, 14 | cars.vin_number, 15 | _s1.agg_0 AS avg_sale_price 16 | FROM main.cars AS cars 17 | LEFT JOIN _s1 AS _s1 18 | ON _s1.car_id = cars._id 19 | WHERE 20 | LOWER(cars.make) LIKE '%fords%' OR LOWER(cars.model) LIKE '%mustang%' 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv7_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | AVG(sale_price) AS agg_0, 4 | car_id 5 | FROM main.sales 6 | GROUP BY 7 | car_id 8 | ) 9 | SELECT 10 | cars.make, 11 | cars.model, 12 | cars.year, 13 | cars.color, 14 | cars.vin_number, 15 | _s1.agg_0 AS avg_sale_price 16 | FROM main.cars AS cars 17 | LEFT JOIN _s1 AS _s1 18 | ON _s1.car_id = cars._id 19 | WHERE 20 | LOWER(cars.make) LIKE '%fords%' OR LOWER(cars.model) LIKE '%mustang%' 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv9_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | AVG(sale_price) AS ASP 3 | FROM main.sales 4 | WHERE 5 | sale_date <= '2023-03-31' AND sale_date >= '2023-01-01' 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_adv9_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | AVG(sale_price) AS ASP 3 | FROM main.sales 4 | WHERE 5 | sale_date <= '2023-03-31' AND sale_date >= '2023-01-01' 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic10_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | COUNT() AS agg_1, 5 | salesperson_id 6 | FROM main.sales 7 | WHERE 8 | sale_date >= DATE_ADD(CURRENT_TIMESTAMP(), -3, 'MONTH') 9 | GROUP BY 10 | salesperson_id 11 | ) 12 | SELECT 13 | salespersons.first_name, 14 | salespersons.last_name, 15 | COALESCE(_s1.agg_1, 0) AS total_sales, 16 | COALESCE(_s1.agg_0, 0) AS total_revenue 17 | FROM main.salespersons AS salespersons 18 | LEFT JOIN _s1 AS _s1 19 | ON _s1.salesperson_id = salespersons._id 20 | ORDER BY 21 | total_revenue DESC 22 | LIMIT 3 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic10_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | COUNT() AS agg_1, 5 | salesperson_id 6 | FROM main.sales 7 | WHERE 8 | sale_date >= DATETIME('now', '-3 month') 9 | GROUP BY 10 | salesperson_id 11 | ) 12 | SELECT 13 | salespersons.first_name, 14 | salespersons.last_name, 15 | COALESCE(_s1.agg_1, 0) AS total_sales, 16 | COALESCE(_s1.agg_0, 0) AS total_revenue 17 | FROM main.salespersons AS salespersons 18 | LEFT JOIN _s1 AS _s1 19 | ON _s1.salesperson_id = salespersons._id 20 | ORDER BY 21 | total_revenue DESC 22 | LIMIT 3 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic1_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sales.car_id AS car_id 4 | FROM main.sales AS sales 5 | ), _s0 AS ( 6 | SELECT 7 | cars._id AS _id, 8 | cars.make AS make, 9 | cars.model AS model, 10 | cars.year AS year 11 | FROM main.cars AS cars 12 | ) 13 | SELECT 14 | _s0._id AS _id, 15 | _s0.make AS make, 16 | _s0.model AS model, 17 | _s0.year AS year 18 | FROM _s0 AS _s0 19 | WHERE 20 | NOT EXISTS( 21 | SELECT 22 | 1 AS "1" 23 | FROM _s1 AS _s1 24 | WHERE 25 | _s0._id = _s1.car_id 26 | ) 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic1_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sales.car_id AS car_id 4 | FROM main.sales AS sales 5 | ), _s0 AS ( 6 | SELECT 7 | cars._id AS _id, 8 | cars.make AS make, 9 | cars.model AS model, 10 | cars.year AS year 11 | FROM main.cars AS cars 12 | ) 13 | SELECT 14 | _s0._id AS _id, 15 | _s0.make AS make, 16 | _s0.model AS model, 17 | _s0.year AS year 18 | FROM _s0 AS _s0 19 | WHERE 20 | NOT EXISTS( 21 | SELECT 22 | 1 AS "1" 23 | FROM _s1 AS _s1 24 | WHERE 25 | _s0._id = _s1.car_id 26 | ) 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sales.customer_id AS customer_id 4 | FROM main.sales AS sales 5 | ), _s0 AS ( 6 | SELECT 7 | customers._id AS _id 8 | FROM main.customers AS customers 9 | ) 10 | SELECT 11 | _s0._id AS _id 12 | FROM _s0 AS _s0 13 | WHERE 14 | EXISTS( 15 | SELECT 16 | 1 AS "1" 17 | FROM _s1 AS _s1 18 | WHERE 19 | _s0._id = _s1.customer_id 20 | ) 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sales.customer_id AS customer_id 4 | FROM main.sales AS sales 5 | ), _s0 AS ( 6 | SELECT 7 | customers._id AS _id 8 | FROM main.customers AS customers 9 | ) 10 | SELECT 11 | _s0._id AS _id 12 | FROM _s0 AS _s0 13 | WHERE 14 | EXISTS( 15 | SELECT 16 | 1 AS "1" 17 | FROM _s1 AS _s1 18 | WHERE 19 | _s0._id = _s1.customer_id 20 | ) 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sales.salesperson_id AS salesperson_id 4 | FROM main.sales AS sales 5 | ), _s0 AS ( 6 | SELECT 7 | salespersons._id AS _id, 8 | salespersons.first_name AS first_name, 9 | salespersons.last_name AS last_name 10 | FROM main.salespersons AS salespersons 11 | ) 12 | SELECT 13 | _s0._id AS _id, 14 | _s0.first_name AS first_name, 15 | _s0.last_name AS last_name 16 | FROM _s0 AS _s0 17 | WHERE 18 | NOT EXISTS( 19 | SELECT 20 | 1 AS "1" 21 | FROM _s1 AS _s1 22 | WHERE 23 | _s0._id = _s1.salesperson_id 24 | ) 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | sales.salesperson_id AS salesperson_id 4 | FROM main.sales AS sales 5 | ), _s0 AS ( 6 | SELECT 7 | salespersons._id AS _id, 8 | salespersons.first_name AS first_name, 9 | salespersons.last_name AS last_name 10 | FROM main.salespersons AS salespersons 11 | ) 12 | SELECT 13 | _s0._id AS _id, 14 | _s0.first_name AS first_name, 15 | _s0.last_name AS last_name 16 | FROM _s0 AS _s0 17 | WHERE 18 | NOT EXISTS( 19 | SELECT 20 | 1 AS "1" 21 | FROM _s1 AS _s1 22 | WHERE 23 | _s0._id = _s1.salesperson_id 24 | ) 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic5_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | COUNT() AS agg_1, 5 | salesperson_id 6 | FROM main.sales 7 | WHERE 8 | DATEDIFF(CURRENT_TIMESTAMP(), sale_date, DAY) <= 30 9 | GROUP BY 10 | salesperson_id 11 | ) 12 | SELECT 13 | salespersons.first_name, 14 | salespersons.last_name, 15 | _t0.agg_1 AS total_sales, 16 | COALESCE(_t0.agg_0, 0) AS total_revenue 17 | FROM main.salespersons AS salespersons 18 | JOIN _t0 AS _t0 19 | ON _t0.salesperson_id = salespersons._id 20 | ORDER BY 21 | total_sales DESC 22 | LIMIT 5 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic5_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | COUNT() AS agg_1, 5 | salesperson_id 6 | FROM main.sales 7 | WHERE 8 | CAST(( 9 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(sale_date, 'start of day')) 10 | ) AS INTEGER) <= 30 11 | GROUP BY 12 | salesperson_id 13 | ) 14 | SELECT 15 | salespersons.first_name, 16 | salespersons.last_name, 17 | _t0.agg_1 AS total_sales, 18 | COALESCE(_t0.agg_0, 0) AS total_revenue 19 | FROM main.salespersons AS salespersons 20 | JOIN _t0 AS _t0 21 | ON _t0.salesperson_id = salespersons._id 22 | ORDER BY 23 | total_sales DESC 24 | LIMIT 5 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(sales.sale_price) AS agg_0, 4 | COUNT(DISTINCT sales.customer_id) AS agg_1, 5 | customers.state 6 | FROM main.customers AS customers 7 | JOIN main.sales AS sales 8 | ON customers._id = sales.customer_id 9 | GROUP BY 10 | customers.state 11 | ) 12 | SELECT 13 | state, 14 | COALESCE(agg_1, 0) AS unique_customers, 15 | COALESCE(agg_0, 0) AS total_revenue 16 | FROM _t1 17 | ORDER BY 18 | total_revenue DESC 19 | LIMIT 5 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(sales.sale_price) AS agg_0, 4 | COUNT(DISTINCT sales.customer_id) AS agg_1, 5 | customers.state 6 | FROM main.customers AS customers 7 | JOIN main.sales AS sales 8 | ON customers._id = sales.customer_id 9 | GROUP BY 10 | customers.state 11 | ) 12 | SELECT 13 | state, 14 | COALESCE(agg_1, 0) AS unique_customers, 15 | COALESCE(agg_0, 0) AS total_revenue 16 | FROM _t1 17 | ORDER BY 18 | total_revenue DESC 19 | LIMIT 5 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic7_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(payment_amount) AS agg_0, 4 | COUNT() AS agg_1, 5 | payment_method 6 | FROM main.payments_received 7 | GROUP BY 8 | payment_method 9 | ) 10 | SELECT 11 | payment_method, 12 | COALESCE(agg_1, 0) AS total_payments, 13 | COALESCE(agg_0, 0) AS total_amount 14 | FROM _t1 15 | ORDER BY 16 | total_amount DESC 17 | LIMIT 3 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic7_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(payment_amount) AS agg_0, 4 | COUNT() AS agg_1, 5 | payment_method 6 | FROM main.payments_received 7 | GROUP BY 8 | payment_method 9 | ) 10 | SELECT 11 | payment_method, 12 | COALESCE(agg_1, 0) AS total_payments, 13 | COALESCE(agg_0, 0) AS total_amount 14 | FROM _t1 15 | ORDER BY 16 | total_amount DESC 17 | LIMIT 3 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic8_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | COUNT() AS agg_1, 5 | car_id 6 | FROM main.sales 7 | GROUP BY 8 | car_id 9 | ) 10 | SELECT 11 | cars.make, 12 | cars.model, 13 | COALESCE(_s1.agg_1, 0) AS total_sales, 14 | COALESCE(_s1.agg_0, 0) AS total_revenue 15 | FROM main.cars AS cars 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.car_id = cars._id 18 | ORDER BY 19 | total_revenue DESC 20 | LIMIT 5 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic8_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(sale_price) AS agg_0, 4 | COUNT() AS agg_1, 5 | car_id 6 | FROM main.sales 7 | GROUP BY 8 | car_id 9 | ) 10 | SELECT 11 | cars.make, 12 | cars.model, 13 | COALESCE(_s1.agg_1, 0) AS total_sales, 14 | COALESCE(_s1.agg_0, 0) AS total_revenue 15 | FROM main.cars AS cars 16 | LEFT JOIN _s1 AS _s1 17 | ON _s1.car_id = cars._id 18 | ORDER BY 19 | total_revenue DESC 20 | LIMIT 5 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic9_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | state 5 | FROM main.customers 6 | GROUP BY 7 | state 8 | ) 9 | SELECT 10 | state, 11 | COALESCE(agg_0, 0) AS total_signups 12 | FROM _t1 13 | ORDER BY 14 | total_signups DESC 15 | LIMIT 2 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_basic9_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | state 5 | FROM main.customers 6 | GROUP BY 7 | state 8 | ) 9 | SELECT 10 | state, 11 | COALESCE(agg_0, 0) AS total_signups 12 | FROM _t1 13 | ORDER BY 14 | total_signups DESC 15 | LIMIT 2 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen1_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | first_name, 3 | last_name, 4 | phone, 5 | DATEDIFF(termination_date, hire_date, DAY) * 1.0 AS days_employed 6 | FROM main.salespersons 7 | WHERE 8 | NOT termination_date IS NULL 9 | ORDER BY 10 | days_employed 11 | LIMIT 1 12 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen1_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | first_name, 3 | last_name, 4 | phone, 5 | CAST(( 6 | JULIANDAY(DATE(termination_date, 'start of day')) - JULIANDAY(DATE(hire_date, 'start of day')) 7 | ) AS INTEGER) * 1.0 AS days_employed 8 | FROM main.salespersons 9 | WHERE 10 | NOT termination_date IS NULL 11 | ORDER BY 12 | days_employed 13 | LIMIT 1 14 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen2_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS weekend_payments 3 | FROM main.payments_made 4 | WHERE 5 | ( 6 | ( 7 | DAY_OF_WEEK(payment_date) + 6 8 | ) % 7 9 | ) IN (5, 6) 10 | AND vendor_name = 'Utility Company' 11 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen2_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS weekend_payments 3 | FROM main.payments_made 4 | WHERE 5 | ( 6 | ( 7 | CAST(STRFTIME('%w', payment_date) AS INTEGER) + 6 8 | ) % 7 9 | ) IN (5, 6) 10 | AND vendor_name = 'Utility Company' 11 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(payment_amount) AS agg_0, 4 | payment_date, 5 | payment_method 6 | FROM main.payments_received 7 | WHERE 8 | DATEDIFF(CURRENT_TIMESTAMP(), payment_date, WEEK) = 1 9 | GROUP BY 10 | payment_date, 11 | payment_method 12 | ) 13 | SELECT 14 | payment_date, 15 | payment_method, 16 | COALESCE(agg_0, 0) AS total_amount 17 | FROM _t0 18 | ORDER BY 19 | payment_date DESC, 20 | payment_method 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(sales.sale_price) AS agg_0, 4 | customers.state AS customer_state, 5 | DATE_TRUNC('QUARTER', CAST(sales.sale_date AS TIMESTAMP)) AS quarter 6 | FROM main.sales AS sales 7 | LEFT JOIN main.customers AS customers 8 | ON customers._id = sales.customer_id 9 | WHERE 10 | EXTRACT(YEAR FROM sales.sale_date) = 2023 11 | GROUP BY 12 | customers.state, 13 | DATE_TRUNC('QUARTER', CAST(sales.sale_date AS TIMESTAMP)) 14 | ) 15 | SELECT 16 | quarter, 17 | customer_state, 18 | COALESCE(agg_0, 0) AS total_sales 19 | FROM _t1 20 | WHERE 21 | NOT agg_0 IS NULL AND agg_0 > 0 22 | ORDER BY 23 | quarter, 24 | customer_state 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen5_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | car_id 4 | FROM main.inventory_snapshots 5 | WHERE 6 | snapshot_date <= '2023-03-31' AND snapshot_date >= '2023-03-01' 7 | QUALIFY 8 | RANK() OVER (ORDER BY snapshot_date DESC NULLS FIRST) = 1 AND is_in_inventory 9 | ) 10 | SELECT 11 | cars._id, 12 | cars.make, 13 | cars.model, 14 | cars.year 15 | FROM _t0 AS _t0 16 | JOIN main.cars AS cars 17 | ON _t0.car_id = cars._id 18 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_dealership_gen5_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t AS ( 2 | SELECT 3 | car_id, 4 | is_in_inventory, 5 | RANK() OVER (ORDER BY snapshot_date DESC) AS _w 6 | FROM main.inventory_snapshots 7 | WHERE 8 | snapshot_date <= '2023-03-31' AND snapshot_date >= '2023-03-01' 9 | ) 10 | SELECT 11 | cars._id, 12 | cars.make, 13 | cars.model, 14 | cars.year 15 | FROM _t AS _t 16 | JOIN main.cars AS cars 17 | ON _t.car_id = cars._id 18 | WHERE 19 | _t._w = 1 AND _t.is_in_inventory 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv10_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS total_transactions, 4 | sender_id 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | sender_type = 0 8 | GROUP BY 9 | sender_id 10 | ) 11 | SELECT 12 | users.uid AS user_id, 13 | _s1.total_transactions 14 | FROM main.users AS users 15 | JOIN _s1 AS _s1 16 | ON _s1.sender_id = users.uid 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv10_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS total_transactions, 4 | sender_id 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | sender_type = 0 8 | GROUP BY 9 | sender_id 10 | ) 11 | SELECT 12 | users.uid AS user_id, 13 | _s1.total_transactions 14 | FROM main.users AS users 15 | JOIN _s1 AS _s1 16 | ON _s1.sender_id = users.uid 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv11_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(DATEDIFF(session_end_ts, session_start_ts, SECOND)) AS agg_0, 4 | user_id 5 | FROM main.user_sessions 6 | WHERE 7 | session_end_ts < '2023-06-08' AND session_start_ts >= '2023-06-01' 8 | GROUP BY 9 | user_id 10 | ) 11 | SELECT 12 | users.uid, 13 | COALESCE(_t0.agg_0, 0) AS total_duration 14 | FROM main.users AS users 15 | JOIN _t0 AS _t0 16 | ON _t0.user_id = users.uid 17 | ORDER BY 18 | total_duration DESC 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv12_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(amount) AS agg_0, 4 | coupon_id 5 | FROM main.wallet_transactions_daily 6 | GROUP BY 7 | coupon_id 8 | ) 9 | SELECT 10 | coupons.cid AS coupon_id, 11 | COALESCE(_s1.agg_0, 0) AS total_discount 12 | FROM main.coupons AS coupons 13 | LEFT JOIN _s1 AS _s1 14 | ON _s1.coupon_id = coupons.cid 15 | WHERE 16 | coupons.merchant_id = '1' 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv12_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(amount) AS agg_0, 4 | coupon_id 5 | FROM main.wallet_transactions_daily 6 | GROUP BY 7 | coupon_id 8 | ) 9 | SELECT 10 | coupons.cid AS coupon_id, 11 | COALESCE(_s1.agg_0, 0) AS total_discount 12 | FROM main.coupons AS coupons 13 | LEFT JOIN _s1 AS _s1 14 | ON _s1.coupon_id = coupons.cid 15 | WHERE 16 | coupons.merchant_id = '1' 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv13_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS TUC 3 | FROM main.user_sessions 4 | WHERE 5 | session_start_ts >= DATE_TRUNC('DAY', DATE_ADD(CURRENT_TIMESTAMP(), -1, 'MONTH')) 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv13_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT() AS TUC 3 | FROM main.user_sessions 4 | WHERE 5 | session_start_ts >= DATE(DATETIME('now', '-1 month'), 'start of day') 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv14_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(status = 'success') AS agg_0, 4 | COUNT() AS agg_1 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | DATEDIFF(CURRENT_TIMESTAMP(), created_at, MONTH) = 1 8 | ) 9 | SELECT 10 | COALESCE(agg_0, 0) / agg_1 AS _expr0 11 | FROM _t0 12 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv14_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(status = 'success') AS agg_0, 4 | COUNT() AS agg_1 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | ( 8 | ( 9 | CAST(STRFTIME('%Y', DATETIME('now')) AS INTEGER) - CAST(STRFTIME('%Y', created_at) AS INTEGER) 10 | ) * 12 + CAST(STRFTIME('%m', DATETIME('now')) AS INTEGER) - CAST(STRFTIME('%m', created_at) AS INTEGER) 11 | ) = 1 12 | ) 13 | SELECT 14 | CAST(COALESCE(agg_0, 0) AS REAL) / agg_1 AS _expr0 15 | FROM _t0 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv15_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | coupons.merchant_id 5 | FROM main.coupons AS coupons 6 | LEFT JOIN main.merchants AS merchants 7 | ON coupons.merchant_id = merchants.mid 8 | WHERE 9 | DATEDIFF(coupons.created_at, merchants.created_at, MONTH) = 0 10 | GROUP BY 11 | coupons.merchant_id 12 | ) 13 | SELECT 14 | merchants.mid AS merchant_id, 15 | merchants.name AS merchant_name, 16 | COALESCE(_s3.agg_0, 0) AS coupons_per_merchant 17 | FROM main.merchants AS merchants 18 | LEFT JOIN _s3 AS _s3 19 | ON _s3.merchant_id = merchants.mid 20 | ORDER BY 21 | coupons_per_merchant DESC 22 | LIMIT 1 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv16_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS total_unread_notifs, 4 | user_id 5 | FROM main.notifications 6 | WHERE 7 | status = 'unread' AND type = 'promotion' 8 | GROUP BY 9 | user_id 10 | ) 11 | SELECT 12 | users.username, 13 | _s1.total_unread_notifs 14 | FROM main.users AS users 15 | JOIN _s1 AS _s1 16 | ON _s1.user_id = users.uid 17 | WHERE 18 | LOWER(users.country) = 'us' 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv16_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS total_unread_notifs, 4 | user_id 5 | FROM main.notifications 6 | WHERE 7 | status = 'unread' AND type = 'promotion' 8 | GROUP BY 9 | user_id 10 | ) 11 | SELECT 12 | users.username, 13 | _s1.total_unread_notifs 14 | FROM main.users AS users 15 | JOIN _s1 AS _s1 16 | ON _s1.user_id = users.uid 17 | WHERE 18 | LOWER(users.country) = 'us' 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv1_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT(DISTINCT coupon_id) AS agg_0, 4 | COUNT(DISTINCT txid) AS agg_1, 5 | receiver_id 6 | FROM main.wallet_transactions_daily 7 | WHERE 8 | status = 'success' 9 | GROUP BY 10 | receiver_id 11 | ) 12 | SELECT 13 | merchants.name, 14 | ( 15 | _t0.agg_0 * 1.0 16 | ) / _t0.agg_1 AS CPUR 17 | FROM main.merchants AS merchants 18 | JOIN _t0 AS _t0 19 | ON _t0.receiver_id = merchants.mid 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv1_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT(DISTINCT coupon_id) AS agg_0, 4 | COUNT(DISTINCT txid) AS agg_1, 5 | receiver_id 6 | FROM main.wallet_transactions_daily 7 | WHERE 8 | status = 'success' 9 | GROUP BY 10 | receiver_id 11 | ) 12 | SELECT 13 | merchants.name, 14 | CAST(( 15 | _t0.agg_0 * 1.0 16 | ) AS REAL) / _t0.agg_1 AS CPUR 17 | FROM main.merchants AS merchants 18 | JOIN _t0 AS _t0 19 | ON _t0.receiver_id = merchants.mid 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS total_coupons, 4 | merchant_id 5 | FROM main.coupons 6 | GROUP BY 7 | merchant_id 8 | ) 9 | SELECT 10 | merchants.name AS merchant_name, 11 | _s1.total_coupons 12 | FROM main.merchants AS merchants 13 | JOIN _s1 AS _s1 14 | ON _s1.merchant_id = merchants.mid 15 | WHERE 16 | LOWER(merchants.category) LIKE '%%retail%%' AND merchants.status = 'active' 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv3_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS total_coupons, 4 | merchant_id 5 | FROM main.coupons 6 | GROUP BY 7 | merchant_id 8 | ) 9 | SELECT 10 | merchants.name AS merchant_name, 11 | _s1.total_coupons 12 | FROM main.merchants AS merchants 13 | JOIN _s1 AS _s1 14 | ON _s1.merchant_id = merchants.mid 15 | WHERE 16 | LOWER(merchants.category) LIKE '%%retail%%' AND merchants.status = 'active' 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(amount) AS agg_1, 5 | sender_id 6 | FROM main.wallet_transactions_daily 7 | WHERE 8 | DATEDIFF(CURRENT_TIMESTAMP(), created_at, DAY) <= 7 9 | GROUP BY 10 | sender_id 11 | ), _t0 AS ( 12 | SELECT 13 | SUM(_s0.agg_0) AS agg_0, 14 | SUM(_s0.agg_1) AS agg_1 15 | FROM _s0 AS _s0 16 | JOIN main.users AS users 17 | ON _s0.sender_id = users.uid AND users.country = 'US' 18 | ) 19 | SELECT 20 | COALESCE(agg_0, 0) AS num_transactions, 21 | CASE 22 | WHEN ( 23 | NOT agg_0 IS NULL AND agg_0 > 0 24 | ) 25 | THEN COALESCE(agg_1, 0) 26 | ELSE NULL 27 | END AS total_amount 28 | FROM _t0 29 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | SUM(amount) AS agg_1, 5 | sender_id 6 | FROM main.wallet_transactions_daily 7 | WHERE 8 | CAST(( 9 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(created_at, 'start of day')) 10 | ) AS INTEGER) <= 7 11 | GROUP BY 12 | sender_id 13 | ), _t0 AS ( 14 | SELECT 15 | SUM(_s0.agg_0) AS agg_0, 16 | SUM(_s0.agg_1) AS agg_1 17 | FROM _s0 AS _s0 18 | JOIN main.users AS users 19 | ON _s0.sender_id = users.uid AND users.country = 'US' 20 | ) 21 | SELECT 22 | COALESCE(agg_0, 0) AS num_transactions, 23 | CASE 24 | WHEN ( 25 | NOT agg_0 IS NULL AND agg_0 > 0 26 | ) 27 | THEN COALESCE(agg_1, 0) 28 | ELSE NULL 29 | END AS total_amount 30 | FROM _t0 31 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv5_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | AVG(balance) AS AMB 3 | FROM main.wallet_user_balance_daily 4 | WHERE 5 | DATEDIFF(CURRENT_TIMESTAMP(), updated_at, DAY) <= 7 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv5_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | AVG(balance) AS AMB 3 | FROM main.wallet_user_balance_daily 4 | WHERE 5 | CAST(( 6 | JULIANDAY(DATE(DATETIME('now'), 'start of day')) - JULIANDAY(DATE(updated_at, 'start of day')) 7 | ) AS INTEGER) <= 7 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | balance, 4 | user_id 5 | FROM main.wallet_user_balance_daily 6 | QUALIFY 7 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY updated_at DESC NULLS FIRST) = 1 8 | ) 9 | SELECT 10 | users.uid AS user_id, 11 | _t0.balance AS latest_balance 12 | FROM main.users AS users 13 | JOIN _t0 AS _t0 14 | ON _t0.user_id = users.uid 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t AS ( 2 | SELECT 3 | balance, 4 | user_id, 5 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY updated_at DESC) AS _w 6 | FROM main.wallet_user_balance_daily 7 | ) 8 | SELECT 9 | users.uid AS user_id, 10 | _t.balance AS latest_balance 11 | FROM main.users AS users 12 | JOIN _t AS _t 13 | ON _t._w = 1 AND _t.user_id = users.uid 14 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv7_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | marketing_opt_in, 4 | user_id 5 | FROM main.user_setting_snapshot 6 | QUALIFY 7 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC NULLS FIRST) = 1 8 | ) 9 | SELECT 10 | users.uid, 11 | _t0.marketing_opt_in 12 | FROM main.users AS users 13 | JOIN _t0 AS _t0 14 | ON _t0.user_id = users.uid 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv7_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t AS ( 2 | SELECT 3 | marketing_opt_in, 4 | user_id, 5 | ROW_NUMBER() OVER (PARTITION BY user_id ORDER BY created_at DESC) AS _w 6 | FROM main.user_setting_snapshot 7 | ) 8 | SELECT 9 | users.uid, 10 | _t.marketing_opt_in 11 | FROM main.users AS users 12 | JOIN _t AS _t 13 | ON _t._w = 1 AND _t.user_id = users.uid 14 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv8_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(amount) AS agg_0, 4 | receiver_id 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | receiver_type = 1 AND status = 'success' 8 | GROUP BY 9 | receiver_id 10 | ) 11 | SELECT 12 | merchants.mid AS merchants_id, 13 | merchants.name AS merchants_name, 14 | merchants.category, 15 | COALESCE(_s1.agg_0, 0) AS total_revenue, 16 | ROW_NUMBER() OVER (ORDER BY COALESCE(_s1.agg_0, 0) DESC NULLS FIRST) AS mrr 17 | FROM main.merchants AS merchants 18 | JOIN _s1 AS _s1 19 | ON _s1.receiver_id = merchants.mid 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv8_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(amount) AS agg_0, 4 | receiver_id 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | receiver_type = 1 AND status = 'success' 8 | GROUP BY 9 | receiver_id 10 | ) 11 | SELECT 12 | merchants.mid AS merchants_id, 13 | merchants.name AS merchants_name, 14 | merchants.category, 15 | COALESCE(_s1.agg_0, 0) AS total_revenue, 16 | ROW_NUMBER() OVER (ORDER BY COALESCE(_s1.agg_0, 0) DESC) AS mrr 17 | FROM main.merchants AS merchants 18 | JOIN _s1 AS _s1 19 | ON _s1.receiver_id = merchants.mid 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv9_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT(DISTINCT sender_id) AS agg_0, 4 | DATE_TRUNC('MONTH', CAST(created_at AS TIMESTAMP)) AS year_month 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | created_at < DATE_TRUNC('MONTH', CURRENT_TIMESTAMP()) 8 | AND created_at >= DATE_ADD(DATE_TRUNC('MONTH', CURRENT_TIMESTAMP()), -2, 'MONTH') 9 | AND sender_type = 0 10 | GROUP BY 11 | DATE_TRUNC('MONTH', CAST(created_at AS TIMESTAMP)) 12 | ) 13 | SELECT 14 | year_month, 15 | COALESCE(agg_0, 0) AS active_users 16 | FROM _t0 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_adv9_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT(DISTINCT sender_id) AS agg_0, 4 | DATE(created_at, 'start of month') AS year_month 5 | FROM main.wallet_transactions_daily 6 | WHERE 7 | created_at < DATE('now', 'start of month') 8 | AND created_at >= DATE('now', 'start of month', '-2 month') 9 | AND sender_type = 0 10 | GROUP BY 11 | DATE(created_at, 'start of month') 12 | ) 13 | SELECT 14 | year_month, 15 | COALESCE(agg_0, 0) AS active_users 16 | FROM _t0 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic10_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(amount) AS agg_0, 4 | COUNT() AS agg_1, 5 | receiver_id 6 | FROM main.wallet_transactions_daily 7 | WHERE 8 | created_at >= DATE_TRUNC('DAY', DATE_ADD(CURRENT_TIMESTAMP(), -150, 'DAY')) 9 | AND receiver_type = 1 10 | GROUP BY 11 | receiver_id 12 | ) 13 | SELECT 14 | merchants.name AS merchant_name, 15 | COALESCE(_s1.agg_1, 0) AS total_transactions, 16 | COALESCE(_s1.agg_0, 0) AS total_amount 17 | FROM main.merchants AS merchants 18 | LEFT JOIN _s1 AS _s1 19 | ON _s1.receiver_id = merchants.mid 20 | ORDER BY 21 | total_amount DESC 22 | LIMIT 2 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic10_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | SUM(amount) AS agg_0, 4 | COUNT() AS agg_1, 5 | receiver_id 6 | FROM main.wallet_transactions_daily 7 | WHERE 8 | created_at >= DATE(DATETIME('now', '-150 day'), 'start of day') 9 | AND receiver_type = 1 10 | GROUP BY 11 | receiver_id 12 | ) 13 | SELECT 14 | merchants.name AS merchant_name, 15 | COALESCE(_s1.agg_1, 0) AS total_transactions, 16 | COALESCE(_s1.agg_0, 0) AS total_amount 17 | FROM main.merchants AS merchants 18 | LEFT JOIN _s1 AS _s1 19 | ON _s1.receiver_id = merchants.mid 20 | ORDER BY 21 | total_amount DESC 22 | LIMIT 2 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic1_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT(DISTINCT wallet_transactions_daily.sender_id) AS agg_0, 4 | DATE_TRUNC('MONTH', CAST(wallet_transactions_daily.created_at AS TIMESTAMP)) AS month 5 | FROM main.wallet_transactions_daily AS wallet_transactions_daily 6 | JOIN main.users AS users 7 | ON users.status = 'active' AND users.uid = wallet_transactions_daily.sender_id 8 | WHERE 9 | EXTRACT(YEAR FROM wallet_transactions_daily.created_at) = 2023 10 | AND wallet_transactions_daily.sender_type = 0 11 | AND wallet_transactions_daily.status = 'success' 12 | GROUP BY 13 | DATE_TRUNC('MONTH', CAST(wallet_transactions_daily.created_at AS TIMESTAMP)) 14 | ) 15 | SELECT 16 | month, 17 | COALESCE(agg_0, 0) AS active_users 18 | FROM _t0 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic1_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT(DISTINCT wallet_transactions_daily.sender_id) AS agg_0, 4 | DATE(wallet_transactions_daily.created_at, 'start of month') AS month 5 | FROM main.wallet_transactions_daily AS wallet_transactions_daily 6 | JOIN main.users AS users 7 | ON users.status = 'active' AND users.uid = wallet_transactions_daily.sender_id 8 | WHERE 9 | CAST(STRFTIME('%Y', wallet_transactions_daily.created_at) AS INTEGER) = 2023 10 | AND wallet_transactions_daily.sender_type = 0 11 | AND wallet_transactions_daily.status = 'success' 12 | GROUP BY 13 | DATE(wallet_transactions_daily.created_at, 'start of month') 14 | ) 15 | SELECT 16 | month, 17 | COALESCE(agg_0, 0) AS active_users 18 | FROM _t0 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | coupons.merchant_id AS merchant_id 4 | FROM main.coupons AS coupons 5 | ), _s0 AS ( 6 | SELECT 7 | merchants.mid AS merchant_id, 8 | merchants.name AS merchant_name, 9 | merchants.mid AS mid 10 | FROM main.merchants AS merchants 11 | ) 12 | SELECT 13 | _s0.merchant_id AS merchant_id, 14 | _s0.merchant_name AS merchant_name 15 | FROM _s0 AS _s0 16 | WHERE 17 | NOT EXISTS( 18 | SELECT 19 | 1 AS "1" 20 | FROM _s1 AS _s1 21 | WHERE 22 | _s0.mid = _s1.merchant_id 23 | ) 24 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | coupons.merchant_id AS merchant_id 4 | FROM main.coupons AS coupons 5 | ), _s0 AS ( 6 | SELECT 7 | merchants.mid AS merchant_id, 8 | merchants.name AS merchant_name, 9 | merchants.mid AS mid 10 | FROM main.merchants AS merchants 11 | ) 12 | SELECT 13 | _s0.merchant_id AS merchant_id, 14 | _s0.merchant_name AS merchant_name 15 | FROM _s0 AS _s0 16 | WHERE 17 | NOT EXISTS( 18 | SELECT 19 | 1 AS "1" 20 | FROM _s1 AS _s1 21 | WHERE 22 | _s0.mid = _s1.merchant_id 23 | ) 24 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic3_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | wallet_transactions_daily.receiver_id AS receiver_id, 4 | wallet_transactions_daily.receiver_type AS receiver_type 5 | FROM main.wallet_transactions_daily AS wallet_transactions_daily 6 | WHERE 7 | wallet_transactions_daily.receiver_type = 1 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.receiver_id AS receiver_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | merchants.mid AS merchant, 15 | merchants.mid AS mid 16 | FROM main.merchants AS merchants 17 | ) 18 | SELECT 19 | _s0.merchant AS merchant 20 | FROM _s0 AS _s0 21 | WHERE 22 | EXISTS( 23 | SELECT 24 | 1 AS "1" 25 | FROM _s1 AS _s1 26 | WHERE 27 | _s0.mid = _s1.receiver_id 28 | ) 29 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic3_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | wallet_transactions_daily.receiver_id AS receiver_id, 4 | wallet_transactions_daily.receiver_type AS receiver_type 5 | FROM main.wallet_transactions_daily AS wallet_transactions_daily 6 | WHERE 7 | wallet_transactions_daily.receiver_type = 1 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.receiver_id AS receiver_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | merchants.mid AS merchant, 15 | merchants.mid AS mid 16 | FROM main.merchants AS merchants 17 | ) 18 | SELECT 19 | _s0.merchant AS merchant 20 | FROM _s0 AS _s0 21 | WHERE 22 | EXISTS( 23 | SELECT 24 | 1 AS "1" 25 | FROM _s1 AS _s1 26 | WHERE 27 | _s0.mid = _s1.receiver_id 28 | ) 29 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic4_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | notifications.type AS notification_type, 4 | notifications.user_id AS user_id 5 | FROM main.notifications AS notifications 6 | WHERE 7 | notifications.type = 'transaction' 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.user_id AS user_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | users.uid AS uid, 15 | users.uid AS user_id 16 | FROM main.users AS users 17 | ) 18 | SELECT 19 | _s0.user_id AS user_id 20 | FROM _s0 AS _s0 21 | WHERE 22 | EXISTS( 23 | SELECT 24 | 1 AS "1" 25 | FROM _s1 AS _s1 26 | WHERE 27 | _s0.uid = _s1.user_id 28 | ) 29 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic4_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | notifications.type AS notification_type, 4 | notifications.user_id AS user_id 5 | FROM main.notifications AS notifications 6 | WHERE 7 | notifications.type = 'transaction' 8 | ), _s1 AS ( 9 | SELECT 10 | _t0.user_id AS user_id 11 | FROM _t0 AS _t0 12 | ), _s0 AS ( 13 | SELECT 14 | users.uid AS uid, 15 | users.uid AS user_id 16 | FROM main.users AS users 17 | ) 18 | SELECT 19 | _s0.user_id AS user_id 20 | FROM _s0 AS _s0 21 | WHERE 22 | EXISTS( 23 | SELECT 24 | 1 AS "1" 25 | FROM _s1 AS _s1 26 | WHERE 27 | _s0.uid = _s1.user_id 28 | ) 29 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic5_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | notifications.user_id AS user_id 4 | FROM main.notifications AS notifications 5 | ), _s0 AS ( 6 | SELECT 7 | users.uid AS uid, 8 | users.username AS username 9 | FROM main.users AS users 10 | ) 11 | SELECT 12 | _s0.uid AS uid, 13 | _s0.username AS username 14 | FROM _s0 AS _s0 15 | WHERE 16 | NOT EXISTS( 17 | SELECT 18 | 1 AS "1" 19 | FROM _s1 AS _s1 20 | WHERE 21 | _s0.uid = _s1.user_id 22 | ) 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic5_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | notifications.user_id AS user_id 4 | FROM main.notifications AS notifications 5 | ), _s0 AS ( 6 | SELECT 7 | users.uid AS uid, 8 | users.username AS username 9 | FROM main.users AS users 10 | ) 11 | SELECT 12 | _s0.uid AS uid, 13 | _s0.username AS username 14 | FROM _s0 AS _s0 15 | WHERE 16 | NOT EXISTS( 17 | SELECT 18 | 1 AS "1" 19 | FROM _s1 AS _s1 20 | WHERE 21 | _s0.uid = _s1.user_id 22 | ) 23 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | device_type 5 | FROM main.user_sessions 6 | GROUP BY 7 | device_type 8 | ) 9 | SELECT 10 | device_type, 11 | COALESCE(agg_0, 0) AS count 12 | FROM _t1 13 | ORDER BY 14 | count DESC 15 | LIMIT 2 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | device_type 5 | FROM main.user_sessions 6 | GROUP BY 7 | device_type 8 | ) 9 | SELECT 10 | device_type, 11 | COALESCE(agg_0, 0) AS count 12 | FROM _t1 13 | ORDER BY 14 | count DESC 15 | LIMIT 2 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic7_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | status 5 | FROM main.wallet_transactions_daily 6 | GROUP BY 7 | status 8 | ) 9 | SELECT 10 | status, 11 | COALESCE(agg_0, 0) AS count 12 | FROM _t1 13 | ORDER BY 14 | count DESC 15 | LIMIT 3 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic7_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | status 5 | FROM main.wallet_transactions_daily 6 | GROUP BY 7 | status 8 | ) 9 | SELECT 10 | status, 11 | COALESCE(agg_0, 0) AS count 12 | FROM _t1 13 | ORDER BY 14 | count DESC 15 | LIMIT 3 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic8_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT(txid) AS agg_0, 4 | SUM(amount) AS agg_1, 5 | coupon_id 6 | FROM main.wallet_transactions_daily 7 | GROUP BY 8 | coupon_id 9 | ) 10 | SELECT 11 | coupons.code AS coupon_code, 12 | COALESCE(_s1.agg_0, 0) AS redemption_count, 13 | COALESCE(_s1.agg_1, 0) AS total_discount 14 | FROM main.coupons AS coupons 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.coupon_id = coupons.cid 17 | ORDER BY 18 | redemption_count DESC 19 | LIMIT 3 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic8_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT(txid) AS agg_0, 4 | SUM(amount) AS agg_1, 5 | coupon_id 6 | FROM main.wallet_transactions_daily 7 | GROUP BY 8 | coupon_id 9 | ) 10 | SELECT 11 | coupons.code AS coupon_code, 12 | COALESCE(_s1.agg_0, 0) AS redemption_count, 13 | COALESCE(_s1.agg_1, 0) AS total_discount 14 | FROM main.coupons AS coupons 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.coupon_id = coupons.cid 17 | ORDER BY 18 | redemption_count DESC 19 | LIMIT 3 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic9_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(wallet_transactions_daily.amount) AS agg_0, 4 | COUNT(DISTINCT wallet_transactions_daily.sender_id) AS agg_1, 5 | users.country 6 | FROM main.wallet_transactions_daily AS wallet_transactions_daily 7 | LEFT JOIN main.users AS users 8 | ON users.uid = wallet_transactions_daily.sender_id 9 | WHERE 10 | wallet_transactions_daily.sender_type = 0 11 | GROUP BY 12 | users.country 13 | ) 14 | SELECT 15 | country, 16 | COALESCE(agg_1, 0) AS user_count, 17 | COALESCE(agg_0, 0) AS total_amount 18 | FROM _t1 19 | ORDER BY 20 | total_amount DESC 21 | LIMIT 5 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_basic9_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | SUM(wallet_transactions_daily.amount) AS agg_0, 4 | COUNT(DISTINCT wallet_transactions_daily.sender_id) AS agg_1, 5 | users.country 6 | FROM main.wallet_transactions_daily AS wallet_transactions_daily 7 | LEFT JOIN main.users AS users 8 | ON users.uid = wallet_transactions_daily.sender_id 9 | WHERE 10 | wallet_transactions_daily.sender_type = 0 11 | GROUP BY 12 | users.country 13 | ) 14 | SELECT 15 | country, 16 | COALESCE(agg_1, 0) AS user_count, 17 | COALESCE(agg_0, 0) AS total_amount 18 | FROM _t1 19 | ORDER BY 20 | total_amount DESC 21 | LIMIT 5 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_gen1_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | wallet_merchant_balance_daily.balance 4 | FROM main.merchants AS merchants 5 | JOIN main.wallet_merchant_balance_daily AS wallet_merchant_balance_daily 6 | ON merchants.mid = wallet_merchant_balance_daily.merchant_id 7 | WHERE 8 | LOWER(merchants.category) LIKE '%retail%' AND merchants.status = 'active' 9 | QUALIFY 10 | DATE_TRUNC('DAY', CAST(wallet_merchant_balance_daily.updated_at AS TIMESTAMP)) = DATE_TRUNC('DAY', CURRENT_TIMESTAMP()) 11 | AND ROW_NUMBER() OVER (PARTITION BY merchants.mid ORDER BY wallet_merchant_balance_daily.updated_at DESC NULLS FIRST) = 1 12 | ) 13 | SELECT 14 | MEDIAN(balance) AS _expr0 15 | FROM _t1 16 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_gen2_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | MIN(snapshot_date) AS min_date 4 | FROM main.user_setting_snapshot 5 | WHERE 6 | EXTRACT(YEAR FROM snapshot_date) = 2023 7 | ) 8 | SELECT 9 | AVG(user_setting_snapshot.tx_limit_daily) AS avg_daily_limit, 10 | AVG(user_setting_snapshot.tx_limit_monthly) AS avg_monthly_limit 11 | FROM _s0 AS _s0 12 | JOIN main.user_setting_snapshot AS user_setting_snapshot 13 | ON EXTRACT(YEAR FROM user_setting_snapshot.snapshot_date) = 2023 14 | AND _s0.min_date = user_setting_snapshot.snapshot_date 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_gen2_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | MIN(snapshot_date) AS min_date 4 | FROM main.user_setting_snapshot 5 | WHERE 6 | CAST(STRFTIME('%Y', snapshot_date) AS INTEGER) = 2023 7 | ) 8 | SELECT 9 | AVG(user_setting_snapshot.tx_limit_daily) AS avg_daily_limit, 10 | AVG(user_setting_snapshot.tx_limit_monthly) AS avg_monthly_limit 11 | FROM _s0 AS _s0 12 | JOIN main.user_setting_snapshot AS user_setting_snapshot 13 | ON CAST(STRFTIME('%Y', user_setting_snapshot.snapshot_date) AS INTEGER) = 2023 14 | AND _s0.min_date = user_setting_snapshot.snapshot_date 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_gen3_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | device_type, 3 | AVG(DATEDIFF(session_end_ts, session_start_ts, SECOND)) AS avg_session_duration_seconds 4 | FROM main.user_sessions 5 | GROUP BY 6 | device_type 7 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/defog_ewallet_gen3_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | device_type, 3 | AVG( 4 | ( 5 | ( 6 | CAST(( 7 | JULIANDAY(DATE(session_end_ts, 'start of day')) - JULIANDAY(DATE(session_start_ts, 'start of day')) 8 | ) AS INTEGER) * 24 + CAST(STRFTIME('%H', session_end_ts) AS INTEGER) - CAST(STRFTIME('%H', session_start_ts) AS INTEGER) 9 | ) * 60 + CAST(STRFTIME('%M', session_end_ts) AS INTEGER) - CAST(STRFTIME('%M', session_start_ts) AS INTEGER) 10 | ) * 60 + CAST(STRFTIME('%S', session_end_ts) AS INTEGER) - CAST(STRFTIME('%S', session_start_ts) AS INTEGER) 11 | ) AS avg_session_duration_seconds 12 | FROM main.user_sessions 13 | GROUP BY 14 | device_type 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/duplicate_limit_different_ordering_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | a, 4 | b 5 | FROM table 6 | ORDER BY 7 | a 8 | LIMIT 5 9 | ) 10 | SELECT 11 | a, 12 | b 13 | FROM _t0 14 | ORDER BY 15 | b DESC 16 | LIMIT 2 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/duplicate_limit_min_inner_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a, 3 | b 4 | FROM table 5 | LIMIT 1 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/duplicate_limit_min_outer_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a, 3 | b 4 | FROM table 5 | ORDER BY 6 | a, 7 | b DESC 8 | LIMIT 1 9 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_events_per_season_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | seasons.s_name AS name 5 | FROM seasons AS seasons 6 | JOIN events AS events 7 | ON seasons.s_month1 = EXTRACT(MONTH FROM events.ev_dt) 8 | OR seasons.s_month2 = EXTRACT(MONTH FROM events.ev_dt) 9 | OR seasons.s_month3 = EXTRACT(MONTH FROM events.ev_dt) 10 | GROUP BY 11 | seasons.s_name 12 | ) 13 | SELECT 14 | seasons.s_name AS season_name, 15 | COALESCE(_s3.agg_0, 0) AS n_events 16 | FROM seasons AS seasons 17 | LEFT JOIN _s3 AS _s3 18 | ON _s3.name = seasons.s_name 19 | ORDER BY 20 | n_events DESC, 21 | season_name 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_events_per_season_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | seasons.s_name AS name 5 | FROM seasons AS seasons 6 | JOIN events AS events 7 | ON seasons.s_month1 = CAST(STRFTIME('%m', events.ev_dt) AS INTEGER) 8 | OR seasons.s_month2 = CAST(STRFTIME('%m', events.ev_dt) AS INTEGER) 9 | OR seasons.s_month3 = CAST(STRFTIME('%m', events.ev_dt) AS INTEGER) 10 | GROUP BY 11 | seasons.s_name 12 | ) 13 | SELECT 14 | seasons.s_name AS season_name, 15 | COALESCE(_s3.agg_0, 0) AS n_events 16 | FROM seasons AS seasons 17 | LEFT JOIN _s3 AS _s3 18 | ON _s3.name = seasons.s_name 19 | ORDER BY 20 | n_events DESC, 21 | season_name 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_first_event_per_era_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | eras.er_name AS name, 4 | events.ev_name AS name_1, 5 | eras.er_start_year AS start_year 6 | FROM eras AS eras 7 | JOIN events AS events 8 | ON eras.er_end_year > EXTRACT(YEAR FROM events.ev_dt) 9 | AND eras.er_start_year <= EXTRACT(YEAR FROM events.ev_dt) 10 | QUALIFY 11 | ROW_NUMBER() OVER (PARTITION BY eras.er_name ORDER BY events.ev_dt NULLS LAST) = 1 12 | ) 13 | SELECT 14 | name AS era_name, 15 | name_1 AS event_name 16 | FROM _t1 17 | ORDER BY 18 | start_year 19 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_first_event_per_era_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t AS ( 2 | SELECT 3 | eras.er_name AS name, 4 | events.ev_name AS name_1, 5 | eras.er_start_year AS start_year, 6 | ROW_NUMBER() OVER (PARTITION BY eras.er_name ORDER BY events.ev_dt) AS _w 7 | FROM eras AS eras 8 | JOIN events AS events 9 | ON eras.er_end_year > CAST(STRFTIME('%Y', events.ev_dt) AS INTEGER) 10 | AND eras.er_start_year <= CAST(STRFTIME('%Y', events.ev_dt) AS INTEGER) 11 | ) 12 | SELECT 13 | name AS era_name, 14 | name_1 AS event_name 15 | FROM _t 16 | WHERE 17 | _w = 1 18 | ORDER BY 19 | start_year 20 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_most_popular_search_engine_per_tod_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t2 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | searches.search_engine, 5 | times.t_name AS tod 6 | FROM times AS times 7 | JOIN searches AS searches 8 | ON times.t_end_hour > EXTRACT(HOUR FROM searches.search_ts) 9 | AND times.t_start_hour <= EXTRACT(HOUR FROM searches.search_ts) 10 | GROUP BY 11 | searches.search_engine, 12 | times.t_name 13 | ), _t0 AS ( 14 | SELECT 15 | COALESCE(agg_0, 0) AS n_searches, 16 | search_engine, 17 | tod 18 | FROM _t2 19 | QUALIFY 20 | ROW_NUMBER() OVER (PARTITION BY tod ORDER BY COALESCE(agg_0, 0) DESC NULLS FIRST, search_engine NULLS LAST) = 1 21 | ) 22 | SELECT 23 | tod, 24 | search_engine, 25 | n_searches 26 | FROM _t0 27 | ORDER BY 28 | tod 29 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_most_popular_search_engine_per_tod_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t2 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | searches.search_engine, 5 | times.t_name AS tod 6 | FROM times AS times 7 | JOIN searches AS searches 8 | ON times.t_end_hour > CAST(STRFTIME('%H', searches.search_ts) AS INTEGER) 9 | AND times.t_start_hour <= CAST(STRFTIME('%H', searches.search_ts) AS INTEGER) 10 | GROUP BY 11 | searches.search_engine, 12 | times.t_name 13 | ), _t AS ( 14 | SELECT 15 | COALESCE(agg_0, 0) AS n_searches, 16 | search_engine, 17 | tod, 18 | ROW_NUMBER() OVER (PARTITION BY tod ORDER BY COALESCE(agg_0, 0) DESC, search_engine) AS _w 19 | FROM _t2 20 | ) 21 | SELECT 22 | tod, 23 | search_engine, 24 | n_searches 25 | FROM _t 26 | WHERE 27 | _w = 1 28 | ORDER BY 29 | tod 30 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_most_popular_topic_per_region_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t2 AS ( 2 | SELECT 3 | COUNT(DISTINCT searches.search_id) AS agg_0, 4 | events.ev_typ AS event_type, 5 | users.user_region AS region 6 | FROM events AS events 7 | JOIN searches AS searches 8 | ON LOWER(searches.search_string) LIKE CONCAT('%', LOWER(events.ev_name), '%') 9 | LEFT JOIN users AS users 10 | ON searches.search_user_id = users.user_id 11 | GROUP BY 12 | events.ev_typ, 13 | users.user_region 14 | ), _t0 AS ( 15 | SELECT 16 | COALESCE(agg_0, 0) AS n_searches, 17 | event_type, 18 | region 19 | FROM _t2 20 | QUALIFY 21 | ROW_NUMBER() OVER (PARTITION BY region ORDER BY COALESCE(agg_0, 0) DESC NULLS FIRST) = 1 22 | ) 23 | SELECT 24 | region, 25 | event_type, 26 | n_searches 27 | FROM _t0 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_pct_searches_per_tod_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | times.t_name AS name 5 | FROM times AS times 6 | JOIN searches AS searches 7 | ON times.t_end_hour > EXTRACT(HOUR FROM searches.search_ts) 8 | AND times.t_start_hour <= EXTRACT(HOUR FROM searches.search_ts) 9 | GROUP BY 10 | times.t_name 11 | ), _t0 AS ( 12 | SELECT 13 | ROUND(( 14 | 100.0 * COALESCE(_s3.agg_0, 0) 15 | ) / SUM(COALESCE(_s3.agg_0, 0)) OVER (), 2) AS pct_searches, 16 | times.t_name AS tod, 17 | times.t_start_hour AS start_hour 18 | FROM times AS times 19 | LEFT JOIN _s3 AS _s3 20 | ON _s3.name = times.t_name 21 | ) 22 | SELECT 23 | tod, 24 | pct_searches 25 | FROM _t0 26 | ORDER BY 27 | start_hour 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_summer_events_per_type_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | events.ev_typ AS event_type 5 | FROM seasons AS seasons 6 | JOIN events AS events 7 | ON seasons.s_month1 = EXTRACT(MONTH FROM events.ev_dt) 8 | OR seasons.s_month2 = EXTRACT(MONTH FROM events.ev_dt) 9 | OR seasons.s_month3 = EXTRACT(MONTH FROM events.ev_dt) 10 | WHERE 11 | seasons.s_name = 'Summer' 12 | GROUP BY 13 | events.ev_typ 14 | ) 15 | SELECT 16 | event_type, 17 | COALESCE(agg_0, 0) AS n_events 18 | FROM _t0 19 | ORDER BY 20 | event_type 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_summer_events_per_type_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | events.ev_typ AS event_type 5 | FROM seasons AS seasons 6 | JOIN events AS events 7 | ON seasons.s_month1 = CAST(STRFTIME('%m', events.ev_dt) AS INTEGER) 8 | OR seasons.s_month2 = CAST(STRFTIME('%m', events.ev_dt) AS INTEGER) 9 | OR seasons.s_month3 = CAST(STRFTIME('%m', events.ev_dt) AS INTEGER) 10 | WHERE 11 | seasons.s_name = 'Summer' 12 | GROUP BY 13 | events.ev_typ 14 | ) 15 | SELECT 16 | event_type, 17 | COALESCE(agg_0, 0) AS n_events 18 | FROM _t0 19 | ORDER BY 20 | event_type 21 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_unique_users_per_engine_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s2 AS ( 2 | SELECT DISTINCT 3 | search_engine 4 | FROM searches 5 | ), _s3 AS ( 6 | SELECT 7 | COUNT(DISTINCT users.user_id) AS agg_0, 8 | searches.search_engine 9 | FROM searches AS searches 10 | JOIN users AS users 11 | ON searches.search_user_id = users.user_id 12 | WHERE 13 | EXTRACT(YEAR FROM searches.search_ts) <= 2019 14 | AND EXTRACT(YEAR FROM searches.search_ts) >= 2010 15 | GROUP BY 16 | searches.search_engine 17 | ) 18 | SELECT 19 | _s2.search_engine AS engine, 20 | COALESCE(_s3.agg_0, 0) AS n_users 21 | FROM _s2 AS _s2 22 | LEFT JOIN _s3 AS _s3 23 | ON _s2.search_engine = _s3.search_engine 24 | ORDER BY 25 | engine 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/epoch_unique_users_per_engine_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s2 AS ( 2 | SELECT DISTINCT 3 | search_engine 4 | FROM searches 5 | ), _s3 AS ( 6 | SELECT 7 | COUNT(DISTINCT users.user_id) AS agg_0, 8 | searches.search_engine 9 | FROM searches AS searches 10 | JOIN users AS users 11 | ON searches.search_user_id = users.user_id 12 | WHERE 13 | CAST(STRFTIME('%Y', searches.search_ts) AS INTEGER) <= 2019 14 | AND CAST(STRFTIME('%Y', searches.search_ts) AS INTEGER) >= 2010 15 | GROUP BY 16 | searches.search_engine 17 | ) 18 | SELECT 19 | _s2.search_engine AS engine, 20 | COALESCE(_s3.agg_0, 0) AS n_users 21 | FROM _s2 AS _s2 22 | LEFT JOIN _s3 AS _s3 23 | ON _s2.search_engine = _s3.search_engine 24 | ORDER BY 25 | engine 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_contains_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | WHERE 5 | b LIKE '%a%' AND b LIKE ( 6 | '%' || a || '%' 7 | ) 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_ends_with_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | WHERE 5 | b LIKE '%a' AND b LIKE ( 6 | '%' || a 7 | ) 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_iff_iif_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | IIF(b >= 0, 'Positive', 'Negative') AS a 3 | FROM table 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_isin_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | WHERE 5 | b IN (1, 2, 3) 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_like_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | WHERE 5 | b LIKE '%abc%efg%' 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_rank_with_filters_a_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | RANK() OVER (ORDER BY a) AS r, 4 | a, 5 | b 6 | FROM table 7 | WHERE 8 | b = 0 9 | ) 10 | SELECT 11 | a, 12 | b, 13 | r 14 | FROM _t0 15 | WHERE 16 | r >= 3 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_rank_with_filters_b_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t1 AS ( 2 | SELECT 3 | RANK() OVER (ORDER BY a) AS r, 4 | a, 5 | b 6 | FROM table 7 | ) 8 | SELECT 9 | a, 10 | b, 11 | r 12 | FROM _t1 13 | WHERE 14 | b = 0 AND r >= 3 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_starts_with_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | WHERE 5 | b LIKE 'a%' AND b LIKE ( 6 | a || '%' 7 | ) 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/func_year_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | CAST(STRFTIME('%Y', a) AS INTEGER) AS a 3 | FROM table 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/global_acctbal_breakdown_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT(CASE WHEN c_acctbal < 0 THEN c_acctbal ELSE NULL END) AS n_red_acctbal, 3 | COUNT(CASE WHEN c_acctbal >= 0 THEN c_acctbal ELSE NULL END) AS n_black_acctbal, 4 | MEDIAN(CASE WHEN c_acctbal < 0 THEN c_acctbal ELSE NULL END) AS median_red_acctbal, 5 | MEDIAN(CASE WHEN c_acctbal >= 0 THEN c_acctbal ELSE NULL END) AS median_black_acctbal, 6 | MEDIAN(c_acctbal) AS median_overall_acctbal 7 | FROM tpch.customer 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/hour_minute_day_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sbtransaction.sbtxid AS transaction_id, 3 | EXTRACT(HOUR FROM sbtransaction.sbtxdatetime) AS _expr0, 4 | EXTRACT(MINUTE FROM sbtransaction.sbtxdatetime) AS _expr1, 5 | EXTRACT(SECOND FROM sbtransaction.sbtxdatetime) AS _expr2 6 | FROM main.sbtransaction AS sbtransaction 7 | LEFT JOIN main.sbticker AS sbticker 8 | ON sbticker.sbtickerid = sbtransaction.sbtxtickerid 9 | WHERE 10 | sbticker.sbtickersymbol IN ('AAPL', 'GOOGL', 'NFLX') 11 | ORDER BY 12 | transaction_id 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/hour_minute_day_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sbtransaction.sbtxid AS transaction_id, 3 | CAST(STRFTIME('%H', sbtransaction.sbtxdatetime) AS INTEGER) AS _expr0, 4 | CAST(STRFTIME('%M', sbtransaction.sbtxdatetime) AS INTEGER) AS _expr1, 5 | CAST(STRFTIME('%S', sbtransaction.sbtxdatetime) AS INTEGER) AS _expr2 6 | FROM main.sbtransaction AS sbtransaction 7 | LEFT JOIN main.sbticker AS sbticker 8 | ON sbticker.sbtickerid = sbtransaction.sbtxtickerid 9 | WHERE 10 | sbticker.sbtickersymbol IN ('AAPL', 'GOOGL', 'NFLX') 11 | ORDER BY 12 | transaction_id 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/multi_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | a 4 | FROM table 5 | ) 6 | SELECT 7 | _s0.a 8 | FROM _s0 AS _s0 9 | JOIN _s0 AS _s1 10 | ON _s0.a = _s1.a 11 | JOIN _s0 AS _s2 12 | ON _s0.a = _s2.a 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/nested_binary_functions_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a * ( 3 | b + 1 4 | ) AS a, 5 | a * ( 6 | b + 1 7 | ) + b * 1 AS b 8 | FROM table 9 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/nested_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | a 4 | FROM table 5 | ) 6 | SELECT 7 | table.b AS d 8 | FROM _s0 AS _s0 9 | JOIN table AS table 10 | ON _s0.a = table.a 11 | LEFT JOIN _s0 AS _s3 12 | ON _s0.a = _s3.a 13 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/ordering_function_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a 3 | FROM table 4 | ORDER BY 5 | ABS(a) 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/project_scan_with_ordering_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | ORDER BY 5 | a + 1 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/rank_a_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | c_custkey AS id, 3 | ROW_NUMBER() OVER (ORDER BY c_acctbal DESC NULLS FIRST) AS rk 4 | FROM tpch.customer 5 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/rank_a_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | c_custkey AS id, 3 | ROW_NUMBER() OVER (ORDER BY c_acctbal DESC) AS rk 4 | FROM tpch.customer 5 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/rank_b_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderkey AS order_key, 3 | RANK() OVER (ORDER BY o_orderpriority NULLS LAST) AS rank 4 | FROM tpch.orders 5 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/rank_b_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderkey AS order_key, 3 | RANK() OVER (ORDER BY o_orderpriority) AS rank 4 | FROM tpch.orders 5 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/rank_c_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderdate AS order_date, 3 | DENSE_RANK() OVER (ORDER BY o_orderdate NULLS LAST) AS rank 4 | FROM tpch.orders 5 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/rank_c_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderdate AS order_date, 3 | DENSE_RANK() OVER (ORDER BY o_orderdate) AS rank 4 | FROM tpch.orders 5 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_anti_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | table.a AS a 4 | FROM table AS table 5 | ) 6 | SELECT 7 | _s0.a AS a 8 | FROM _s1 AS _s0 9 | WHERE 10 | NOT EXISTS( 11 | SELECT 12 | 1 AS "1" 13 | FROM _s1 AS _s1 14 | WHERE 15 | _s0.a = _s1.a 16 | ) 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_distinct_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT DISTINCT 2 | b 3 | FROM table 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_filter_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderdate AS order_date, 3 | o_orderkey, 4 | o_totalprice 5 | FROM tpch.orders 6 | WHERE 7 | o_totalprice < 1000.0 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_filter_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderdate AS order_date, 3 | o_orderkey, 4 | o_totalprice 5 | FROM tpch.orders 6 | WHERE 7 | o_totalprice < 1000.0 8 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_filter_test_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a, 3 | b 4 | FROM table 5 | WHERE 6 | a = 1 7 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_full_outer_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | a 4 | FROM table 5 | ) 6 | SELECT 7 | _s0.a 8 | FROM _s0 AS _s0 9 | FULL JOIN _s0 AS _s1 10 | ON _s0.a = _s1.a 11 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_groupby_sum_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | SUM(a) AS a, 3 | b 4 | FROM table 5 | GROUP BY 6 | b 7 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_inner_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | table.a, 3 | table_2.b 4 | FROM table AS table 5 | JOIN table AS table_2 6 | ON table.a = table_2.a 7 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_left_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | a 4 | FROM table 5 | ) 6 | SELECT 7 | _s0.a 8 | FROM _s0 AS _s0 9 | LEFT JOIN _s0 AS _s1 10 | ON _s0.a = _s1.a 11 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_limit_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a, 3 | b 4 | FROM table 5 | LIMIT 1 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_limit_with_ordering_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a, 3 | b 4 | FROM table 5 | ORDER BY 6 | a, 7 | b DESC 8 | LIMIT 10 9 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_right_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | a 4 | FROM table 5 | ) 6 | SELECT 7 | _s0.a 8 | FROM _s0 AS _s0 9 | RIGHT JOIN _s0 AS _s1 10 | ON _s0.a = _s1.a 11 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_scan_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderkey AS key 3 | FROM tpch.orders 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_scan_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | o_orderkey AS key 3 | FROM tpch.orders 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_scan_test_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | b 3 | FROM table 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_scan_with_ordering_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | a, 3 | b 4 | FROM table 5 | ORDER BY 6 | a 7 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_semi_join_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | table.a AS a 4 | FROM table AS table 5 | ) 6 | SELECT 7 | _s0.a AS a 8 | FROM _s1 AS _s0 9 | WHERE 10 | EXISTS( 11 | SELECT 12 | 1 AS "1" 13 | FROM _s1 AS _s1 14 | WHERE 15 | _s0.a = _s1.a 16 | ) 17 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_smallest_or_largest_ansi.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | 10 AS s1, 3 | 20 AS s2, 4 | 0 AS s3, 5 | -200 AS s4, 6 | NULL AS s5, 7 | -0.34 AS s6, 8 | CAST('2023-01-01 00:00:00' AS TIMESTAMP) AS s7, 9 | '' AS s8, 10 | NULL AS s9, 11 | 20 AS l1, 12 | 20 AS l2, 13 | 20 AS l3, 14 | 300 AS l4, 15 | NULL AS l5, 16 | 100.22 AS l6, 17 | CAST('2025-01-01 00:00:00' AS TIMESTAMP) AS l7, 18 | 'alphabet soup' AS l8, 19 | NULL AS l9 20 | FROM (VALUES 21 | (NULL)) AS _q_0(_col_0) 22 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_sum_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | SUM(a) AS a 3 | FROM table 4 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_values_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | 42 AS A, 3 | 'foo' AS B 4 | FROM (VALUES 5 | (NULL)) AS _q_0 6 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/simple_var_std_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | STDDEV_POP(s_acctbal) AS agg_0, 4 | VARIANCE_POP(s_acctbal) AS agg_1, 5 | STDDEV(s_acctbal) AS agg_2, 6 | VARIANCE(s_acctbal) AS agg_3, 7 | s_nationkey AS nation_key 8 | FROM tpch.supplier 9 | GROUP BY 10 | s_nationkey 11 | ) 12 | SELECT 13 | nation.n_name AS name, 14 | _s1.agg_1 AS var, 15 | _s1.agg_0 AS std, 16 | _s1.agg_3 AS sample_var, 17 | _s1.agg_2 AS sample_std, 18 | _s1.agg_1 AS pop_var, 19 | _s1.agg_0 AS pop_std 20 | FROM tpch.nation AS nation 21 | LEFT JOIN _s1 AS _s1 22 | ON _s1.nation_key = nation.n_nationkey 23 | WHERE 24 | nation.n_name IN ('ALGERIA', 'ARGENTINA') 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_country_cartesian_oddball_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0 4 | FROM main.countries 5 | ) 6 | SELECT 7 | countries.co_name AS name, 8 | COALESCE(_s1.agg_0, 0) AS n_other_countries 9 | FROM main.countries AS countries 10 | LEFT JOIN _s1 AS _s1 11 | ON TRUE 12 | ORDER BY 13 | name 14 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_country_cartesian_oddball_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0 4 | FROM main.countries 5 | ) 6 | SELECT 7 | countries.co_name AS name, 8 | COALESCE(_s1.agg_0, 0) AS n_other_countries 9 | FROM main.countries AS countries 10 | LEFT JOIN _s1 AS _s1 11 | ON TRUE 12 | ORDER BY 13 | name 14 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_error_percentages_sun_set_by_error_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s5 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | incidents.in_error_id AS error_id 5 | FROM main.incidents AS incidents 6 | JOIN main.devices AS devices 7 | ON devices.de_id = incidents.in_device_id 8 | JOIN main.products AS products 9 | ON devices.de_product_id = products.pr_id AND products.pr_name = 'Sun-Set' 10 | GROUP BY 11 | incidents.in_error_id 12 | ), _t0 AS ( 13 | SELECT 14 | errors.er_name AS error, 15 | ROUND(( 16 | 100.0 * COALESCE(_s5.agg_0, 0) 17 | ) / SUM(COALESCE(_s5.agg_0, 0)) OVER (), 2) AS pct 18 | FROM main.errors AS errors 19 | LEFT JOIN _s5 AS _s5 20 | ON _s5.error_id = errors.er_id 21 | ) 22 | SELECT 23 | error, 24 | pct 25 | FROM _t0 26 | ORDER BY 27 | pct DESC 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_global_incident_rate_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | COUNT() AS agg_0 4 | FROM main.incidents 5 | ), _s1 AS ( 6 | SELECT 7 | COUNT() AS agg_1 8 | FROM main.devices 9 | ) 10 | SELECT 11 | ROUND(_s0.agg_0 / _s1.agg_1, 2) AS ir 12 | FROM _s0 AS _s0 13 | LEFT JOIN _s1 AS _s1 14 | ON TRUE 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_global_incident_rate_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s0 AS ( 2 | SELECT 3 | COUNT() AS agg_0 4 | FROM main.incidents 5 | ), _s1 AS ( 6 | SELECT 7 | COUNT() AS agg_1 8 | FROM main.devices 9 | ) 10 | SELECT 11 | ROUND(CAST(_s0.agg_0 AS REAL) / _s1.agg_1, 2) AS ir 12 | FROM _s0 AS _s0 13 | LEFT JOIN _s1 AS _s1 14 | ON TRUE 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_hot_purchase_window_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT() AS n_purchases, 4 | ANY_VALUE(calendar.ca_dt) AS start_of_period 5 | FROM main.calendar AS calendar 6 | JOIN main.calendar AS calendar_2 7 | ON calendar.ca_dt <= calendar_2.ca_dt 8 | AND calendar_2.ca_dt < DATE_ADD(CAST(calendar.ca_dt AS TIMESTAMP), 5, 'DAY') 9 | JOIN main.devices AS devices 10 | ON calendar_2.ca_dt = DATE_TRUNC('DAY', CAST(devices.de_purchase_ts AS TIMESTAMP)) 11 | WHERE 12 | EXTRACT(YEAR FROM calendar.ca_dt) = 2024 13 | GROUP BY 14 | calendar.ca_dt 15 | ) 16 | SELECT 17 | start_of_period, 18 | n_purchases 19 | FROM _t0 20 | ORDER BY 21 | n_purchases DESC, 22 | start_of_period 23 | LIMIT 1 24 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_hot_purchase_window_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | COUNT() AS n_purchases, 4 | MAX(calendar.ca_dt) AS start_of_period 5 | FROM main.calendar AS calendar 6 | JOIN main.calendar AS calendar_2 7 | ON calendar.ca_dt <= calendar_2.ca_dt 8 | AND calendar_2.ca_dt < DATETIME(calendar.ca_dt, '5 day') 9 | JOIN main.devices AS devices 10 | ON calendar_2.ca_dt = DATE(devices.de_purchase_ts, 'start of day') 11 | WHERE 12 | CAST(STRFTIME('%Y', calendar.ca_dt) AS INTEGER) = 2024 13 | GROUP BY 14 | calendar.ca_dt 15 | ) 16 | SELECT 17 | start_of_period, 18 | n_purchases 19 | FROM _t0 20 | ORDER BY 21 | n_purchases DESC, 22 | start_of_period 23 | LIMIT 1 24 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_incident_rate_per_brand_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | in_device_id AS device_id 5 | FROM main.incidents 6 | GROUP BY 7 | in_device_id 8 | ), _t0 AS ( 9 | SELECT 10 | SUM(COALESCE(_s3.agg_0, 0)) AS agg_0, 11 | COUNT() AS agg_1, 12 | products.pr_brand AS brand 13 | FROM main.devices AS devices 14 | LEFT JOIN main.products AS products 15 | ON devices.de_product_id = products.pr_id 16 | LEFT JOIN _s3 AS _s3 17 | ON _s3.device_id = devices.de_id 18 | GROUP BY 19 | products.pr_brand 20 | ) 21 | SELECT 22 | brand, 23 | ROUND(COALESCE(agg_0, 0) / COALESCE(agg_1, 0), 2) AS ir 24 | FROM _t0 25 | ORDER BY 26 | brand 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/technograph_incident_rate_per_brand_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | in_device_id AS device_id 5 | FROM main.incidents 6 | GROUP BY 7 | in_device_id 8 | ), _t0 AS ( 9 | SELECT 10 | SUM(COALESCE(_s3.agg_0, 0)) AS agg_0, 11 | COUNT() AS agg_1, 12 | products.pr_brand AS brand 13 | FROM main.devices AS devices 14 | LEFT JOIN main.products AS products 15 | ON devices.de_product_id = products.pr_id 16 | LEFT JOIN _s3 AS _s3 17 | ON _s3.device_id = devices.de_id 18 | GROUP BY 19 | products.pr_brand 20 | ) 21 | SELECT 22 | brand, 23 | ROUND(CAST(COALESCE(agg_0, 0) AS REAL) / COALESCE(agg_1, 0), 2) AS ir 24 | FROM _t0 25 | ORDER BY 26 | brand 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/time_threshold_reached_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t2 AS ( 2 | SELECT 3 | CAST(( 4 | 100.0 * SUM(sbtxshares) OVER (PARTITION BY DATE(sbtxdatetime, 'start of day') ORDER BY sbtxdatetime ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) 5 | ) AS REAL) / SUM(sbtxshares) OVER (PARTITION BY DATE(sbtxdatetime, 'start of day')) AS pct_of_day, 6 | sbtxdatetime AS date_time, 7 | DATE(sbtxdatetime, 'start of day') AS txn_day 8 | FROM main.sbtransaction 9 | WHERE 10 | CAST(STRFTIME('%Y', sbtxdatetime) AS INTEGER) = 2023 11 | ), _t AS ( 12 | SELECT 13 | date_time, 14 | ROW_NUMBER() OVER (PARTITION BY txn_day ORDER BY pct_of_day) AS _w 15 | FROM _t2 16 | WHERE 17 | pct_of_day >= 50.0 18 | ) 19 | SELECT 20 | date_time 21 | FROM _t 22 | WHERE 23 | _w = 1 24 | ORDER BY 25 | date_time 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q13_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | o_custkey AS customer_key 5 | FROM tpch.orders 6 | WHERE 7 | NOT o_comment LIKE '%special%requests%' 8 | GROUP BY 9 | o_custkey 10 | ), _t1 AS ( 11 | SELECT 12 | COUNT() AS agg_0, 13 | COALESCE(_s1.agg_0, 0) AS num_non_special_orders 14 | FROM tpch.customer AS customer 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.customer_key = customer.c_custkey 17 | GROUP BY 18 | COALESCE(_s1.agg_0, 0) 19 | ) 20 | SELECT 21 | num_non_special_orders AS C_COUNT, 22 | COALESCE(agg_0, 0) AS CUSTDIST 23 | FROM _t1 24 | ORDER BY 25 | custdist DESC, 26 | c_count DESC 27 | LIMIT 10 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q13_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | COUNT() AS agg_0, 4 | o_custkey AS customer_key 5 | FROM tpch.orders 6 | WHERE 7 | NOT o_comment LIKE '%special%requests%' 8 | GROUP BY 9 | o_custkey 10 | ), _t1 AS ( 11 | SELECT 12 | COUNT() AS agg_0, 13 | COALESCE(_s1.agg_0, 0) AS num_non_special_orders 14 | FROM tpch.customer AS customer 15 | LEFT JOIN _s1 AS _s1 16 | ON _s1.customer_key = customer.c_custkey 17 | GROUP BY 18 | COALESCE(_s1.agg_0, 0) 19 | ) 20 | SELECT 21 | num_non_special_orders AS C_COUNT, 22 | COALESCE(agg_0, 0) AS CUSTDIST 23 | FROM _t1 24 | ORDER BY 25 | custdist DESC, 26 | c_count DESC 27 | LIMIT 10 28 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q14_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM( 4 | CASE 5 | WHEN part.p_type LIKE 'PROMO%' 6 | THEN lineitem.l_extendedprice * ( 7 | 1 - lineitem.l_discount 8 | ) 9 | ELSE 0 10 | END 11 | ) AS agg_0, 12 | SUM(lineitem.l_extendedprice * ( 13 | 1 - lineitem.l_discount 14 | )) AS agg_1 15 | FROM tpch.lineitem AS lineitem 16 | LEFT JOIN tpch.part AS part 17 | ON lineitem.l_partkey = part.p_partkey 18 | WHERE 19 | lineitem.l_shipdate < CAST('1995-10-01' AS DATE) 20 | AND lineitem.l_shipdate >= CAST('1995-09-01' AS DATE) 21 | ) 22 | SELECT 23 | ( 24 | 100.0 * COALESCE(agg_0, 0) 25 | ) / COALESCE(agg_1, 0) AS PROMO_REVENUE 26 | FROM _t0 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q14_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM( 4 | IIF( 5 | part.p_type LIKE 'PROMO%', 6 | lineitem.l_extendedprice * ( 7 | 1 - lineitem.l_discount 8 | ), 9 | 0 10 | ) 11 | ) AS agg_0, 12 | SUM(lineitem.l_extendedprice * ( 13 | 1 - lineitem.l_discount 14 | )) AS agg_1 15 | FROM tpch.lineitem AS lineitem 16 | LEFT JOIN tpch.part AS part 17 | ON lineitem.l_partkey = part.p_partkey 18 | WHERE 19 | lineitem.l_shipdate < '1995-10-01' AND lineitem.l_shipdate >= '1995-09-01' 20 | ) 21 | SELECT 22 | CAST(( 23 | 100.0 * COALESCE(agg_0, 0) 24 | ) AS REAL) / COALESCE(agg_1, 0) AS PROMO_REVENUE 25 | FROM _t0 26 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q17_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | AVG(l_quantity) AS agg_0, 4 | l_partkey AS part_key 5 | FROM tpch.lineitem 6 | GROUP BY 7 | l_partkey 8 | ), _t0 AS ( 9 | SELECT 10 | SUM(lineitem.l_extendedprice) AS agg_0 11 | FROM tpch.part AS part 12 | LEFT JOIN _s1 AS _s1 13 | ON _s1.part_key = part.p_partkey 14 | JOIN tpch.lineitem AS lineitem 15 | ON lineitem.l_partkey = part.p_partkey 16 | AND lineitem.l_quantity < ( 17 | 0.2 * _s1.agg_0 18 | ) 19 | WHERE 20 | part.p_brand = 'Brand#23' AND part.p_container = 'MED BOX' 21 | ) 22 | SELECT 23 | COALESCE(agg_0, 0) / 7.0 AS AVG_YEARLY 24 | FROM _t0 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q17_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s1 AS ( 2 | SELECT 3 | AVG(l_quantity) AS agg_0, 4 | l_partkey AS part_key 5 | FROM tpch.lineitem 6 | GROUP BY 7 | l_partkey 8 | ), _t0 AS ( 9 | SELECT 10 | SUM(lineitem.l_extendedprice) AS agg_0 11 | FROM tpch.part AS part 12 | LEFT JOIN _s1 AS _s1 13 | ON _s1.part_key = part.p_partkey 14 | JOIN tpch.lineitem AS lineitem 15 | ON lineitem.l_partkey = part.p_partkey 16 | AND lineitem.l_quantity < ( 17 | 0.2 * _s1.agg_0 18 | ) 19 | WHERE 20 | part.p_brand = 'Brand#23' AND part.p_container = 'MED BOX' 21 | ) 22 | SELECT 23 | CAST(COALESCE(agg_0, 0) AS REAL) / 7.0 AS AVG_YEARLY 24 | FROM _t0 25 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q18_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | SUM(l_quantity) AS agg_0, 4 | l_orderkey AS order_key 5 | FROM tpch.lineitem 6 | GROUP BY 7 | l_orderkey 8 | ) 9 | SELECT 10 | customer.c_name AS C_NAME, 11 | customer.c_custkey AS C_CUSTKEY, 12 | orders.o_orderkey AS O_ORDERKEY, 13 | orders.o_orderdate AS O_ORDERDATE, 14 | orders.o_totalprice AS O_TOTALPRICE, 15 | COALESCE(_s3.agg_0, 0) AS TOTAL_QUANTITY 16 | FROM tpch.orders AS orders 17 | LEFT JOIN tpch.customer AS customer 18 | ON customer.c_custkey = orders.o_custkey 19 | LEFT JOIN _s3 AS _s3 20 | ON _s3.order_key = orders.o_orderkey 21 | WHERE 22 | NOT _s3.agg_0 IS NULL AND _s3.agg_0 > 300 23 | ORDER BY 24 | o_totalprice DESC, 25 | o_orderdate 26 | LIMIT 10 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q18_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _s3 AS ( 2 | SELECT 3 | SUM(l_quantity) AS agg_0, 4 | l_orderkey AS order_key 5 | FROM tpch.lineitem 6 | GROUP BY 7 | l_orderkey 8 | ) 9 | SELECT 10 | customer.c_name AS C_NAME, 11 | customer.c_custkey AS C_CUSTKEY, 12 | orders.o_orderkey AS O_ORDERKEY, 13 | orders.o_orderdate AS O_ORDERDATE, 14 | orders.o_totalprice AS O_TOTALPRICE, 15 | COALESCE(_s3.agg_0, 0) AS TOTAL_QUANTITY 16 | FROM tpch.orders AS orders 17 | LEFT JOIN tpch.customer AS customer 18 | ON customer.c_custkey = orders.o_custkey 19 | LEFT JOIN _s3 AS _s3 20 | ON _s3.order_key = orders.o_orderkey 21 | WHERE 22 | NOT _s3.agg_0 IS NULL AND _s3.agg_0 > 300 23 | ORDER BY 24 | o_totalprice DESC, 25 | o_orderdate 26 | LIMIT 10 27 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q6_ansi.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(l_extendedprice * l_discount) AS agg_0 4 | FROM tpch.lineitem 5 | WHERE 6 | l_discount <= 0.07 7 | AND l_discount >= 0.05 8 | AND l_quantity < 24 9 | AND l_shipdate < CAST('1995-01-01' AS DATE) 10 | AND l_shipdate >= CAST('1994-01-01' AS DATE) 11 | ) 12 | SELECT 13 | COALESCE(agg_0, 0) AS REVENUE 14 | FROM _t0 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/tpch_q6_sqlite.sql: -------------------------------------------------------------------------------- 1 | WITH _t0 AS ( 2 | SELECT 3 | SUM(l_extendedprice * l_discount) AS agg_0 4 | FROM tpch.lineitem 5 | WHERE 6 | l_discount <= 0.07 7 | AND l_discount >= 0.05 8 | AND l_quantity < 24 9 | AND l_shipdate < '1995-01-01' 10 | AND l_shipdate >= '1994-01-01' 11 | ) 12 | SELECT 13 | COALESCE(agg_0, 0) AS REVENUE 14 | FROM _t0 15 | -------------------------------------------------------------------------------- /tests/test_sql_refsols/week_offset_sqlite.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | sbtxdatetime AS date_time, 3 | DATETIME(sbtxdatetime, '7 day') AS week_adj1, 4 | DATETIME(sbtxdatetime, '-7 day') AS week_adj2, 5 | DATETIME(sbtxdatetime, '1 hour', '14 day') AS week_adj3, 6 | DATETIME(sbtxdatetime, '-1 second', '14 day') AS week_adj4, 7 | DATETIME(sbtxdatetime, '1 day', '14 day') AS week_adj5, 8 | DATETIME(sbtxdatetime, '-1 minute', '14 day') AS week_adj6, 9 | DATETIME(sbtxdatetime, '1 month', '14 day') AS week_adj7, 10 | DATETIME(sbtxdatetime, '1 year', '14 day') AS week_adj8 11 | FROM main.sbtransaction 12 | WHERE 13 | CAST(STRFTIME('%Y', sbtxdatetime) AS INTEGER) < 2025 14 | AND CAST(STRFTIME('%d', sbtxdatetime) AS INTEGER) > 1 15 | --------------------------------------------------------------------------------