diff --git a/tests/gen_data/init_defog_sf.sql b/tests/gen_data/init_defog_sf.sql index 812b66ede..2aa947ab1 100644 --- a/tests/gen_data/init_defog_sf.sql +++ b/tests/gen_data/init_defog_sf.sql @@ -1370,3 +1370,63 @@ INSERT INTO writes (aid, pid) VALUES (2, 4), (2, 5), (3, 5); + +------------------------------------------------------------------------------- +-- For the Restaurants SCHEMA +-- https://github.com/defog-ai/defog-data/blob/main/defog_data/academic/restaurants.sql + +------------------------------------------------------------------------------- + +CREATE TABLE geographic ( + city_name VARCHAR, + county VARCHAR, + region VARCHAR +); + +CREATE TABLE location ( + restaurant_id BIGINT, + house_number BIGINT, + street_name VARCHAR, + city_name VARCHAR +); + +CREATE TABLE restaurant ( + id BIGINT, + name VARCHAR, + food_type VARCHAR, + city_name VARCHAR, + rating FLOAT +); + +INSERT INTO geographic (city_name, county, region) VALUES +('Los Angeles', 'Los Angeles', 'California'), +('New York', 'New York', 'New York'), +('San Francisco', 'San Francisco', 'California'), +('Miami', 'Miami-Dade', 'Florida'), +('Chicago', 'Cook', 'Illinois'); + +INSERT INTO location (restaurant_id, house_number, street_name, city_name) VALUES +(1, 123, 'Main St', 'Los Angeles'), +(2, 456, 'Maple Ave', 'Los Angeles'), +(3, 789, 'Oak St', 'Los Angeles'), +(4, 321, 'Elm St', 'New York'), +(5, 654, 'Pine Ave', 'New York'), +(6, 123, 'Pine Ave', 'New York'), +(7, 12, 'Market St', 'San Francisco'), +(8, 34, 'Mission St', 'San Francisco'), +(9, 56, 'Valencia St', 'San Francisco'), +(10, 78, 'Ocean Dr', 'Miami'), +(11, 90, 'Biscayne Rd', 'Miami'); + +INSERT INTO restaurant (id, rating, name, food_type, city_name) VALUES +(1, 4.5, 'The Pasta House', 'Italian', 'Los Angeles'), +(2, 3.8, 'The Burger Joint', 'American', 'Los Angeles'), +(3, 4.2, 'The Sushi Bar', 'Japanese', 'Los Angeles'), +(4, 4.7, 'The Pizza Place', 'Italian', 'New York'), +(5, 3.9, 'The Steakhouse', 'American', 'New York'), +(6, 4.3, 'The Ramen Shop', 'Japanese', 'New York'), +(7, 4.1, 'The Tacos & Burritos', 'Mexican', 'San Francisco'), +(8, 4.6, 'The Vegan Cafe', 'Vegan', 'San Francisco'), +(9, 3.7, 'The BBQ Joint', 'American', 'San Francisco'), +(10, 4.4, 'The Seafood Shack', 'Seafood', 'Miami'), +(11, 4.6, 'The Seafood Shack', 'Seafood', 'Miami'); diff --git a/tests/gen_data/init_defog_sqlite.sql b/tests/gen_data/init_defog_sqlite.sql index b38618e7d..598cf13e0 100644 --- a/tests/gen_data/init_defog_sqlite.sql +++ b/tests/gen_data/init_defog_sqlite.sql @@ -1085,3 +1085,59 @@ INSERT INTO writes (aid, pid) VALUES (2, 4), (2, 5), (3, 5); + +------------------------------------------------------------------------------- +--RESTAURANTS SCHEMA +CREATE TABLE geographic ( + city_name TEXT, + county TEXT, + region TEXT +); + +CREATE TABLE location ( + restaurant_id INTEGER, + house_number INTEGER, + street_name TEXT, + city_name TEXT +); + +CREATE TABLE restaurant ( + id INTEGER, + name TEXT, + food_type TEXT, + city_name TEXT, + rating REAL +); + +INSERT INTO geographic (city_name, county, region) VALUES +('Los Angeles', 'Los Angeles', 'California'), +('New York', 'New York', 'New York'), +('San Francisco', 'San Francisco', 'California'), +('Miami', 'Miami-Dade', 'Florida'), +('Chicago', 'Cook', 'Illinois'); + +INSERT INTO location (restaurant_id, house_number, street_name, city_name) VALUES +(1, 123, 'Main St', 'Los Angeles'), +(2, 456, 'Maple Ave', 'Los Angeles'), +(3, 789, 'Oak St', 'Los Angeles'), +(4, 321, 'Elm St', 'New York'), +(5, 654, 'Pine Ave', 'New York'), +(6, 123, 'Pine Ave', 'New York'), +(7, 12, 'Market St', 'San Francisco'), +(8, 34, 'Mission St', 'San Francisco'), +(9, 56, 'Valencia St', 'San Francisco'), +(10, 78, 'Ocean Dr', 'Miami'), +(11, 90, 'Biscayne Rd', 'Miami'); + +INSERT INTO restaurant (id, rating, name, food_type, city_name) VALUES +(1, 4.5, 'The Pasta House', 'Italian', 'Los Angeles'), +(2, 3.8, 'The Burger Joint', 'American', 'Los Angeles'), +(3, 4.2, 'The Sushi Bar', 'Japanese', 'Los Angeles'), +(4, 4.7, 'The Pizza Place', 'Italian', 'New York'), +(5, 3.9, 'The Steakhouse', 'American', 'New York'), +(6, 4.3, 'The Ramen Shop', 'Japanese', 'New York'), +(7, 4.1, 'The Tacos & Burritos', 'Mexican', 'San Francisco'), +(8, 4.6, 'The Vegan Cafe', 'Vegan', 'San Francisco'), +(9, 3.7, 'The BBQ Joint', 'American', 'San Francisco'), +(10, 4.4, 'The Seafood Shack', 'Seafood', 'Miami'), +(11, 4.6, 'The Seafood Shack', 'Seafood', 'Miami'); diff --git a/tests/test_metadata/defog_graphs.json b/tests/test_metadata/defog_graphs.json index 6e4bca072..ef5476294 100644 --- a/tests/test_metadata/defog_graphs.json +++ b/tests/test_metadata/defog_graphs.json @@ -4432,5 +4432,232 @@ "synonyms": ["publication's author", "work's author"] } ] + }, + { + "name": "Restaurants", + "version": "V2", + "collections": [ + { + "name": "cities", + "type": "simple table", + "table path": "main.geographic", + "unique properties": [ + "city_name" + ], + "properties": [ + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The name of the city", + "sample values": ["Los Angeles", "Miami"], + "synonyms": ["city"] + }, + { + "name": "county", + "type": "table column", + "column name": "county", + "data type": "string", + "description": "The name of the county", + "sample values": ["Miami-Dade", "Cook", "New York"], + "synonyms": ["division"] + }, + { + "name": "region", + "type": "table column", + "column name": "region", + "data type": "string", + "description": "The name of the region", + "sample values": ["California", "New York"], + "synonyms": ["territory"] + } + ], + "description": "Contains records of cities locations including its name, county and region", + "synonyms": ["locations", "places"] + }, + { + "name": "locations", + "type": "simple table", + "table path": "main.location", + "unique properties": [ + ["restaurant_id", "house_number", "street_name","city_name"] + ], + "properties": [ + { + "name": "restaurant_id", + "type": "table column", + "column name": "restaurant_id", + "data type": "numeric", + "description": "Unique identifier for each restaurant", + "sample values": [1, 2, 3], + "synonyms": ["restaurant_id", "diner_id"] + }, + { + "name": "house_number", + "type": "table column", + "column name": "house_number", + "data type": "numeric", + "description": "The number assigned to the building where the restaurant is located", + "sample values": [123, 789, 12], + "synonyms": ["street_number"] + }, + { + "name": "street_name", + "type": "table column", + "column name": "street_name", + "data type": "string", + "description": "The name of the street where the restaurant is located", + "sample values": ["Main St", "Oak St", "Pine Ave"], + "synonyms": ["avenue"] + }, + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The name of the city where the restaurant is located", + "sample values": ["New York", "Los Angeles", "Miami"], + "synonyms": [] + } + ], + "description": "Contains the location of each restaurant", + "synonyms": ["address"] + }, + { + "name": "restaurants", + "type": "simple table", + "table path": "main.restaurant", + "unique properties": [ + "id_" + ], + "properties": [ + { + "name": "id_", + "type": "table column", + "column name": "id", + "data type": "numeric", + "description": "Unique identifier for each restaurant", + "sample values": [1, 2, 3], + "synonyms": ["identifier"] + }, + { + "name": "name", + "type": "table column", + "column name": "name", + "data type": "string", + "description": "The name of the restaurant", + "sample values": ["The Pasta House", "The Burger Joint", "The Seafood Shack"], + "synonyms": ["restaurant"] + }, + { + "name": "food_type", + "type": "table column", + "column name": "food_type", + "data type": "string", + "description": "The type of food served at the restaurant", + "sample values": ["Seafood", "American", "Japanese"], + "synonyms": ["specialty", "menu type"] + }, + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The city where the restaurant is located", + "sample values": ["San Francisco", "New York", "Miami"], + "synonyms": ["locality", "town"] + }, + { + "name": "rating", + "type": "table column", + "column name": "rating", + "data type": "numeric", + "description": "The rating of the restaurant on a scale of 0 to 5", + "sample values": [4.2, 3.9, 4.5], + "synonyms": ["score", "review"] + } + ], + "description": "Contains the information of the restaurants", + "synonyms": ["diner"] + } + ], + "relationships": [ + { + "type": "simple join", + "name": "restaurant_locations", + "parent collection": "cities", + "child collection": "locations", + "singular": false, + "always matches": false, + "keys": { + "city_name": [ + "city_name" + ] + }, + "description": "All restaurant locations within the city", + "synonyms": ["restaurant locations"] + }, + { + "type": "reverse", + "name": "city", + "original parent": "cities", + "original property": "restaurant_locations", + "singular": true, + "always matches": false, + "description": "The geographic information for the city that the location belongs to", + "synonyms": ["geography", "town"] + }, + { + "type": "simple join", + "name": "location", + "parent collection": "restaurants", + "child collection": "locations", + "singular": true, + "always matches": true, + "keys": { + "id_": [ + "restaurant_id" + ] + }, + "description": "The location of this restaurant", + "synonyms": ["place", "diner"] + }, + { + "type": "reverse", + "name": "restaurant", + "original parent": "restaurants", + "original property": "location", + "singular": true, + "always matches": true, + "description": "The restaurant related to this location", + "synonyms": ["franchise", "chain"] + }, + { + "type": "simple join", + "name": "restaurants", + "parent collection": "cities", + "child collection": "restaurants", + "singular": false, + "always matches": false, + "keys": { + "city_name": [ + "city_name" + ] + }, + "description": "The restaurants located in this geographic territory", + "synonyms": ["diners"] + }, + { + "type": "reverse", + "name": "city", + "original parent": "cities", + "original property": "restaurants", + "singular": true, + "always matches": true, + "description": "The geographic territory related to this restaurant", + "synonyms": ["location", "territory"] + } + ] } ] diff --git a/tests/test_metadata/mysql_defog_graphs.json b/tests/test_metadata/mysql_defog_graphs.json index 21e3c8bfd..3b159985b 100644 --- a/tests/test_metadata/mysql_defog_graphs.json +++ b/tests/test_metadata/mysql_defog_graphs.json @@ -4432,5 +4432,232 @@ "synonyms": [] } ] + }, + { + "name": "Restaurants", + "version": "V2", + "collections": [ + { + "name": "cities", + "type": "simple table", + "table path": "restaurants.geographic", + "unique properties": [ + "city_name" + ], + "properties": [ + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The name of the city", + "sample values": ["Los Angeles", "Miami"], + "synonyms": ["city"] + }, + { + "name": "county", + "type": "table column", + "column name": "county", + "data type": "string", + "description": "The name of the county", + "sample values": ["Miami-Dade", "Cook", "New York"], + "synonyms": ["division"] + }, + { + "name": "region", + "type": "table column", + "column name": "region", + "data type": "string", + "description": "The name of the region", + "sample values": ["California", "New York"], + "synonyms": ["territory"] + } + ], + "description": "Contains records of cities locations including its name, county and region", + "synonyms": ["locations", "places"] + }, + { + "name": "locations", + "type": "simple table", + "table path": "restaurants.location", + "unique properties": [ + ["restaurant_id", "house_number", "street_name","city_name"] + ], + "properties": [ + { + "name": "restaurant_id", + "type": "table column", + "column name": "restaurant_id", + "data type": "numeric", + "description": "Unique identifier for each restaurant", + "sample values": [1, 2, 3], + "synonyms": ["restaurant_id", "diner_id"] + }, + { + "name": "house_number", + "type": "table column", + "column name": "house_number", + "data type": "numeric", + "description": "The number assigned to the building where the restaurant is located", + "sample values": [123, 789, 12], + "synonyms": ["street_number"] + }, + { + "name": "street_name", + "type": "table column", + "column name": "street_name", + "data type": "string", + "description": "The name of the street where the restaurant is located", + "sample values": ["Main St", "Oak St", "Pine Ave"], + "synonyms": ["avenue"] + }, + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The name of the city where the restaurant is located", + "sample values": ["New York", "Los Angeles", "Miami"], + "synonyms": [] + } + ], + "description": "Contains the location of each restaurant", + "synonyms": ["address"] + }, + { + "name": "restaurants", + "type": "simple table", + "table path": "restaurants.restaurant", + "unique properties": [ + "id_" + ], + "properties": [ + { + "name": "id_", + "type": "table column", + "column name": "id", + "data type": "numeric", + "description": "Unique identifier for each restaurant", + "sample values": [1, 2, 3], + "synonyms": ["identifier"] + }, + { + "name": "name", + "type": "table column", + "column name": "name", + "data type": "string", + "description": "The name of the restaurant", + "sample values": ["The Pasta House", "The Burger Joint", "The Seafood Shack"], + "synonyms": ["restaurant"] + }, + { + "name": "food_type", + "type": "table column", + "column name": "food_type", + "data type": "string", + "description": "The type of food served at the restaurant", + "sample values": ["Seafood", "American", "Japanese"], + "synonyms": ["specialty", "menu type"] + }, + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The city where the restaurant is located", + "sample values": ["San Francisco", "New York", "Miami"], + "synonyms": ["locality", "town"] + }, + { + "name": "rating", + "type": "table column", + "column name": "rating", + "data type": "numeric", + "description": "The rating of the restaurant on a scale of 0 to 5", + "sample values": [4.2, 3.9, 4.5], + "synonyms": ["score", "review"] + } + ], + "description": "Contains the information of the restaurants", + "synonyms": ["diner"] + } + ], + "relationships": [ + { + "type": "simple join", + "name": "restaurant_locations", + "parent collection": "cities", + "child collection": "locations", + "singular": false, + "always matches": false, + "keys": { + "city_name": [ + "city_name" + ] + }, + "description": "All restaurant locations within the city", + "synonyms": ["restaurant locations"] + }, + { + "type": "reverse", + "name": "city", + "original parent": "cities", + "original property": "restaurant_locations", + "singular": true, + "always matches": false, + "description": "The geographic information for the city that the location belongs to", + "synonyms": ["geography", "town"] + }, + { + "type": "simple join", + "name": "location", + "parent collection": "restaurants", + "child collection": "locations", + "singular": true, + "always matches": true, + "keys": { + "id_": [ + "restaurant_id" + ] + }, + "description": "The location of this restaurant", + "synonyms": ["place", "diner"] + }, + { + "type": "reverse", + "name": "restaurant", + "original parent": "restaurants", + "original property": "location", + "singular": true, + "always matches": true, + "description": "The restaurant related to this location", + "synonyms": ["franchise", "chain"] + }, + { + "type": "simple join", + "name": "restaurants", + "parent collection": "cities", + "child collection": "restaurants", + "singular": false, + "always matches": false, + "keys": { + "city_name": [ + "city_name" + ] + }, + "description": "The restaurants located in this geographic territory", + "synonyms": ["diners"] + }, + { + "type": "reverse", + "name": "city", + "original parent": "cities", + "original property": "restaurants", + "singular": true, + "always matches": true, + "description": "The geographic territory related to this restaurant", + "synonyms": ["location", "territory"] + } + ] } ] diff --git a/tests/test_metadata/snowflake_defog_graphs.json b/tests/test_metadata/snowflake_defog_graphs.json index 7ef7c34d9..862c7dee4 100644 --- a/tests/test_metadata/snowflake_defog_graphs.json +++ b/tests/test_metadata/snowflake_defog_graphs.json @@ -4432,5 +4432,232 @@ "synonyms": [] } ] + }, + { + "name": "Restaurants", + "version": "V2", + "collections": [ + { + "name": "cities", + "type": "simple table", + "table path": "restaurants.geographic", + "unique properties": [ + "city_name" + ], + "properties": [ + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The name of the city", + "sample values": ["Los Angeles", "Miami"], + "synonyms": ["city"] + }, + { + "name": "county", + "type": "table column", + "column name": "county", + "data type": "string", + "description": "The name of the county", + "sample values": ["Miami-Dade", "Cook", "New York"], + "synonyms": ["division"] + }, + { + "name": "region", + "type": "table column", + "column name": "region", + "data type": "string", + "description": "The name of the region", + "sample values": ["California", "New York"], + "synonyms": ["territory"] + } + ], + "description": "Contains records of cities locations including its name, county and region", + "synonyms": ["locations", "places"] + }, + { + "name": "locations", + "type": "simple table", + "table path": "restaurants.location", + "unique properties": [ + ["restaurant_id", "house_number", "street_name","city_name"] + ], + "properties": [ + { + "name": "restaurant_id", + "type": "table column", + "column name": "restaurant_id", + "data type": "numeric", + "description": "Unique identifier for each restaurant", + "sample values": [1, 2, 3], + "synonyms": ["restaurant_id", "diner_id"] + }, + { + "name": "house_number", + "type": "table column", + "column name": "house_number", + "data type": "numeric", + "description": "The number assigned to the building where the restaurant is located", + "sample values": [123, 789, 12], + "synonyms": ["street_number"] + }, + { + "name": "street_name", + "type": "table column", + "column name": "street_name", + "data type": "string", + "description": "The name of the street where the restaurant is located", + "sample values": ["Main St", "Oak St", "Pine Ave"], + "synonyms": ["avenue"] + }, + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The name of the city where the restaurant is located", + "sample values": ["New York", "Los Angeles", "Miami"], + "synonyms": [] + } + ], + "description": "Contains the location of each restaurant", + "synonyms": ["address"] + }, + { + "name": "restaurants", + "type": "simple table", + "table path": "restaurants.restaurant", + "unique properties": [ + "id_" + ], + "properties": [ + { + "name": "id_", + "type": "table column", + "column name": "id", + "data type": "numeric", + "description": "Unique identifier for each restaurant", + "sample values": [1, 2, 3], + "synonyms": ["identifier"] + }, + { + "name": "name", + "type": "table column", + "column name": "name", + "data type": "string", + "description": "The name of the restaurant", + "sample values": ["The Pasta House", "The Burger Joint", "The Seafood Shack"], + "synonyms": ["restaurant"] + }, + { + "name": "food_type", + "type": "table column", + "column name": "food_type", + "data type": "string", + "description": "The type of food served at the restaurant", + "sample values": ["Seafood", "American", "Japanese"], + "synonyms": ["specialty", "menu type"] + }, + { + "name": "city_name", + "type": "table column", + "column name": "city_name", + "data type": "string", + "description": "The city where the restaurant is located", + "sample values": ["San Francisco", "New York", "Miami"], + "synonyms": ["locality", "town"] + }, + { + "name": "rating", + "type": "table column", + "column name": "rating", + "data type": "numeric", + "description": "The rating of the restaurant on a scale of 0 to 5", + "sample values": [4.2, 3.9, 4.5], + "synonyms": ["score", "review"] + } + ], + "description": "Contains the information of the restaurants", + "synonyms": ["diner"] + } + ], + "relationships": [ + { + "type": "simple join", + "name": "restaurant_locations", + "parent collection": "cities", + "child collection": "locations", + "singular": false, + "always matches": false, + "keys": { + "city_name": [ + "city_name" + ] + }, + "description": "All restaurant locations within the city", + "synonyms": ["restaurant locations"] + }, + { + "type": "reverse", + "name": "city", + "original parent": "cities", + "original property": "restaurant_locations", + "singular": true, + "always matches": false, + "description": "The geographic information for the city that the location belongs to", + "synonyms": ["geography", "town"] + }, + { + "type": "simple join", + "name": "location", + "parent collection": "restaurants", + "child collection": "locations", + "singular": true, + "always matches": true, + "keys": { + "id_": [ + "restaurant_id" + ] + }, + "description": "The location of this restaurant", + "synonyms": ["place", "diner"] + }, + { + "type": "reverse", + "name": "restaurant", + "original parent": "restaurants", + "original property": "location", + "singular": true, + "always matches": true, + "description": "The restaurant related to this location", + "synonyms": ["franchise", "chain"] + }, + { + "type": "simple join", + "name": "restaurants", + "parent collection": "cities", + "child collection": "restaurants", + "singular": false, + "always matches": false, + "keys": { + "city_name": [ + "city_name" + ] + }, + "description": "The restaurants located in this geographic territory", + "synonyms": ["diners"] + }, + { + "type": "reverse", + "name": "city", + "original parent": "cities", + "original property": "restaurants", + "singular": true, + "always matches": true, + "description": "The geographic territory related to this restaurant", + "synonyms": ["location", "territory"] + } + ] } ] diff --git a/tests/test_pipeline_defog.py b/tests/test_pipeline_defog.py index 0cf29fe9d..24999572d 100644 --- a/tests/test_pipeline_defog.py +++ b/tests/test_pipeline_defog.py @@ -163,6 +163,31 @@ defog_sql_text_ewallet_gen3, defog_sql_text_ewallet_gen4, defog_sql_text_ewallet_gen5, + defog_sql_text_restaurants_gen1, + defog_sql_text_restaurants_gen2, + defog_sql_text_restaurants_gen3, + defog_sql_text_restaurants_gen4, + defog_sql_text_restaurants_gen5, + defog_sql_text_restaurants_gen6, + defog_sql_text_restaurants_gen7, + defog_sql_text_restaurants_gen8, + defog_sql_text_restaurants_gen9, + defog_sql_text_restaurants_gen10, + defog_sql_text_restaurants_gen11, + defog_sql_text_restaurants_gen12, + defog_sql_text_restaurants_gen13, + defog_sql_text_restaurants_gen14, + defog_sql_text_restaurants_gen15, + defog_sql_text_restaurants_gen16, + defog_sql_text_restaurants_gen17, + defog_sql_text_restaurants_gen18, + defog_sql_text_restaurants_gen19, + defog_sql_text_restaurants_gen20, + defog_sql_text_restaurants_gen21, + defog_sql_text_restaurants_gen22, + defog_sql_text_restaurants_gen23, + defog_sql_text_restaurants_gen24, + defog_sql_text_restaurants_gen25, ) from tests.test_pydough_functions.defog_test_functions import ( impl_defog_academic_gen1, @@ -314,6 +339,31 @@ impl_defog_ewallet_gen3, impl_defog_ewallet_gen4, impl_defog_ewallet_gen5, + impl_defog_restaurants_gen1, + impl_defog_restaurants_gen2, + impl_defog_restaurants_gen3, + impl_defog_restaurants_gen4, + impl_defog_restaurants_gen5, + impl_defog_restaurants_gen6, + impl_defog_restaurants_gen7, + impl_defog_restaurants_gen8, + impl_defog_restaurants_gen9, + impl_defog_restaurants_gen10, + impl_defog_restaurants_gen11, + impl_defog_restaurants_gen12, + impl_defog_restaurants_gen13, + impl_defog_restaurants_gen14, + impl_defog_restaurants_gen15, + impl_defog_restaurants_gen16, + impl_defog_restaurants_gen17, + impl_defog_restaurants_gen18, + impl_defog_restaurants_gen19, + impl_defog_restaurants_gen20, + impl_defog_restaurants_gen21, + impl_defog_restaurants_gen22, + impl_defog_restaurants_gen23, + impl_defog_restaurants_gen24, + impl_defog_restaurants_gen25, ) from tests.testing_utilities import ( PyDoughSQLComparisonTest, @@ -1724,6 +1774,237 @@ def test_graph_structure_defog(defog_graphs: graph_fetcher, graph_name: str) -> ), id="academic_gen25", ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen1, + "Restaurants", + defog_sql_text_restaurants_gen1, + "restaurants_gen1", + ), + id="restaurants_gen1", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen2, + "Restaurants", + defog_sql_text_restaurants_gen2, + "restaurants_gen2", + ), + id="restaurants_gen2", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen3, + "Restaurants", + defog_sql_text_restaurants_gen3, + "restaurants_gen3", + order_sensitive=True, + ), + id="restaurants_gen3", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen4, + "Restaurants", + defog_sql_text_restaurants_gen4, + "restaurants_gen4", + order_sensitive=True, + ), + id="restaurants_gen4", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen5, + "Restaurants", + defog_sql_text_restaurants_gen5, + "restaurants_gen5", + order_sensitive=True, + ), + id="restaurants_gen5", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen6, + "Restaurants", + defog_sql_text_restaurants_gen6, + "restaurants_gen6", + ), + id="restaurants_gen6", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen7, + "Restaurants", + defog_sql_text_restaurants_gen7, + "restaurants_gen7", + ), + id="restaurants_gen7", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen8, + "Restaurants", + defog_sql_text_restaurants_gen8, + "restaurants_gen8", + order_sensitive=True, + ), + id="restaurants_gen8", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen9, + "Restaurants", + defog_sql_text_restaurants_gen9, + "restaurants_gen9", + order_sensitive=True, + ), + id="restaurants_gen9", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen10, + "Restaurants", + defog_sql_text_restaurants_gen10, + "restaurants_gen10", + order_sensitive=True, + ), + id="restaurants_gen10", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen11, + "Restaurants", + defog_sql_text_restaurants_gen11, + "restaurants_gen11", + ), + id="restaurants_gen11", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen12, + "Restaurants", + defog_sql_text_restaurants_gen12, + "restaurants_gen12", + ), + id="restaurants_gen12", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen13, + "Restaurants", + defog_sql_text_restaurants_gen13, + "restaurants_gen13", + ), + id="restaurants_gen13", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen14, + "Restaurants", + defog_sql_text_restaurants_gen14, + "restaurants_gen14", + ), + id="restaurants_gen14", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen15, + "Restaurants", + defog_sql_text_restaurants_gen15, + "restaurants_gen15", + ), + id="restaurants_gen15", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen16, + "Restaurants", + defog_sql_text_restaurants_gen16, + "restaurants_gen16", + ), + id="restaurants_gen16", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen17, + "Restaurants", + defog_sql_text_restaurants_gen17, + "restaurants_gen17", + ), + id="restaurants_gen17", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen18, + "Restaurants", + defog_sql_text_restaurants_gen18, + "restaurants_gen18", + ), + id="restaurants_gen18", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen19, + "Restaurants", + defog_sql_text_restaurants_gen19, + "restaurants_gen19", + ), + id="restaurants_gen19", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen20, + "Restaurants", + defog_sql_text_restaurants_gen20, + "restaurants_gen20", + ), + id="restaurants_gen20", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen21, + "Restaurants", + defog_sql_text_restaurants_gen21, + "restaurants_gen21", + ), + id="restaurants_gen21", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen22, + "Restaurants", + defog_sql_text_restaurants_gen22, + "restaurants_gen22", + ), + id="restaurants_gen22", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen23, + "Restaurants", + defog_sql_text_restaurants_gen23, + "restaurants_gen23", + ), + id="restaurants_gen23", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen24, + "Restaurants", + defog_sql_text_restaurants_gen24, + "restaurants_gen24", + ), + id="restaurants_gen24", + ), + pytest.param( + PyDoughSQLComparisonTest( + impl_defog_restaurants_gen25, + "Restaurants", + defog_sql_text_restaurants_gen25, + "restaurants_gen25", + ), + id="restaurants_gen25", + ), ], ) def defog_pipeline_test_data( diff --git a/tests/test_pydough_functions/defog_outputs.py b/tests/test_pydough_functions/defog_outputs.py index c7c4fc060..ea39c0a2f 100644 --- a/tests/test_pydough_functions/defog_outputs.py +++ b/tests/test_pydough_functions/defog_outputs.py @@ -2903,3 +2903,399 @@ def defog_sql_text_academic_gen25() -> str: JOIN domain ON domain_publication.did = domain.did WHERE LOWER(domain.name) LIKE LOWER('%computer%science%'); """ + + +def defog_sql_text_restaurants_gen1() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the total number of restaurants serving each type of food? + """ + return """ + SELECT + restaurant.food_type, + COUNT(DISTINCT restaurant.id) AS total_number_of_restaurants + FROM restaurant GROUP BY restaurant.food_type; + """ + + +def defog_sql_text_restaurants_gen2() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the total count of restaurants in each city? + """ + return """ + SELECT + location.city_name, + COUNT(DISTINCT location.restaurant_id) AS total_count + FROM LOCATION GROUP BY location.city_name; + """ + + +def defog_sql_text_restaurants_gen3() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the average rating of restaurants serving each type of food? + """ + return """ + SELECT + restaurant.food_type, + AVG(restaurant.rating) AS average_rating + FROM restaurant + GROUP BY restaurant.food_type + ORDER BY average_rating DESC; + """ + + +def defog_sql_text_restaurants_gen4() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + How many restaurants serve Italian food in each city? + """ + return """ + SELECT + restaurant.city_name, + COUNT(*) AS number_of_restaurants + FROM restaurant + WHERE LOWER(restaurant.food_type) LIKE LOWER('%Italian%') + GROUP BY restaurant.city_name + ORDER BY number_of_restaurants DESC; + """ + + +def defog_sql_text_restaurants_gen5() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + How many restaurants are there in each city? Order the results by the + number of restaurants in descending order. + """ + return """ + SELECT + location.city_name, + COUNT(DISTINCT location.restaurant_id) AS number_of_restaurants + FROM LOCATION + GROUP BY location.city_name + ORDER BY number_of_restaurants DESC; + """ + + +def defog_sql_text_restaurants_gen6() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + Which street has the most number of restaurants? + """ + return """ + SELECT street_name + FROM location + GROUP BY street_name + ORDER BY COUNT(restaurant_id) DESC NULLS FIRST LIMIT 1; + """ + + +def defog_sql_text_restaurants_gen7() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + Which restaurants serve Italian cuisine or are located in New York? Order + the results by the restaurant name. + """ + return """ + SELECT name + FROM restaurant + WHERE LOWER(food_type) LIKE LOWER('%Italian%') + OR LOWER(city_name) LIKE LOWER('%New York%') + ORDER BY name NULLS LAST; + """ + + +def defog_sql_text_restaurants_gen8() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the average rating of restaurants in each region? Order the results + by the region name. + """ + return """ + SELECT + geographic.region, + AVG(restaurant.rating) AS average_rating + FROM restaurant + JOIN geographic ON restaurant.city_name = geographic.city_name + GROUP BY geographic.region + ORDER BY geographic.region NULLS LAST; + """ + + +def defog_sql_text_restaurants_gen9() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What are the names of the top 3 restaurants with the highest ratings? + """ + return """ + SELECT restaurant.name + FROM restaurant + ORDER BY restaurant.rating DESC LIMIT 3; + """ + + +def defog_sql_text_restaurants_gen10() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + List the restaurants starting from the best ratings to the lowest + """ + return """ + SELECT name, rating + FROM restaurant + ORDER BY rating DESC NULLS FIRST; + """ + + +def defog_sql_text_restaurants_gen11() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the ratio of restaurants with rating > 4.5 to the total number of + restaurants in the database. + """ + return """ + SELECT + CAST(COUNT(*) AS REAL) / NULLIF((SELECT COUNT(*) FROM restaurant), 0) AS rating_ratio + FROM restaurant WHERE rating > 4.5; + """ + + +def defog_sql_text_restaurants_gen12() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the ratio of restaurants with a rating above 4.0 to restaurants with + a rating below 4.0 overall? + """ + return """ + SELECT CAST( + SUM(CASE WHEN restaurant.rating > 4.0 THEN 1 ELSE 0 END) AS REAL + ) / NULLIF( + SUM(CASE WHEN restaurant.rating < 4.0 THEN 1 ELSE 0 END), 0 + ) AS ratio + FROM restaurant; + """ + + +def defog_sql_text_restaurants_gen13() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the ratio of restaurants with a rating above 4 to restaurants with + a rating below 4 in New York? + """ + return """ + SELECT CAST( + COUNT(CASE WHEN rating > 4 THEN 1 END) AS REAL + ) / NULLIF( + COUNT(CASE WHEN rating < 4 THEN 1 END), 0 + ) AS ratio + FROM restaurant WHERE LOWER(city_name) LIKE LOWER('New York'); + """ + + +def defog_sql_text_restaurants_gen14() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the ratio of restaurants serving vegan food to restaurants serving + non-vegan food in San Francisco? Match food_type case insensitively + """ + return """ + SELECT CAST( + SUM(CASE WHEN LOWER(restaurant.food_type) LIKE '%vegan%' THEN 1 ELSE 0 END) AS REAL + ) / NULLIF( + SUM(CASE WHEN NOT LOWER(restaurant.food_type) LIKE '%vegan%' THEN 1 ELSE 0 END), 0 + ) AS ratio + FROM restaurant + WHERE LOWER(LOWER(restaurant.city_name)) LIKE LOWER('%san francisco%'); + """ + + +def defog_sql_text_restaurants_gen15() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the ratio of Italian restaurants out of all restaurants in + Los Angeles? + """ + return """ + SELECT CAST( + COUNT(CASE WHEN LOWER(food_type) LIKE LOWER('%Italian%') THEN 1 END) AS REAL + ) / NULLIF( + COUNT(food_type), 0 + ) AS ratio + FROM restaurant + WHERE LOWER(city_name) LIKE LOWER('%Los Angeles%'); + """ + + +def defog_sql_text_restaurants_gen16() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What cities have more than one restaurants with the same name, and how many + of them are there? Return the city name, restaurant name, and restaurant + count + """ + return """ + SELECT + r.city_name, + r.name, + COUNT(r.id) AS restaurant_count + FROM restaurant AS r + GROUP BY r.city_name, r.name + HAVING COUNT(r.id) > 1; + """ + + +def defog_sql_text_restaurants_gen17() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the average rating of restaurants that serve Mexican food in each + city? + """ + return """ + SELECT + location.city_name, + AVG(restaurant.rating) AS average_rating + FROM restaurant JOIN LOCATION ON restaurant.id = location.restaurant_id + WHERE LOWER(restaurant.food_type) LIKE '%mexican%' + GROUP BY location.city_name; + """ + + +def defog_sql_text_restaurants_gen18() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What is the average rating of restaurants in each region? + """ + return """ + SELECT + geographic.region, + AVG(restaurant.rating) AS average_rating + FROM geographic + JOIN restaurant ON geographic.city_name = restaurant.city_name + GROUP BY 1; + """ + + +def defog_sql_text_restaurants_gen19() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + How many restaurants serve Italian food in each region? + """ + return """ + SELECT + geographic.region, + COUNT(restaurant.id) AS number_of_restaurants + FROM restaurant + JOIN geographic ON restaurant.city_name = geographic.city_name + WHERE LOWER(restaurant.food_type) LIKE '%italian%' + GROUP BY geographic.region + ORDER BY number_of_restaurants DESC; + """ + + +def defog_sql_text_restaurants_gen20() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + How many restaurants are there in each region? + """ + return """ + SELECT + geographic.region, + COUNT(DISTINCT restaurant.id) AS number_of_restaurants + FROM geographic + JOIN restaurant ON geographic.city_name = restaurant.city_name + GROUP BY geographic.region + ORDER BY number_of_restaurants DESC NULLS FIRST; + """ + + +def defog_sql_text_restaurants_gen21() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + Which city has the highest-rated restaurant? + """ + return """ + SELECT DISTINCT restaurant.city_name + FROM restaurant + WHERE rating = (SELECT MAX(rating) FROM restaurant); + """ + + +def defog_sql_text_restaurants_gen22() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What's the name and rating of all the restaurants that have a rating greater + than 4 and are located in the city of New York? + """ + return """ + SELECT restaurant.name, restaurant.rating + FROM restaurant + WHERE restaurant.rating > 4 + AND LOWER(restaurant.city_name) LIKE LOWER('%New York%'); + """ + + +def defog_sql_text_restaurants_gen23() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What's the name and food type of all the restaurants located on Market St in + San Francisco? + """ + return """ + SELECT restaurant.name, restaurant.food_type + FROM restaurant + JOIN LOCATION ON restaurant.id = location.restaurant_id + WHERE LOWER(location.street_name) LIKE LOWER('%Market St%') + AND LOWER(location.city_name) LIKE LOWER('%San Francisco%'); + """ + + +def defog_sql_text_restaurants_gen24() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What are the names of the restaurants that serve Italian food? + """ + return """ + SELECT restaurant.name + FROM restaurant + WHERE LOWER(LOWER(restaurant.food_type)) LIKE LOWER('%italian%'); + """ + + +def defog_sql_text_restaurants_gen25() -> str: + """ + SQLite query text for the following question for the Restaurants graph: + + What are the names of the restaurants in Los Angeles that have a rating + higher than 4? + """ + return """ + SELECT DISTINCT restaurant.name + FROM restaurant + WHERE LOWER(restaurant.city_name) LIKE LOWER('%Los Angeles%') + AND restaurant.rating > 4 + ORDER BY restaurant.name NULLS LAST; + """ diff --git a/tests/test_pydough_functions/defog_test_functions.py b/tests/test_pydough_functions/defog_test_functions.py index 3a4e26144..d000330d2 100644 --- a/tests/test_pydough_functions/defog_test_functions.py +++ b/tests/test_pydough_functions/defog_test_functions.py @@ -1792,7 +1792,7 @@ def impl_defog_dermtreatment_basic1(): # Find the treatments from the doctors within the specialty in the past 6 months recent_treatments = doctors.prescribed_treatments.WHERE( - DATEDIFF("months", start_date, DATETIME("now")) <= 6 + start_date >= DATETIME("now", "-6 months", "start of day") ) # Calculate totals for each specialty @@ -2777,3 +2777,345 @@ def impl_defog_academic_gen25(): .PARTITION(name="authors", by=author_name) .CALCULATE(author_name) ) + + +def impl_defog_restaurants_gen1(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the total number of restaurants serving each type of food? + """ + return restaurants.PARTITION(name="food", by=food_type).CALCULATE( + food_type, restaurants=COUNT(restaurants) + ) + + +def impl_defog_restaurants_gen2(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the total count of restaurants in each city? + """ + return locations.PARTITION(name="city", by=city_name).CALCULATE( + city_name, total_count=COUNT(locations) + ) + + +def impl_defog_restaurants_gen3(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the average rating of restaurants serving each type of food? + """ + return ( + restaurants.PARTITION(name="food", by=food_type) + .CALCULATE(food_type, avg_rating=AVG(restaurants.rating)) + .ORDER_BY(avg_rating.DESC(), food_type.DESC()) + ) + + +def impl_defog_restaurants_gen4(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + How many restaurants serve Italian food in each city? + """ + return ( + restaurants.WHERE(LOWER(food_type) == "italian") + .PARTITION(name="cities", by=city_name) + .CALCULATE(city_name, num_restaurants=COUNT(restaurants)) + .ORDER_BY(num_restaurants.DESC(), city_name.DESC()) + ) + + +def impl_defog_restaurants_gen5(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + How many restaurants are there in each city? Order the results by the + number of restaurants in descending order. + """ + return ( + locations.PARTITION(name="cities", by=city_name) + .CALCULATE(city_name, num_restaurants=COUNT(locations)) + .ORDER_BY(num_restaurants.DESC(), city_name.DESC()) + ) + + +def impl_defog_restaurants_gen6(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + Which street has the most number of restaurants? + """ + return ( + locations.PARTITION(name="streets", by=street_name) + .TOP_K(1, by=COUNT(locations).DESC()) + .CALCULATE(street_name) + ) + + +def impl_defog_restaurants_gen7(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + Which restaurants serve Italian cuisine or are located in New York? Order + the results by the restaurant name. + """ + return restaurants.WHERE( + (LOWER(food_type) == "italian") | (LOWER(city_name) == "new york") + ).CALCULATE(name) + + +def impl_defog_restaurants_gen8(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the average rating of restaurants in each region? Order the results + by the region name. + """ + return ( + locations.CALCULATE(region_name=city.region) + .PARTITION(name="region", by=region_name) + .CALCULATE(region_name, avg_rating=AVG(locations.restaurant.rating)) + .ORDER_BY(region_name.ASC(), avg_rating.DESC()) + ) + + +def impl_defog_restaurants_gen9(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What are the names of the top 3 restaurants with the highest ratings? + """ + return restaurants.CALCULATE(name).TOP_K(3, by=(rating.DESC(), name.DESC())) + + +def impl_defog_restaurants_gen10(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + List the restaurants starting from the best ratings to the lowest + """ + return restaurants.CALCULATE(name, rating).ORDER_BY(rating.DESC(), name.DESC()) + + +def impl_defog_restaurants_gen11(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the ratio of restaurants with rating > 4.5 to the total number of + restaurants in the database. + """ + high_rated_restaurants = restaurants.WHERE(rating > 4.5) + return Restaurants.CALCULATE( + ratio=(COUNT(high_rated_restaurants) / COUNT(restaurants)) + ) + + +def impl_defog_restaurants_gen12(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the ratio of restaurants with a rating above 4.0 to restaurants with + a rating below 4.0 overall? + """ + n_hi_rating = SUM(restaurants.rating > 4.0) + n_lo_rating = SUM(restaurants.rating < 4.0) + return Restaurants.CALCULATE( + ratio=n_hi_rating / KEEP_IF(n_lo_rating, n_lo_rating != 0) + ) + + +def impl_defog_restaurants_gen13(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the ratio of restaurants with a rating above 4 to restaurants with + a rating below 4 in New York? + """ + nyc_restaurants = restaurants.WHERE(LOWER(city_name) == "new york") + n_hi_rating = SUM(nyc_restaurants.rating > 4.0) + n_lo_rating = SUM(nyc_restaurants.rating < 4.0) + return Restaurants.CALCULATE( + ratio=(n_hi_rating / KEEP_IF(n_lo_rating, n_lo_rating != 0)) + ) + + +def impl_defog_restaurants_gen14(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the ratio of restaurants serving vegan food to restaurants serving + non-vegan food in San Francisco? Match food_type case insensitively + """ + sf_restaurants = restaurants.WHERE(LOWER(city_name) == "san francisco") + n_vegan = SUM(LOWER(sf_restaurants.food_type) == "vegan") + n_non_vegan = SUM(LOWER(sf_restaurants.food_type) != "vegan") + return Restaurants.CALCULATE( + ratio=(n_vegan / KEEP_IF(n_non_vegan, n_non_vegan != 0)) + ) + + +def impl_defog_restaurants_gen15(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the ratio of Italian restaurants out of all restaurants in + Los Angeles? + """ + la_restaurants = restaurants.WHERE(LOWER(city_name) == "los angeles") + n_la_italian = SUM(LOWER(la_restaurants.food_type) == "italian") + n_la = COUNT(la_restaurants) + return Restaurants.CALCULATE(ratio=(n_la_italian / KEEP_IF(n_la, n_la != 0))) + + +def impl_defog_restaurants_gen16(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What cities have more than one restaurants with the same name, and how many + of them are there? Return the city name, restaurant name, and restaurant + count + """ + return ( + restaurants.PARTITION(name="cities", by=(city_name, name)) + .CALCULATE(city_name, name, n_restaurants=COUNT(restaurants)) + .WHERE(n_restaurants > 1) + ) + + +def impl_defog_restaurants_gen17(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the average rating of restaurants that serve Mexican food in each + city? + """ + return ( + restaurants.WHERE(LOWER(food_type) == "mexican") + .PARTITION(name="cities", by=city_name) + .CALCULATE(city_name, avg_rating=AVG(restaurants.rating)) + ) + + +def impl_defog_restaurants_gen18(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What is the average rating of restaurants in each region? + """ + return ( + cities.WHERE(HAS(restaurants)) + .PARTITION(name="regions", by=region) + .CALCULATE(rest_region=region, avg_rating=AVG(cities.restaurants.rating)) + .ORDER_BY(region.ASC()) + ) + + +def impl_defog_restaurants_gen19(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + How many restaurants serve Italian food in each region? + """ + return ( + restaurants.WHERE(LOWER(food_type) == "italian") + .CALCULATE(rest_region=city.region) + .PARTITION(name="regions", by=rest_region) + .CALCULATE(rest_region, n_restaurants=COUNT(restaurants)) + .ORDER_BY(n_restaurants.DESC(), rest_region.ASC()) + ) + + +def impl_defog_restaurants_gen20(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + How many restaurants are there in each region? + """ + return ( + restaurants.CALCULATE(rest_region=city.region) + .PARTITION(name="regions", by=rest_region) + .CALCULATE(rest_region, n_restaurants=COUNT(restaurants)) + .ORDER_BY(n_restaurants.DESC(), rest_region.ASC()) + ) + + +def impl_defog_restaurants_gen21(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + Which city has the highest-rated restaurant? + """ + return restaurants.TOP_K(1, by=rating.DESC()).CALCULATE(city_name) + + +def impl_defog_restaurants_gen22(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What's the name and rating of all the restaurants that have a rating greater + than 4 and are located in the city of New York? + """ + return restaurants.WHERE((rating > 4) & (LOWER(city_name) == "new york")).CALCULATE( + name, rating + ) + + +def impl_defog_restaurants_gen23(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What's the name and food type of all the restaurants located on Market St in + San Francisco? + """ + return locations.WHERE( + (LOWER(street_name) == "market st") & (LOWER(city_name) == "san francisco") + ).CALCULATE(restaurant.name, restaurant.food_type) + + +def impl_defog_restaurants_gen24(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + What are the names of the restaurants that serve Italian food? + """ + return restaurants.WHERE((LOWER(food_type) == "italian")).CALCULATE(name) + + +def impl_defog_restaurants_gen25(): + """ + PyDough implementation of the following question for the Restaurants + graph: + + WWhat are the names of the restaurants in Los Angeles that have a rating + higher than 4? + """ + return restaurants.WHERE( + (rating > 4) & (LOWER(city_name) == "los angeles") + ).CALCULATE(name) diff --git a/tests/test_sql_refsols/defog_dermtreatment_basic1_ansi.sql b/tests/test_sql_refsols/defog_dermtreatment_basic1_ansi.sql index 36995e1d9..f6fbe2cee 100644 --- a/tests/test_sql_refsols/defog_dermtreatment_basic1_ansi.sql +++ b/tests/test_sql_refsols/defog_dermtreatment_basic1_ansi.sql @@ -5,7 +5,7 @@ WITH _s1 AS ( SUM(tot_drug_amt) AS sum_tot_drug_amt FROM main.treatments WHERE - DATEDIFF(CURRENT_TIMESTAMP(), CAST(start_dt AS DATETIME), MONTH) <= 6 + start_dt >= DATE_TRUNC('DAY', DATE_SUB(CURRENT_TIMESTAMP(), 6, MONTH)) GROUP BY 1 ), _t1 AS ( diff --git a/tests/test_sql_refsols/defog_dermtreatment_basic1_mysql.sql b/tests/test_sql_refsols/defog_dermtreatment_basic1_mysql.sql index 32b7d7fe8..ec0b04d18 100644 --- a/tests/test_sql_refsols/defog_dermtreatment_basic1_mysql.sql +++ b/tests/test_sql_refsols/defog_dermtreatment_basic1_mysql.sql @@ -5,13 +5,7 @@ WITH _s1 AS ( SUM(tot_drug_amt) AS sum_tot_drug_amt FROM main.treatments WHERE - ( - ( - YEAR(CURRENT_TIMESTAMP()) - YEAR(start_dt) - ) * 12 + ( - MONTH(CURRENT_TIMESTAMP()) - MONTH(start_dt) - ) - ) <= 6 + start_dt >= CAST(DATE_SUB(CURRENT_TIMESTAMP(), INTERVAL '6' MONTH) AS DATE) GROUP BY 1 ), _t1 AS ( diff --git a/tests/test_sql_refsols/defog_dermtreatment_basic1_postgres.sql b/tests/test_sql_refsols/defog_dermtreatment_basic1_postgres.sql index 61f47f4bc..b36c34e24 100644 --- a/tests/test_sql_refsols/defog_dermtreatment_basic1_postgres.sql +++ b/tests/test_sql_refsols/defog_dermtreatment_basic1_postgres.sql @@ -5,13 +5,7 @@ WITH _s1 AS ( SUM(tot_drug_amt) AS sum_tot_drug_amt FROM main.treatments WHERE - ( - ( - EXTRACT(YEAR FROM CURRENT_TIMESTAMP) - EXTRACT(YEAR FROM CAST(start_dt AS TIMESTAMP)) - ) * 12 + ( - EXTRACT(MONTH FROM CURRENT_TIMESTAMP) - EXTRACT(MONTH FROM CAST(start_dt AS TIMESTAMP)) - ) - ) <= 6 + start_dt >= DATE_TRUNC('DAY', CURRENT_TIMESTAMP - INTERVAL '6 MONTH') GROUP BY 1 ), _t1 AS ( diff --git a/tests/test_sql_refsols/defog_dermtreatment_basic1_snowflake.sql b/tests/test_sql_refsols/defog_dermtreatment_basic1_snowflake.sql index cda7df693..82c37ab10 100644 --- a/tests/test_sql_refsols/defog_dermtreatment_basic1_snowflake.sql +++ b/tests/test_sql_refsols/defog_dermtreatment_basic1_snowflake.sql @@ -5,7 +5,7 @@ WITH _s1 AS ( SUM(tot_drug_amt) AS sum_tot_drug_amt FROM main.treatments WHERE - DATEDIFF(MONTH, CAST(start_dt AS DATETIME), CURRENT_TIMESTAMP()) <= 6 + start_dt >= DATE_TRUNC('DAY', DATEADD(MONTH, -6, CURRENT_TIMESTAMP())) GROUP BY 1 ), _t1 AS ( diff --git a/tests/test_sql_refsols/defog_dermtreatment_basic1_sqlite.sql b/tests/test_sql_refsols/defog_dermtreatment_basic1_sqlite.sql index e2b483a5d..2819d078d 100644 --- a/tests/test_sql_refsols/defog_dermtreatment_basic1_sqlite.sql +++ b/tests/test_sql_refsols/defog_dermtreatment_basic1_sqlite.sql @@ -5,11 +5,7 @@ WITH _s1 AS ( SUM(tot_drug_amt) AS sum_tot_drug_amt FROM main.treatments WHERE - ( - ( - CAST(STRFTIME('%Y', DATETIME('now')) AS INTEGER) - CAST(STRFTIME('%Y', start_dt) AS INTEGER) - ) * 12 + CAST(STRFTIME('%m', DATETIME('now')) AS INTEGER) - CAST(STRFTIME('%m', start_dt) AS INTEGER) - ) <= 6 + start_dt >= DATE(DATETIME('now', '-6 month'), 'start of day') GROUP BY 1 ), _t1 AS ( diff --git a/tests/test_sql_refsols/defog_restaurants_gen10_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen10_ansi.sql new file mode 100644 index 000000000..8501b302a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen10_ansi.sql @@ -0,0 +1,7 @@ +SELECT + name, + rating +FROM main.restaurant +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen10_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen10_mysql.sql new file mode 100644 index 000000000..99f8c7b63 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen10_mysql.sql @@ -0,0 +1,7 @@ +SELECT + name COLLATE utf8mb4_bin AS name, + rating +FROM main.restaurant +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen10_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen10_postgres.sql new file mode 100644 index 000000000..0e57071ca --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen10_postgres.sql @@ -0,0 +1,7 @@ +SELECT + name, + rating +FROM main.restaurant +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen10_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen10_snowflake.sql new file mode 100644 index 000000000..0e57071ca --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen10_snowflake.sql @@ -0,0 +1,7 @@ +SELECT + name, + rating +FROM main.restaurant +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen10_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen10_sqlite.sql new file mode 100644 index 000000000..8501b302a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen10_sqlite.sql @@ -0,0 +1,7 @@ +SELECT + name, + rating +FROM main.restaurant +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen11_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen11_ansi.sql new file mode 100644 index 000000000..832005452 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen11_ansi.sql @@ -0,0 +1,15 @@ +WITH _s0 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + rating > 4.5 +), _s1 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant +) +SELECT + _s0.n_rows / _s1.n_rows AS ratio +FROM _s0 AS _s0 +CROSS JOIN _s1 AS _s1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen11_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen11_mysql.sql new file mode 100644 index 000000000..832005452 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen11_mysql.sql @@ -0,0 +1,15 @@ +WITH _s0 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + rating > 4.5 +), _s1 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant +) +SELECT + _s0.n_rows / _s1.n_rows AS ratio +FROM _s0 AS _s0 +CROSS JOIN _s1 AS _s1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen11_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen11_postgres.sql new file mode 100644 index 000000000..bf0e704bf --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen11_postgres.sql @@ -0,0 +1,15 @@ +WITH _s0 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + rating > 4.5 +), _s1 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant +) +SELECT + CAST(_s0.n_rows AS DOUBLE PRECISION) / _s1.n_rows AS ratio +FROM _s0 AS _s0 +CROSS JOIN _s1 AS _s1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen11_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen11_snowflake.sql new file mode 100644 index 000000000..832005452 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen11_snowflake.sql @@ -0,0 +1,15 @@ +WITH _s0 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + rating > 4.5 +), _s1 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant +) +SELECT + _s0.n_rows / _s1.n_rows AS ratio +FROM _s0 AS _s0 +CROSS JOIN _s1 AS _s1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen11_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen11_sqlite.sql new file mode 100644 index 000000000..4b5cce5d6 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen11_sqlite.sql @@ -0,0 +1,15 @@ +WITH _s0 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + rating > 4.5 +), _s1 AS ( + SELECT + COUNT(*) AS n_rows + FROM main.restaurant +) +SELECT + CAST(_s0.n_rows AS REAL) / _s1.n_rows AS ratio +FROM _s0 AS _s0 +CROSS JOIN _s1 AS _s1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen12_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen12_ansi.sql new file mode 100644 index 000000000..9afcc60a6 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen12_ansi.sql @@ -0,0 +1,9 @@ +SELECT + COALESCE(SUM(rating > 4.0), 0) / CASE + WHEN ( + NOT SUM(rating < 4.0) IS NULL AND SUM(rating < 4.0) <> 0 + ) + THEN COALESCE(SUM(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant diff --git a/tests/test_sql_refsols/defog_restaurants_gen12_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen12_mysql.sql new file mode 100644 index 000000000..9afcc60a6 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen12_mysql.sql @@ -0,0 +1,9 @@ +SELECT + COALESCE(SUM(rating > 4.0), 0) / CASE + WHEN ( + NOT SUM(rating < 4.0) IS NULL AND SUM(rating < 4.0) <> 0 + ) + THEN COALESCE(SUM(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant diff --git a/tests/test_sql_refsols/defog_restaurants_gen12_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen12_postgres.sql new file mode 100644 index 000000000..fc66f22ba --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen12_postgres.sql @@ -0,0 +1,10 @@ +SELECT + CAST(COALESCE(SUM(CASE WHEN rating > 4.0 THEN 1 ELSE 0 END), 0) AS DOUBLE PRECISION) / CASE + WHEN ( + NOT SUM(CASE WHEN rating < 4.0 THEN 1 ELSE 0 END) IS NULL + AND SUM(CASE WHEN rating < 4.0 THEN 1 ELSE 0 END) <> 0 + ) + THEN COALESCE(SUM(CASE WHEN rating < 4.0 THEN 1 ELSE 0 END), 0) + ELSE NULL + END AS ratio +FROM main.restaurant diff --git a/tests/test_sql_refsols/defog_restaurants_gen12_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen12_snowflake.sql new file mode 100644 index 000000000..9d1bcf6ad --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen12_snowflake.sql @@ -0,0 +1,9 @@ +SELECT + COALESCE(COUNT_IF(rating > 4.0), 0) / CASE + WHEN ( + COUNT_IF(rating < 4.0) <> 0 AND NOT COUNT_IF(rating < 4.0) IS NULL + ) + THEN COALESCE(COUNT_IF(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant diff --git a/tests/test_sql_refsols/defog_restaurants_gen12_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen12_sqlite.sql new file mode 100644 index 000000000..837e07fbc --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen12_sqlite.sql @@ -0,0 +1,9 @@ +SELECT + CAST(COALESCE(SUM(rating > 4.0), 0) AS REAL) / CASE + WHEN ( + NOT SUM(rating < 4.0) IS NULL AND SUM(rating < 4.0) <> 0 + ) + THEN COALESCE(SUM(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant diff --git a/tests/test_sql_refsols/defog_restaurants_gen13_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen13_ansi.sql new file mode 100644 index 000000000..e242399d5 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen13_ansi.sql @@ -0,0 +1,11 @@ +SELECT + COALESCE(SUM(rating > 4.0), 0) / CASE + WHEN ( + NOT SUM(rating < 4.0) IS NULL AND SUM(rating < 4.0) <> 0 + ) + THEN COALESCE(SUM(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' diff --git a/tests/test_sql_refsols/defog_restaurants_gen13_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen13_mysql.sql new file mode 100644 index 000000000..e242399d5 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen13_mysql.sql @@ -0,0 +1,11 @@ +SELECT + COALESCE(SUM(rating > 4.0), 0) / CASE + WHEN ( + NOT SUM(rating < 4.0) IS NULL AND SUM(rating < 4.0) <> 0 + ) + THEN COALESCE(SUM(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' diff --git a/tests/test_sql_refsols/defog_restaurants_gen13_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen13_postgres.sql new file mode 100644 index 000000000..7d950c523 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen13_postgres.sql @@ -0,0 +1,12 @@ +SELECT + CAST(COALESCE(SUM(CASE WHEN rating > 4.0 THEN 1 ELSE 0 END), 0) AS DOUBLE PRECISION) / CASE + WHEN ( + NOT SUM(CASE WHEN rating < 4.0 THEN 1 ELSE 0 END) IS NULL + AND SUM(CASE WHEN rating < 4.0 THEN 1 ELSE 0 END) <> 0 + ) + THEN COALESCE(SUM(CASE WHEN rating < 4.0 THEN 1 ELSE 0 END), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' diff --git a/tests/test_sql_refsols/defog_restaurants_gen13_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen13_snowflake.sql new file mode 100644 index 000000000..615701afe --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen13_snowflake.sql @@ -0,0 +1,11 @@ +SELECT + COALESCE(COUNT_IF(rating > 4.0), 0) / CASE + WHEN ( + COUNT_IF(rating < 4.0) <> 0 AND NOT COUNT_IF(rating < 4.0) IS NULL + ) + THEN COALESCE(COUNT_IF(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' diff --git a/tests/test_sql_refsols/defog_restaurants_gen13_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen13_sqlite.sql new file mode 100644 index 000000000..65e74ad5c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen13_sqlite.sql @@ -0,0 +1,11 @@ +SELECT + CAST(COALESCE(SUM(rating > 4.0), 0) AS REAL) / CASE + WHEN ( + NOT SUM(rating < 4.0) IS NULL AND SUM(rating < 4.0) <> 0 + ) + THEN COALESCE(SUM(rating < 4.0), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' diff --git a/tests/test_sql_refsols/defog_restaurants_gen14_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen14_ansi.sql new file mode 100644 index 000000000..6d482b5af --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen14_ansi.sql @@ -0,0 +1,12 @@ +SELECT + COALESCE(SUM(LOWER(food_type) = 'vegan'), 0) / CASE + WHEN ( + NOT SUM(LOWER(food_type) <> 'vegan') IS NULL + AND SUM(LOWER(food_type) <> 'vegan') <> 0 + ) + THEN COALESCE(SUM(LOWER(food_type) <> 'vegan'), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'san francisco' diff --git a/tests/test_sql_refsols/defog_restaurants_gen14_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen14_mysql.sql new file mode 100644 index 000000000..6d482b5af --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen14_mysql.sql @@ -0,0 +1,12 @@ +SELECT + COALESCE(SUM(LOWER(food_type) = 'vegan'), 0) / CASE + WHEN ( + NOT SUM(LOWER(food_type) <> 'vegan') IS NULL + AND SUM(LOWER(food_type) <> 'vegan') <> 0 + ) + THEN COALESCE(SUM(LOWER(food_type) <> 'vegan'), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'san francisco' diff --git a/tests/test_sql_refsols/defog_restaurants_gen14_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen14_postgres.sql new file mode 100644 index 000000000..a184ccfef --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen14_postgres.sql @@ -0,0 +1,12 @@ +SELECT + CAST(COALESCE(SUM(CASE WHEN LOWER(food_type) = 'vegan' THEN 1 ELSE 0 END), 0) AS DOUBLE PRECISION) / CASE + WHEN ( + NOT SUM(CASE WHEN LOWER(food_type) <> 'vegan' THEN 1 ELSE 0 END) IS NULL + AND SUM(CASE WHEN LOWER(food_type) <> 'vegan' THEN 1 ELSE 0 END) <> 0 + ) + THEN COALESCE(SUM(CASE WHEN LOWER(food_type) <> 'vegan' THEN 1 ELSE 0 END), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'san francisco' diff --git a/tests/test_sql_refsols/defog_restaurants_gen14_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen14_snowflake.sql new file mode 100644 index 000000000..70767f83e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen14_snowflake.sql @@ -0,0 +1,12 @@ +SELECT + COALESCE(COUNT_IF(LOWER(food_type) = 'vegan'), 0) / CASE + WHEN ( + COUNT_IF(LOWER(food_type) <> 'vegan') <> 0 + AND NOT COUNT_IF(LOWER(food_type) <> 'vegan') IS NULL + ) + THEN COALESCE(COUNT_IF(LOWER(food_type) <> 'vegan'), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'san francisco' diff --git a/tests/test_sql_refsols/defog_restaurants_gen14_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen14_sqlite.sql new file mode 100644 index 000000000..59b2ad815 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen14_sqlite.sql @@ -0,0 +1,12 @@ +SELECT + CAST(COALESCE(SUM(LOWER(food_type) = 'vegan'), 0) AS REAL) / CASE + WHEN ( + NOT SUM(LOWER(food_type) <> 'vegan') IS NULL + AND SUM(LOWER(food_type) <> 'vegan') <> 0 + ) + THEN COALESCE(SUM(LOWER(food_type) <> 'vegan'), 0) + ELSE NULL + END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'san francisco' diff --git a/tests/test_sql_refsols/defog_restaurants_gen15_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen15_ansi.sql new file mode 100644 index 000000000..f1d9a4ac5 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen15_ansi.sql @@ -0,0 +1,5 @@ +SELECT + COALESCE(SUM(LOWER(food_type) = 'italian'), 0) / CASE WHEN COUNT(*) <> 0 THEN COUNT(*) ELSE NULL END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' diff --git a/tests/test_sql_refsols/defog_restaurants_gen15_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen15_mysql.sql new file mode 100644 index 000000000..f1d9a4ac5 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen15_mysql.sql @@ -0,0 +1,5 @@ +SELECT + COALESCE(SUM(LOWER(food_type) = 'italian'), 0) / CASE WHEN COUNT(*) <> 0 THEN COUNT(*) ELSE NULL END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' diff --git a/tests/test_sql_refsols/defog_restaurants_gen15_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen15_postgres.sql new file mode 100644 index 000000000..68ac00f1e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen15_postgres.sql @@ -0,0 +1,5 @@ +SELECT + CAST(COALESCE(SUM(CASE WHEN LOWER(food_type) = 'italian' THEN 1 ELSE 0 END), 0) AS DOUBLE PRECISION) / CASE WHEN COUNT(*) <> 0 THEN COUNT(*) ELSE NULL END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' diff --git a/tests/test_sql_refsols/defog_restaurants_gen15_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen15_snowflake.sql new file mode 100644 index 000000000..f31117c9a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen15_snowflake.sql @@ -0,0 +1,5 @@ +SELECT + COALESCE(COUNT_IF(LOWER(food_type) = 'italian'), 0) / CASE WHEN COUNT(*) <> 0 THEN COUNT(*) ELSE NULL END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' diff --git a/tests/test_sql_refsols/defog_restaurants_gen15_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen15_sqlite.sql new file mode 100644 index 000000000..6cf3b4b72 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen15_sqlite.sql @@ -0,0 +1,5 @@ +SELECT + CAST(COALESCE(SUM(LOWER(food_type) = 'italian'), 0) AS REAL) / CASE WHEN COUNT(*) <> 0 THEN COUNT(*) ELSE NULL END AS ratio +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' diff --git a/tests/test_sql_refsols/defog_restaurants_gen16_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen16_ansi.sql new file mode 100644 index 000000000..09d3455d4 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen16_ansi.sql @@ -0,0 +1,17 @@ +WITH _t0 AS ( + SELECT + city_name, + name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1, + 2 +) +SELECT + city_name, + name, + n_rows AS n_restaurants +FROM _t0 +WHERE + n_rows > 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen16_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen16_mysql.sql new file mode 100644 index 000000000..09d3455d4 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen16_mysql.sql @@ -0,0 +1,17 @@ +WITH _t0 AS ( + SELECT + city_name, + name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1, + 2 +) +SELECT + city_name, + name, + n_rows AS n_restaurants +FROM _t0 +WHERE + n_rows > 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen16_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen16_postgres.sql new file mode 100644 index 000000000..09d3455d4 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen16_postgres.sql @@ -0,0 +1,17 @@ +WITH _t0 AS ( + SELECT + city_name, + name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1, + 2 +) +SELECT + city_name, + name, + n_rows AS n_restaurants +FROM _t0 +WHERE + n_rows > 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen16_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen16_snowflake.sql new file mode 100644 index 000000000..09d3455d4 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen16_snowflake.sql @@ -0,0 +1,17 @@ +WITH _t0 AS ( + SELECT + city_name, + name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1, + 2 +) +SELECT + city_name, + name, + n_rows AS n_restaurants +FROM _t0 +WHERE + n_rows > 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen16_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen16_sqlite.sql new file mode 100644 index 000000000..09d3455d4 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen16_sqlite.sql @@ -0,0 +1,17 @@ +WITH _t0 AS ( + SELECT + city_name, + name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1, + 2 +) +SELECT + city_name, + name, + n_rows AS n_restaurants +FROM _t0 +WHERE + n_rows > 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen17_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen17_ansi.sql new file mode 100644 index 000000000..7a8c02f1d --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen17_ansi.sql @@ -0,0 +1,8 @@ +SELECT + city_name, + AVG(rating) AS avg_rating +FROM main.restaurant +WHERE + LOWER(food_type) = 'mexican' +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen17_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen17_mysql.sql new file mode 100644 index 000000000..7a8c02f1d --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen17_mysql.sql @@ -0,0 +1,8 @@ +SELECT + city_name, + AVG(rating) AS avg_rating +FROM main.restaurant +WHERE + LOWER(food_type) = 'mexican' +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen17_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen17_postgres.sql new file mode 100644 index 000000000..09063cea1 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen17_postgres.sql @@ -0,0 +1,8 @@ +SELECT + city_name, + AVG(CAST(rating AS DECIMAL)) AS avg_rating +FROM main.restaurant +WHERE + LOWER(food_type) = 'mexican' +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen17_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen17_snowflake.sql new file mode 100644 index 000000000..7a8c02f1d --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen17_snowflake.sql @@ -0,0 +1,8 @@ +SELECT + city_name, + AVG(rating) AS avg_rating +FROM main.restaurant +WHERE + LOWER(food_type) = 'mexican' +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen17_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen17_sqlite.sql new file mode 100644 index 000000000..7a8c02f1d --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen17_sqlite.sql @@ -0,0 +1,8 @@ +SELECT + city_name, + AVG(rating) AS avg_rating +FROM main.restaurant +WHERE + LOWER(food_type) = 'mexican' +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen18_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen18_ansi.sql new file mode 100644 index 000000000..c12293c26 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen18_ansi.sql @@ -0,0 +1,43 @@ +WITH _s0 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s1 AS ( + SELECT + city_name + FROM main.restaurant +), _s6 AS ( + SELECT DISTINCT + _s0.region + FROM _s0 AS _s0 + JOIN _s1 AS _s1 + ON _s0.city_name = _s1.city_name +), _s5 AS ( + SELECT + city_name, + COUNT(rating) AS count_rating, + SUM(rating) AS sum_rating + FROM main.restaurant + GROUP BY + 1 +), _s7 AS ( + SELECT + SUM(_s5.sum_rating) / SUM(_s5.count_rating) AS avg_rating, + _s2.region + FROM _s0 AS _s2 + JOIN _s1 AS _s3 + ON _s2.city_name = _s3.city_name + JOIN _s5 AS _s5 + ON _s2.city_name = _s5.city_name + GROUP BY + 2 +) +SELECT + _s6.region AS rest_region, + _s7.avg_rating +FROM _s6 AS _s6 +LEFT JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen18_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen18_mysql.sql new file mode 100644 index 000000000..01b828b6a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen18_mysql.sql @@ -0,0 +1,59 @@ +WITH _s0 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s1 AS ( + SELECT + city_name + FROM main.restaurant +), _u_0 AS ( + SELECT + city_name AS _u_1 + FROM _s1 + GROUP BY + 1 +), _s6 AS ( + SELECT DISTINCT + _s0.region + FROM _s0 AS _s0 + LEFT JOIN _u_0 AS _u_0 + ON _s0.city_name = _u_0._u_1 + WHERE + NOT _u_0._u_1 IS NULL +), _u_2 AS ( + SELECT + city_name AS _u_3 + FROM _s1 + GROUP BY + 1 +), _s5 AS ( + SELECT + city_name, + COUNT(rating) AS count_rating, + SUM(rating) AS sum_rating + FROM main.restaurant + GROUP BY + 1 +), _s7 AS ( + SELECT + SUM(_s5.sum_rating) / SUM(_s5.count_rating) AS avg_rating, + _s2.region + FROM _s0 AS _s2 + LEFT JOIN _u_2 AS _u_2 + ON _s2.city_name = _u_2._u_3 + JOIN _s5 AS _s5 + ON _s2.city_name = _s5.city_name + WHERE + NOT _u_2._u_3 IS NULL + GROUP BY + 2 +) +SELECT + _s6.region COLLATE utf8mb4_bin AS rest_region, + _s7.avg_rating +FROM _s6 AS _s6 +LEFT JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen18_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen18_postgres.sql new file mode 100644 index 000000000..28dbff8cb --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen18_postgres.sql @@ -0,0 +1,59 @@ +WITH _s0 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s1 AS ( + SELECT + city_name + FROM main.restaurant +), _u_0 AS ( + SELECT + city_name AS _u_1 + FROM _s1 + GROUP BY + 1 +), _s6 AS ( + SELECT DISTINCT + _s0.region + FROM _s0 AS _s0 + LEFT JOIN _u_0 AS _u_0 + ON _s0.city_name = _u_0._u_1 + WHERE + NOT _u_0._u_1 IS NULL +), _u_2 AS ( + SELECT + city_name AS _u_3 + FROM _s1 + GROUP BY + 1 +), _s5 AS ( + SELECT + city_name, + COUNT(rating) AS count_rating, + SUM(rating) AS sum_rating + FROM main.restaurant + GROUP BY + 1 +), _s7 AS ( + SELECT + CAST(SUM(_s5.sum_rating) AS DOUBLE PRECISION) / SUM(_s5.count_rating) AS avg_rating, + _s2.region + FROM _s0 AS _s2 + LEFT JOIN _u_2 AS _u_2 + ON _s2.city_name = _u_2._u_3 + JOIN _s5 AS _s5 + ON _s2.city_name = _s5.city_name + WHERE + NOT _u_2._u_3 IS NULL + GROUP BY + 2 +) +SELECT + _s6.region AS rest_region, + _s7.avg_rating +FROM _s6 AS _s6 +LEFT JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 NULLS FIRST diff --git a/tests/test_sql_refsols/defog_restaurants_gen18_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen18_snowflake.sql new file mode 100644 index 000000000..9d8d7fb77 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen18_snowflake.sql @@ -0,0 +1,59 @@ +WITH _s0 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s1 AS ( + SELECT + city_name + FROM main.restaurant +), _u_0 AS ( + SELECT + city_name AS _u_1 + FROM _s1 + GROUP BY + 1 +), _s6 AS ( + SELECT DISTINCT + _s0.region + FROM _s0 AS _s0 + LEFT JOIN _u_0 AS _u_0 + ON _s0.city_name = _u_0._u_1 + WHERE + NOT _u_0._u_1 IS NULL +), _u_2 AS ( + SELECT + city_name AS _u_3 + FROM _s1 + GROUP BY + 1 +), _s5 AS ( + SELECT + city_name, + COUNT(rating) AS count_rating, + SUM(rating) AS sum_rating + FROM main.restaurant + GROUP BY + 1 +), _s7 AS ( + SELECT + SUM(_s5.sum_rating) / SUM(_s5.count_rating) AS avg_rating, + _s2.region + FROM _s0 AS _s2 + LEFT JOIN _u_2 AS _u_2 + ON _s2.city_name = _u_2._u_3 + JOIN _s5 AS _s5 + ON _s2.city_name = _s5.city_name + WHERE + NOT _u_2._u_3 IS NULL + GROUP BY + 2 +) +SELECT + _s6.region AS rest_region, + _s7.avg_rating +FROM _s6 AS _s6 +LEFT JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 NULLS FIRST diff --git a/tests/test_sql_refsols/defog_restaurants_gen18_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen18_sqlite.sql new file mode 100644 index 000000000..373d62e71 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen18_sqlite.sql @@ -0,0 +1,59 @@ +WITH _s0 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s1 AS ( + SELECT + city_name + FROM main.restaurant +), _u_0 AS ( + SELECT + city_name AS _u_1 + FROM _s1 + GROUP BY + 1 +), _s6 AS ( + SELECT DISTINCT + _s0.region + FROM _s0 AS _s0 + LEFT JOIN _u_0 AS _u_0 + ON _s0.city_name = _u_0._u_1 + WHERE + NOT _u_0._u_1 IS NULL +), _u_2 AS ( + SELECT + city_name AS _u_3 + FROM _s1 + GROUP BY + 1 +), _s5 AS ( + SELECT + city_name, + COUNT(rating) AS count_rating, + SUM(rating) AS sum_rating + FROM main.restaurant + GROUP BY + 1 +), _s7 AS ( + SELECT + CAST(SUM(_s5.sum_rating) AS REAL) / SUM(_s5.count_rating) AS avg_rating, + _s2.region + FROM _s0 AS _s2 + LEFT JOIN _u_2 AS _u_2 + ON _s2.city_name = _u_2._u_3 + JOIN _s5 AS _s5 + ON _s2.city_name = _s5.city_name + WHERE + NOT _u_2._u_3 IS NULL + GROUP BY + 2 +) +SELECT + _s6.region AS rest_region, + _s7.avg_rating +FROM _s6 AS _s6 +LEFT JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen19_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen19_ansi.sql new file mode 100644 index 000000000..97ca5bd82 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen19_ansi.sql @@ -0,0 +1,21 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + LOWER(food_type) = 'italian' + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen19_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen19_mysql.sql new file mode 100644 index 000000000..e71170339 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen19_mysql.sql @@ -0,0 +1,21 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + LOWER(food_type) = 'italian' + GROUP BY + 1 +) +SELECT + geographic.region COLLATE utf8mb4_bin AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen19_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen19_postgres.sql new file mode 100644 index 000000000..6d54dbef2 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen19_postgres.sql @@ -0,0 +1,21 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + LOWER(food_type) = 'italian' + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 NULLS FIRST diff --git a/tests/test_sql_refsols/defog_restaurants_gen19_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen19_snowflake.sql new file mode 100644 index 000000000..6d54dbef2 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen19_snowflake.sql @@ -0,0 +1,21 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + LOWER(food_type) = 'italian' + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 NULLS FIRST diff --git a/tests/test_sql_refsols/defog_restaurants_gen19_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen19_sqlite.sql new file mode 100644 index 000000000..97ca5bd82 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen19_sqlite.sql @@ -0,0 +1,21 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + WHERE + LOWER(food_type) = 'italian' + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen1_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen1_ansi.sql new file mode 100644 index 000000000..eb6929934 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen1_ansi.sql @@ -0,0 +1,6 @@ +SELECT + food_type, + COUNT(*) AS restaurants +FROM main.restaurant +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen1_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen1_mysql.sql new file mode 100644 index 000000000..eb6929934 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen1_mysql.sql @@ -0,0 +1,6 @@ +SELECT + food_type, + COUNT(*) AS restaurants +FROM main.restaurant +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen1_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen1_postgres.sql new file mode 100644 index 000000000..eb6929934 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen1_postgres.sql @@ -0,0 +1,6 @@ +SELECT + food_type, + COUNT(*) AS restaurants +FROM main.restaurant +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen1_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen1_snowflake.sql new file mode 100644 index 000000000..eb6929934 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen1_snowflake.sql @@ -0,0 +1,6 @@ +SELECT + food_type, + COUNT(*) AS restaurants +FROM main.restaurant +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen1_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen1_sqlite.sql new file mode 100644 index 000000000..eb6929934 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen1_sqlite.sql @@ -0,0 +1,6 @@ +SELECT + food_type, + COUNT(*) AS restaurants +FROM main.restaurant +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen20_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen20_ansi.sql new file mode 100644 index 000000000..50e24b2ee --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen20_ansi.sql @@ -0,0 +1,19 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen20_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen20_mysql.sql new file mode 100644 index 000000000..3aa5772ac --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen20_mysql.sql @@ -0,0 +1,19 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1 +) +SELECT + geographic.region COLLATE utf8mb4_bin AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen20_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen20_postgres.sql new file mode 100644 index 000000000..8b399bcd2 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen20_postgres.sql @@ -0,0 +1,19 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 NULLS FIRST diff --git a/tests/test_sql_refsols/defog_restaurants_gen20_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen20_snowflake.sql new file mode 100644 index 000000000..8b399bcd2 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen20_snowflake.sql @@ -0,0 +1,19 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 NULLS FIRST diff --git a/tests/test_sql_refsols/defog_restaurants_gen20_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen20_sqlite.sql new file mode 100644 index 000000000..50e24b2ee --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen20_sqlite.sql @@ -0,0 +1,19 @@ +WITH _s0 AS ( + SELECT + city_name, + COUNT(*) AS n_rows + FROM main.restaurant + GROUP BY + 1 +) +SELECT + geographic.region AS rest_region, + SUM(_s0.n_rows) AS n_restaurants +FROM _s0 AS _s0 +JOIN main.geographic AS geographic + ON _s0.city_name = geographic.city_name +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen21_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen21_ansi.sql new file mode 100644 index 000000000..6651009f8 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen21_ansi.sql @@ -0,0 +1,6 @@ +SELECT + city_name +FROM main.restaurant +ORDER BY + rating DESC +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen21_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen21_mysql.sql new file mode 100644 index 000000000..6651009f8 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen21_mysql.sql @@ -0,0 +1,6 @@ +SELECT + city_name +FROM main.restaurant +ORDER BY + rating DESC +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen21_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen21_postgres.sql new file mode 100644 index 000000000..97bc2de50 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen21_postgres.sql @@ -0,0 +1,6 @@ +SELECT + city_name +FROM main.restaurant +ORDER BY + rating DESC NULLS LAST +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen21_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen21_snowflake.sql new file mode 100644 index 000000000..97bc2de50 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen21_snowflake.sql @@ -0,0 +1,6 @@ +SELECT + city_name +FROM main.restaurant +ORDER BY + rating DESC NULLS LAST +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen21_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen21_sqlite.sql new file mode 100644 index 000000000..6651009f8 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen21_sqlite.sql @@ -0,0 +1,6 @@ +SELECT + city_name +FROM main.restaurant +ORDER BY + rating DESC +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen22_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen22_ansi.sql new file mode 100644 index 000000000..4de0f8792 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen22_ansi.sql @@ -0,0 +1,6 @@ +SELECT + name, + rating +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen22_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen22_mysql.sql new file mode 100644 index 000000000..4de0f8792 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen22_mysql.sql @@ -0,0 +1,6 @@ +SELECT + name, + rating +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen22_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen22_postgres.sql new file mode 100644 index 000000000..4de0f8792 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen22_postgres.sql @@ -0,0 +1,6 @@ +SELECT + name, + rating +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen22_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen22_snowflake.sql new file mode 100644 index 000000000..4de0f8792 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen22_snowflake.sql @@ -0,0 +1,6 @@ +SELECT + name, + rating +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen22_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen22_sqlite.sql new file mode 100644 index 000000000..4de0f8792 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen22_sqlite.sql @@ -0,0 +1,6 @@ +SELECT + name, + rating +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen23_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen23_ansi.sql new file mode 100644 index 000000000..78a287d66 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen23_ansi.sql @@ -0,0 +1,9 @@ +SELECT + restaurant.name, + restaurant.food_type +FROM main.location AS location +JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id +WHERE + LOWER(location.city_name) = 'san francisco' + AND LOWER(location.street_name) = 'market st' diff --git a/tests/test_sql_refsols/defog_restaurants_gen23_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen23_mysql.sql new file mode 100644 index 000000000..78a287d66 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen23_mysql.sql @@ -0,0 +1,9 @@ +SELECT + restaurant.name, + restaurant.food_type +FROM main.location AS location +JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id +WHERE + LOWER(location.city_name) = 'san francisco' + AND LOWER(location.street_name) = 'market st' diff --git a/tests/test_sql_refsols/defog_restaurants_gen23_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen23_postgres.sql new file mode 100644 index 000000000..78a287d66 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen23_postgres.sql @@ -0,0 +1,9 @@ +SELECT + restaurant.name, + restaurant.food_type +FROM main.location AS location +JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id +WHERE + LOWER(location.city_name) = 'san francisco' + AND LOWER(location.street_name) = 'market st' diff --git a/tests/test_sql_refsols/defog_restaurants_gen23_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen23_snowflake.sql new file mode 100644 index 000000000..78a287d66 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen23_snowflake.sql @@ -0,0 +1,9 @@ +SELECT + restaurant.name, + restaurant.food_type +FROM main.location AS location +JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id +WHERE + LOWER(location.city_name) = 'san francisco' + AND LOWER(location.street_name) = 'market st' diff --git a/tests/test_sql_refsols/defog_restaurants_gen23_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen23_sqlite.sql new file mode 100644 index 000000000..78a287d66 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen23_sqlite.sql @@ -0,0 +1,9 @@ +SELECT + restaurant.name, + restaurant.food_type +FROM main.location AS location +JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id +WHERE + LOWER(location.city_name) = 'san francisco' + AND LOWER(location.street_name) = 'market st' diff --git a/tests/test_sql_refsols/defog_restaurants_gen24_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen24_ansi.sql new file mode 100644 index 000000000..de54aae26 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen24_ansi.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen24_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen24_mysql.sql new file mode 100644 index 000000000..de54aae26 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen24_mysql.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen24_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen24_postgres.sql new file mode 100644 index 000000000..de54aae26 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen24_postgres.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen24_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen24_snowflake.sql new file mode 100644 index 000000000..de54aae26 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen24_snowflake.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen24_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen24_sqlite.sql new file mode 100644 index 000000000..de54aae26 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen24_sqlite.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen25_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen25_ansi.sql new file mode 100644 index 000000000..a7373300c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen25_ansi.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen25_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen25_mysql.sql new file mode 100644 index 000000000..a7373300c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen25_mysql.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen25_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen25_postgres.sql new file mode 100644 index 000000000..a7373300c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen25_postgres.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen25_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen25_snowflake.sql new file mode 100644 index 000000000..a7373300c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen25_snowflake.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen25_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen25_sqlite.sql new file mode 100644 index 000000000..a7373300c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen25_sqlite.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'los angeles' AND rating > 4 diff --git a/tests/test_sql_refsols/defog_restaurants_gen2_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen2_ansi.sql new file mode 100644 index 000000000..462da428a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen2_ansi.sql @@ -0,0 +1,6 @@ +SELECT + city_name, + COUNT(*) AS total_count +FROM main.location +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen2_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen2_mysql.sql new file mode 100644 index 000000000..462da428a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen2_mysql.sql @@ -0,0 +1,6 @@ +SELECT + city_name, + COUNT(*) AS total_count +FROM main.location +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen2_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen2_postgres.sql new file mode 100644 index 000000000..462da428a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen2_postgres.sql @@ -0,0 +1,6 @@ +SELECT + city_name, + COUNT(*) AS total_count +FROM main.location +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen2_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen2_snowflake.sql new file mode 100644 index 000000000..462da428a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen2_snowflake.sql @@ -0,0 +1,6 @@ +SELECT + city_name, + COUNT(*) AS total_count +FROM main.location +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen2_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen2_sqlite.sql new file mode 100644 index 000000000..462da428a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen2_sqlite.sql @@ -0,0 +1,6 @@ +SELECT + city_name, + COUNT(*) AS total_count +FROM main.location +GROUP BY + 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen3_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen3_ansi.sql new file mode 100644 index 000000000..9b8f8595c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen3_ansi.sql @@ -0,0 +1,9 @@ +SELECT + food_type, + AVG(rating) AS avg_rating +FROM main.restaurant +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen3_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen3_mysql.sql new file mode 100644 index 000000000..586a97cc1 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen3_mysql.sql @@ -0,0 +1,9 @@ +SELECT + food_type COLLATE utf8mb4_bin AS food_type, + AVG(rating) AS avg_rating +FROM main.restaurant +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen3_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen3_postgres.sql new file mode 100644 index 000000000..da9ed10a6 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen3_postgres.sql @@ -0,0 +1,9 @@ +SELECT + food_type, + AVG(CAST(rating AS DECIMAL)) AS avg_rating +FROM main.restaurant +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen3_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen3_snowflake.sql new file mode 100644 index 000000000..7418ea676 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen3_snowflake.sql @@ -0,0 +1,9 @@ +SELECT + food_type, + AVG(rating) AS avg_rating +FROM main.restaurant +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen3_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen3_sqlite.sql new file mode 100644 index 000000000..9b8f8595c --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen3_sqlite.sql @@ -0,0 +1,9 @@ +SELECT + food_type, + AVG(rating) AS avg_rating +FROM main.restaurant +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen4_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen4_ansi.sql new file mode 100644 index 000000000..9ab4be5a0 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen4_ansi.sql @@ -0,0 +1,11 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen4_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen4_mysql.sql new file mode 100644 index 000000000..7237796c3 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen4_mysql.sql @@ -0,0 +1,11 @@ +SELECT + city_name COLLATE utf8mb4_bin AS city_name, + COUNT(*) AS num_restaurants +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen4_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen4_postgres.sql new file mode 100644 index 000000000..93a080c4d --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen4_postgres.sql @@ -0,0 +1,11 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen4_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen4_snowflake.sql new file mode 100644 index 000000000..93a080c4d --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen4_snowflake.sql @@ -0,0 +1,11 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen4_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen4_sqlite.sql new file mode 100644 index 000000000..9ab4be5a0 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen4_sqlite.sql @@ -0,0 +1,11 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.restaurant +WHERE + LOWER(food_type) = 'italian' +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen5_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen5_ansi.sql new file mode 100644 index 000000000..f0a1066a5 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen5_ansi.sql @@ -0,0 +1,9 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.location +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen5_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen5_mysql.sql new file mode 100644 index 000000000..08d80a1ce --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen5_mysql.sql @@ -0,0 +1,9 @@ +SELECT + city_name COLLATE utf8mb4_bin AS city_name, + COUNT(*) AS num_restaurants +FROM main.location +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen5_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen5_postgres.sql new file mode 100644 index 000000000..9c85c9820 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen5_postgres.sql @@ -0,0 +1,9 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.location +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen5_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen5_snowflake.sql new file mode 100644 index 000000000..9c85c9820 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen5_snowflake.sql @@ -0,0 +1,9 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.location +GROUP BY + 1 +ORDER BY + 2 DESC NULLS LAST, + 1 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen5_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen5_sqlite.sql new file mode 100644 index 000000000..f0a1066a5 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen5_sqlite.sql @@ -0,0 +1,9 @@ +SELECT + city_name, + COUNT(*) AS num_restaurants +FROM main.location +GROUP BY + 1 +ORDER BY + 2 DESC, + 1 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen6_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen6_ansi.sql new file mode 100644 index 000000000..508db2eec --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen6_ansi.sql @@ -0,0 +1,8 @@ +SELECT + street_name +FROM main.location +GROUP BY + 1 +ORDER BY + COUNT(*) DESC +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen6_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen6_mysql.sql new file mode 100644 index 000000000..508db2eec --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen6_mysql.sql @@ -0,0 +1,8 @@ +SELECT + street_name +FROM main.location +GROUP BY + 1 +ORDER BY + COUNT(*) DESC +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen6_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen6_postgres.sql new file mode 100644 index 000000000..91f5debe6 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen6_postgres.sql @@ -0,0 +1,8 @@ +SELECT + street_name +FROM main.location +GROUP BY + 1 +ORDER BY + COUNT(*) DESC NULLS LAST +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen6_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen6_snowflake.sql new file mode 100644 index 000000000..91f5debe6 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen6_snowflake.sql @@ -0,0 +1,8 @@ +SELECT + street_name +FROM main.location +GROUP BY + 1 +ORDER BY + COUNT(*) DESC NULLS LAST +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen6_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen6_sqlite.sql new file mode 100644 index 000000000..508db2eec --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen6_sqlite.sql @@ -0,0 +1,8 @@ +SELECT + street_name +FROM main.location +GROUP BY + 1 +ORDER BY + COUNT(*) DESC +LIMIT 1 diff --git a/tests/test_sql_refsols/defog_restaurants_gen7_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen7_ansi.sql new file mode 100644 index 000000000..009763d1e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen7_ansi.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' OR LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen7_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen7_mysql.sql new file mode 100644 index 000000000..009763d1e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen7_mysql.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' OR LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen7_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen7_postgres.sql new file mode 100644 index 000000000..009763d1e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen7_postgres.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' OR LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen7_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen7_snowflake.sql new file mode 100644 index 000000000..009763d1e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen7_snowflake.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' OR LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen7_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen7_sqlite.sql new file mode 100644 index 000000000..009763d1e --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen7_sqlite.sql @@ -0,0 +1,5 @@ +SELECT + name +FROM main.restaurant +WHERE + LOWER(city_name) = 'new york' OR LOWER(food_type) = 'italian' diff --git a/tests/test_sql_refsols/defog_restaurants_gen8_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen8_ansi.sql new file mode 100644 index 000000000..cf572383b --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen8_ansi.sql @@ -0,0 +1,33 @@ +WITH _s1 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s6 AS ( + SELECT DISTINCT + _s1.region + FROM main.location AS location + LEFT JOIN _s1 AS _s1 + ON _s1.city_name = location.city_name +), _s7 AS ( + SELECT + _s3.region, + SUM(CASE WHEN NOT restaurant.rating IS NULL THEN 1 ELSE 0 END) AS sum_expr, + SUM(restaurant.rating) AS sum_rating + FROM main.location AS location + LEFT JOIN _s1 AS _s3 + ON _s3.city_name = location.city_name + JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id + GROUP BY + 1 +) +SELECT + _s6.region AS region_name, + _s7.sum_rating / _s7.sum_expr AS avg_rating +FROM _s6 AS _s6 +JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1, + 2 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen8_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen8_mysql.sql new file mode 100644 index 000000000..d3c25d5a9 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen8_mysql.sql @@ -0,0 +1,33 @@ +WITH _s1 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s6 AS ( + SELECT DISTINCT + _s1.region + FROM main.location AS location + LEFT JOIN _s1 AS _s1 + ON _s1.city_name = location.city_name +), _s7 AS ( + SELECT + _s3.region, + SUM(CASE WHEN NOT restaurant.rating IS NULL THEN 1 ELSE 0 END) AS sum_expr, + SUM(restaurant.rating) AS sum_rating + FROM main.location AS location + LEFT JOIN _s1 AS _s3 + ON _s3.city_name = location.city_name + JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id + GROUP BY + 1 +) +SELECT + _s6.region COLLATE utf8mb4_bin AS region_name, + _s7.sum_rating / _s7.sum_expr AS avg_rating +FROM _s6 AS _s6 +JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1, + 2 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen8_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen8_postgres.sql new file mode 100644 index 000000000..8c6994569 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen8_postgres.sql @@ -0,0 +1,33 @@ +WITH _s1 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s6 AS ( + SELECT DISTINCT + _s1.region + FROM main.location AS location + LEFT JOIN _s1 AS _s1 + ON _s1.city_name = location.city_name +), _s7 AS ( + SELECT + _s3.region, + SUM(CASE WHEN NOT restaurant.rating IS NULL THEN 1 ELSE 0 END) AS sum_expr, + SUM(restaurant.rating) AS sum_rating + FROM main.location AS location + LEFT JOIN _s1 AS _s3 + ON _s3.city_name = location.city_name + JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id + GROUP BY + 1 +) +SELECT + _s6.region AS region_name, + CAST(_s7.sum_rating AS DOUBLE PRECISION) / _s7.sum_expr AS avg_rating +FROM _s6 AS _s6 +JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 NULLS FIRST, + 2 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen8_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen8_snowflake.sql new file mode 100644 index 000000000..de01bfd58 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen8_snowflake.sql @@ -0,0 +1,33 @@ +WITH _s1 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s6 AS ( + SELECT DISTINCT + _s1.region + FROM main.location AS location + LEFT JOIN _s1 AS _s1 + ON _s1.city_name = location.city_name +), _s7 AS ( + SELECT + _s3.region, + SUM(IFF(NOT restaurant.rating IS NULL, 1, 0)) AS sum_expr, + SUM(restaurant.rating) AS sum_rating + FROM main.location AS location + LEFT JOIN _s1 AS _s3 + ON _s3.city_name = location.city_name + JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id + GROUP BY + 1 +) +SELECT + _s6.region AS region_name, + _s7.sum_rating / _s7.sum_expr AS avg_rating +FROM _s6 AS _s6 +JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1 NULLS FIRST, + 2 DESC NULLS LAST diff --git a/tests/test_sql_refsols/defog_restaurants_gen8_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen8_sqlite.sql new file mode 100644 index 000000000..2ea3ca06a --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen8_sqlite.sql @@ -0,0 +1,33 @@ +WITH _s1 AS ( + SELECT + city_name, + region + FROM main.geographic +), _s6 AS ( + SELECT DISTINCT + _s1.region + FROM main.location AS location + LEFT JOIN _s1 AS _s1 + ON _s1.city_name = location.city_name +), _s7 AS ( + SELECT + _s3.region, + SUM(IIF(NOT restaurant.rating IS NULL, 1, 0)) AS sum_expr, + SUM(restaurant.rating) AS sum_rating + FROM main.location AS location + LEFT JOIN _s1 AS _s3 + ON _s3.city_name = location.city_name + JOIN main.restaurant AS restaurant + ON location.restaurant_id = restaurant.id + GROUP BY + 1 +) +SELECT + _s6.region AS region_name, + CAST(_s7.sum_rating AS REAL) / _s7.sum_expr AS avg_rating +FROM _s6 AS _s6 +JOIN _s7 AS _s7 + ON _s6.region = _s7.region +ORDER BY + 1, + 2 DESC diff --git a/tests/test_sql_refsols/defog_restaurants_gen9_ansi.sql b/tests/test_sql_refsols/defog_restaurants_gen9_ansi.sql new file mode 100644 index 000000000..33f54de55 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen9_ansi.sql @@ -0,0 +1,7 @@ +SELECT + name +FROM main.restaurant +ORDER BY + rating DESC, + 1 DESC +LIMIT 3 diff --git a/tests/test_sql_refsols/defog_restaurants_gen9_mysql.sql b/tests/test_sql_refsols/defog_restaurants_gen9_mysql.sql new file mode 100644 index 000000000..ce4c710fd --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen9_mysql.sql @@ -0,0 +1,7 @@ +SELECT + name COLLATE utf8mb4_bin AS name +FROM main.restaurant +ORDER BY + rating DESC, + 1 DESC +LIMIT 3 diff --git a/tests/test_sql_refsols/defog_restaurants_gen9_postgres.sql b/tests/test_sql_refsols/defog_restaurants_gen9_postgres.sql new file mode 100644 index 000000000..facbdabad --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen9_postgres.sql @@ -0,0 +1,7 @@ +SELECT + name +FROM main.restaurant +ORDER BY + rating DESC NULLS LAST, + 1 DESC NULLS LAST +LIMIT 3 diff --git a/tests/test_sql_refsols/defog_restaurants_gen9_snowflake.sql b/tests/test_sql_refsols/defog_restaurants_gen9_snowflake.sql new file mode 100644 index 000000000..facbdabad --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen9_snowflake.sql @@ -0,0 +1,7 @@ +SELECT + name +FROM main.restaurant +ORDER BY + rating DESC NULLS LAST, + 1 DESC NULLS LAST +LIMIT 3 diff --git a/tests/test_sql_refsols/defog_restaurants_gen9_sqlite.sql b/tests/test_sql_refsols/defog_restaurants_gen9_sqlite.sql new file mode 100644 index 000000000..33f54de55 --- /dev/null +++ b/tests/test_sql_refsols/defog_restaurants_gen9_sqlite.sql @@ -0,0 +1,7 @@ +SELECT + name +FROM main.restaurant +ORDER BY + rating DESC, + 1 DESC +LIMIT 3