From c516d9e4563a320ee567bfec54e4e325536fa08d Mon Sep 17 00:00:00 2001 From: Benjamin Gaidioz Date: Fri, 30 Aug 2024 15:42:52 +0200 Subject: [PATCH 1/2] Tests for RD-14664 --- .../resources/large-query-that-generates.sql | 52 +++ .../test/resources/large-query-with-list.sql | 303 ++++++++++++++++++ .../rawlabs/sql/compiler/TestSqlParser.scala | 42 ++- 3 files changed, 392 insertions(+), 5 deletions(-) create mode 100644 sql-compiler/src/test/resources/large-query-that-generates.sql create mode 100644 sql-compiler/src/test/resources/large-query-with-list.sql diff --git a/sql-compiler/src/test/resources/large-query-that-generates.sql b/sql-compiler/src/test/resources/large-query-that-generates.sql new file mode 100644 index 000000000..2bbb4f9a5 --- /dev/null +++ b/sql-compiler/src/test/resources/large-query-that-generates.sql @@ -0,0 +1,52 @@ +SELECT + -- Identifier, which comes from "generate_series" + s as id, + -- Pick a random first name from 'firstnames' array + arrays.firstnames[trunc(random() * ARRAY_LENGTH(arrays.firstnames, 1) + 1)] AS firstname, + -- Pick a random middle name character + substring('ABCDEFGHIJKLMNOPQRSTUVWXYZ' from trunc(random() * 26 + 1)::int for 1) AS middlename, + -- Pick a random last name from 'lastnames' array + arrays.lastnames[trunc(random() * ARRAY_LENGTH(arrays.lastnames,1) + 1)] AS lastname, + -- Pick number birthdate + date(now() - trunc(random() * 365 * 82 /*max age + 18*/) * '1 day'::interval - interval '18 year' /* min age*/) as birth_date, + -- Generate random SSN number + 100000000 + round(random() * 900000000) as ssn, + -- Generate random amount + round((random() * 100000)::numeric, 2) as amount, + -- Generate random house number + (100 + random() * 9900)::int as house, + -- Generate random stree name from 'streets' + arrays.streets[trunc(random() * ARRAY_LENGTH(arrays.streets, 1) + 1)] AS street, + -- Choose random street type + case (random() * 2)::int when 0 then 'St.' when 1 then 'Ave.' when 2 then 'Rd.' end as street_type, + -- Pick random city + arrays.cities[trunc(random() * ARRAY_LENGTH(arrays.cities, 1) + 1)] AS city, + -- Pick random state + arrays.states[trunc(random() * ARRAY_LENGTH(arrays.states, 1) + 1)] AS state, + -- Generate random phone number + concat(FLOOR(100 + random() * 900), ' ', FLOOR(100 + random() * 900), ' ', FLOOR(1000 + random() * 9000)) as phone +FROM + -- Number of rows to generate + generate_series(1, 1000) AS s +CROSS JOIN( + SELECT ARRAY[ + 'Adam', 'Bill', 'Bob', 'Donald', 'Frank', 'George', 'James', 'John', 'Jacob', 'Jack', 'Martin', 'Matthew', 'Max', 'Michael', 'Paul','Peter', 'Ronald', + 'Samuel','Steve','William', 'Abigail', 'Alice', 'Amanda', 'Barbara','Betty', 'Carol', 'Donna', 'Jane','Jennifer','Julie','Mary','Melissa','Sarah','Susan' + ] AS firstnames, + ARRAY[ + 'Matthews','Smith','Jones','Davis','Jacobson','Williams','Donaldson','Maxwell','Peterson','Stevens', 'Franklin','Washington','Jefferson','Adams', + 'Jackson','Johnson','Lincoln','Grant','Fillmore','Harding','Taft', 'Truman','Nixon','Ford','Carter','Reagan','Bush','Clinton','Hancock' + ] AS lastnames, + ARRAY[ + 'Green', 'Smith', 'Church', 'Grant', 'Cedar', 'Forest', 'Frankl', 'Birch', 'Jones', 'Brown', + 'Cherry', 'Willow', 'Rose', 'School', 'Wilson', 'Center', 'Walnut', 'Mill', 'Valley' + ] as streets, + ARRAY[ + 'Washington', 'Franklin', 'Clinton', 'Georgetown', 'Springfield', 'Chester', 'Greenville', 'Dayton', 'Madison', 'Salem', + 'Winchester', 'Oakland', 'Milton', 'Newport', 'Ashland', 'Riverside', 'Manchester', 'Oxford', 'Burlington', 'Jackson', 'Milford' + ] as cities, + ARRAY[ + 'AK','AL','AR','AZ','CA','CO','CT','DC','DE','FL','GA','HI','IA','ID','IL','IN','KS','KY','LA','MA','MD','ME','MI','MN','MS','MO', + 'MT','NC','NE','NH','NJ','NM','NV','NY','ND','OH','OK','OR','PA','RI','SC','SD','TN','TX','UT','VT','VA','WA','WV','WI','WY' + ] as states +) AS arrays \ No newline at end of file diff --git a/sql-compiler/src/test/resources/large-query-with-list.sql b/sql-compiler/src/test/resources/large-query-with-list.sql new file mode 100644 index 000000000..1da5ad8a5 --- /dev/null +++ b/sql-compiler/src/test/resources/large-query-with-list.sql @@ -0,0 +1,303 @@ +SELECT f1, f2, f3, f4, f5, f6 FROM +(VALUES + (1, 'xyz', NULL, 'xyz', 0, 1), +(2, 'xyz', NULL, 'xyz', 0, 1), +(3, 'xyz', NULL, 'xyz', 2501, 1), +(4, 'xyz', NULL, 'xyz', 11, 1), +(5, 'xyz', NULL, 'xyz', 11, 1), +(6, 'xyz', NULL, 'xyz', 11, 1), +(7, 'xyz', NULL, 'xyz', 11, 1), +(8, 'xyz', NULL, 'xyz', 101, 1), +(9, 'xyz', NULL, 'xyz', 0, 1), +(10, 'xyz', 'xyz', 'xyz', 51, 1), +(11, 'xyz', NULL, 'xyz', 101, 1), +(12, 'xyz', NULL, 'xyz', 0, 1), +(13, 'xyz', 'xyz', 'xyz', 2501, 1), +(14, 'xyz', 'xyz', 'xyz', 2501, 1), +(15, 'xyz', 'xyz', 'xyz', 0, 1), +(16, 'xyz', 'xyz', 'xyz', 123, 1), +(17, 'xyz', 'xyz', 'xyz', 123, 1), +(18, 'xyz', 'xyz', 'xyz', 0, 1), +(19, 'xyz', 'xyz', 'xyz', 0, 2501), +(20, 'xyz', 'xyz', 'xyz', 0, 2501), +(21, 'xyz', 'xyz', 'xyz', 0, 2501), +(22, 'xyz', 'xyz', 'xyz', 0, 2501), +(23, 'xyz', 'xyz', 'xyz', 0, 2501), +(24, 'xyz', 'xyz', 'xyz', 0, 2501), +(25, 'xyz', 'xyz', 'xyz', 0, 2501), +(26, 'xyz', 'xyz', 'xyz', 0, 2501), +(27, 'xyz', NULL, 'xyz', 101, 1), +(28, 'xyz', 'xyz', 'xyz', 0, 1), +(29, 'xyz', NULL, 'xyz', 0, 1), +(30, 'xyz', NULL, 'xyz', 0, 1), +(31, 'xyz', 'xyz', 'xyz', 2501, 1), +(32, 'xyz', 'xyz', 'xyz', 2501, 1), +(33, 'xyz', 'xyz', 'xyz', 2501, 1), +(34, 'xyz', 'xyz', 'xyz', 2501, 1), +(35, 'xyz', 'xyz', 'xyz', 0, 1), +(36, 'xyz', 'xyz', 'xyz', 2501, 1), +(37, 'xyz', 'xyz', 'xyz', 123, 1), +(38, 'xyz', 'xyz', 'xyz', 123, 1), +(39, 'xyz', 'xyz', 'xyz', 101, 1), +(40, 'xyz', 'xyz', 'xyz', 123, 1), +(41, 'xyz', 'xyz', 'xyz', 0, 1), +(42, 'xyz', 'xyz', 'xyz', 123, 1), +(43, 'xyz', 'xyz', 'xyz', 0, 1), +(44, 'xyz', NULL, 'xyz', 2501, 1), +(45, 'xyz', NULL, 'xyz', 2501, 1), +(46, 'xyz', 'xyz', 'xyz', 0, 1), +(47, 'xyz', NULL, 'xyz', 2501, 1), +(48, 'xyz', NULL, 'xyz', 2501, 1), +(49, 'xyz', 'xyz', 'xyz', 2501, 1), +(50, 'xyz', 'xyz', 'xyz', 0, 1), +(51, 'xyz', 'xyz', 'xyz', 2501, 1), +(52, 'xyz', 'xyz', 'xyz', 0, 1), +(53, 'xyz', 'xyz', 'xyz', 2501, 1), +(54, 'xyz', 'xyz', 'xyz', 0, 1), +(55, 'xyz', 'xyz', 'xyz', 2501, 1), +(56, 'xyz', 'xyz', 'xyz', 0, 1), +(57, 'xyz', 'xyz', 'xyz', 2501, 1), +(58, 'xyz', 'xyz', 'xyz', 0, 1), +(59, 'xyz', 'xyz', 'xyz', 0, 1), +(60, 'xyz', 'xyz', 'xyz', 123, 1), +(61, 'xyz', 'xyz', 'xyz', 0, 1), +(62, 'xyz', 'xyz', 'xyz', 123, 1), +(63, 'xyz', 'xyz', 'xyz', 0, 1), +(64, 'xyz', 'xyz', 'xyz', 123, 1), +(65, 'xyz', 'xyz', 'xyz', 0, 1), +(66, 'xyz', 'xyz', 'xyz', 123, 1), +(67, 'xyz', 'xyz', 'xyz', 0, 1), +(68, 'xyz', 'xyz', 'xyz', 101, 1), +(69, 'xyz', 'xyz', 'xyz', 0, 1), +(70, 'xyz', NULL, 'xyz', 11, 1), +(71, 'xyz', NULL, 'xyz', 11, 1), +(72, 'xyz', 'xyz', 'xyz', 0, 1), +(73, 'xyz', NULL, 'xyz', 2501, 1), +(74, 'xyz', NULL, 'xyz', 11, 1), +(75, 'xyz', NULL, 'xyz', 11, 1), +(76, 'xyz', 'xyz', 'xyz', 0, 1), +(77, 'xyz', NULL, 'xyz', 0, 1), +(78, 'xyz', NULL, 'xyz', 0, 1), +(79, 'xyz', NULL, 'xyz', 2501, 1), +(80, 'xyz', NULL, 'xyz', 11, 1), +(81, 'xyz', NULL, 'xyz', 101, 1), +(82, 'xyz', NULL, 'xyz', 2501, 1), +(83, 'xyz', NULL, 'xyz', 11, 1), +(84, 'xyz', NULL, 'xyz', 101, 1), +(85, 'xyz', NULL, 'xyz', 11, 1), +(86, 'xyz', NULL, 'xyz', 11, 1), +(87, 'xyz', NULL, 'xyz', 11, 1), +(88, 'xyz', NULL, 'xyz', 11, 1), +(89, 'xyz', NULL, 'xyz', 2501, 1), +(90, 'xyz', NULL, 'xyz', 2501, 1), +(91, 'xyz', NULL, 'xyz', 11, 1), +(92, 'xyz', NULL, 'xyz', 11, 1), +(93, 'xyz', NULL, 'xyz', 123, 1), +(94, 'xyz', NULL, 'xyz', 123, 1), +(95, 'xyz', NULL, 'xyz', 51, 1), +(96, 'xyz', NULL, 'xyz', 123, 1), +(97, 'xyz', NULL, 'xyz', 0, 1), +(98, 'xyz', NULL, 'xyz', 51, 1), +(99, 'xyz', NULL, 'xyz', 51, 1), +(10, 'xyz', NULL, 'xyz', 101, 1), +(101, 'xyz', NULL, 'xyz', 101, 1), +(102, 'xyz', NULL, 'xyz', 101, 1), +(103, 'xyz', NULL, 'xyz', 2501, 1), +(104, 'xyz', NULL, 'xyz', 2501, 1), +(105, 'xyz', NULL, 'xyz', 0, 1), +(106, 'xyz', NULL, 'xyz', 0, 1), +(107, 'xyz', NULL, 'xyz', 51, 1), +(108, 'xyz', NULL, 'xyz', 51, 1), +(109, 'xyz', NULL, 'xyz', 0, 1), +(110, 'xyz', NULL, 'xyz', 0, 1), +(111, 'xyz', NULL, 'xyz', 0, 1), +(112, 'xyz', NULL, 'xyz', 2501, 1), +(113, 'xyz', NULL, 'xyz', 11, 1), +(114, 'xyz', NULL, 'xyz', 11, 1), +(115, 'xyz', NULL, 'xyz', 11, 1), +(116, 'xyz', NULL, 'xyz', 11, 1), +(117, 'xyz', NULL, 'xyz', 123, 1), +(118, 'xyz', NULL, 'xyz', 51, 1), +(119, 'xyz', NULL, 'xyz', 0, 1), +(120, 'xyz', NULL, 'xyz', 101, 1), +(121, 'xyz', NULL, 'xyz', 0, 1), +(122, 'xyz', 'xyz', 'xyz', 123, 1), +(123, 'xyz', 'xyz', 'xyz', 101, 1), +(124, 'xyz', 'xyz', 'xyz', 0, 1), +(125, 'xyz', 'xyz', 'xyz', 2501, 1), +(126, 'xyz', 'xyz', 'xyz', 0, 1), +(127, 'xyz', NULL, 'xyz', 2501, 1), +(128, 'xyz', NULL, 'xyz', 11, 1), +(129, 'xyz', NULL, 'xyz', 11, 1), +(130, 'xyz', NULL, 'xyz', 101, 1), +(131, 'xyz', NULL, 'xyz', 101, 1), +(132, 'xyz', 'xyz', 'xyz', 0, 1), +(133, 'xyz', 'xyz', 'xyz', 0, 1), +(134, 'xyz', 'xyz', 'xyz', 0, 1), +(135, 'xyz', 'xyz', 'xyz', 0, 1), +(136, 'xyz', 'xyz', 'xyz', 123, 1), +(137, 'xyz', 'xyz', 'xyz', 123, 1), +(138, 'xyz', 'xyz', 'xyz', 101, 1), +(139, 'xyz', 'xyz', 'xyz', 0, 1), +(140, 'xyz', 'xyz', 'xyz', 123, 1), +(141, 'xyz', 'xyz', 'xyz', 123, 1), +(142, 'xyz', 'xyz', 'xyz', 101, 1), +(143, 'xyz', 'xyz', 'xyz', 0, 1), +(144, 'xyz', 'xyz', 'xyz', 123, 1), +(145, 'xyz', 'xyz', 'xyz', 123, 1), +(146, 'xyz', 'xyz', 'xyz', 101, 1), +(147, 'xyz', 'xyz', 'xyz', 0, 1), +(148, 'xyz', 'xyz', 'xyz', 0, 1), +(149, 'xyz', 'xyz', 'xyz', 123, 1), +(150, 'xyz', 'xyz', 'xyz', 123, 1), +(151, 'xyz', 'xyz', 'xyz', 101, 1), +(152, 'xyz', 'xyz', 'xyz', 123, 1), +(153, 'xyz', 'xyz', 'xyz', 123, 1), +(154, 'xyz', 'xyz', 'xyz', 101, 1), +(155, 'xyz', 'xyz', 'xyz', 0, 1), +(156, 'xyz', 'xyz', 'xyz', 123, 1), +(157, 'xyz', 'xyz', 'xyz', 123, 1), +(158, 'xyz', 'xyz', 'xyz', 101, 1), +(159, 'xyz', 'xyz', 'xyz', 0, 1), +(160, 'xyz', 'xyz', 'xyz', 123, 1), +(161, 'xyz', 'xyz', 'xyz', 123, 1), +(162, 'xyz', 'xyz', 'xyz', 101, 1), +(163, 'xyz', 'xyz', 'xyz', 0, 1), +(164, 'xyz', 'xyz', 'xyz', 0, 1), +(165, 'xyz', 'xyz', 'xyz', 0, 1), +(166, 'xyz', 'xyz', 'xyz', 0, 1), +(167, 'xyz', 'xyz', 'xyz', 0, 1), +(168, 'xyz', 'xyz', 'xyz', 0, 1), +(169, 'xyz', 'xyz', 'xyz', 0, 1), +(170, 'xyz', 'xyz', 'xyz', 0, 1), +(171, 'xyz', 'xyz', 'xyz', 0, 1), +(172, 'xyz', 'xyz', 'xyz', 0, 1), +(173, 'xyz', 'xyz', 'xyz', 0, 1), +(174, 'xyz', 'xyz', 'xyz', 0, 1), +(175, 'xyz', 'xyz', 'xyz', 0, 1), +(176, 'xyz', 'xyz', 'xyz', 0, 1), +(177, 'xyz', 'xyz', 'xyz', 0, 1), +(178, 'xyz', 'xyz', 'xyz', 0, 1), +(179, 'xyz', 'xyz', 'xyz', 0, 1), +(180, 'xyz', 'xyz', 'xyz', 0, 1), +(181, 'xyz', 'xyz', 'xyz', 0, 1), +(182, 'xyz', 'xyz', 'xyz', 0, 1), +(183, 'xyz', 'xyz', 'xyz', 0, 1), +(184, 'xyz', 'xyz', 'xyz', 0, 1), +(185, 'xyz', 'xyz', 'xyz', 0, 1), +(186, 'xyz', 'xyz', 'xyz', 0, 1), +(187, 'xyz', 'xyz', 'xyz', 0, 1), +(188, 'xyz', 'xyz', 'xyz', 0, 1), +(189, 'xyz', NULL, 'xyz', 0, 1), +(190, 'xyz', 'xyz', 'xyz', 123, 1), +(191, 'xyz', 'xyz', 'xyz', 123, 1), +(192, 'xyz', 'xyz', 'xyz', 101, 1), +(193, 'xyz', 'xyz', 'xyz', 0, 1), +(194, 'xyz', 'xyz', 'xyz', 123, 1), +(195, 'xyz', 'xyz', 'xyz', 123, 1), +(196, 'xyz', 'xyz', 'xyz', 101, 1), +(197, 'xyz', 'xyz', 'xyz', 0, 1), +(198, 'xyz', 'xyz', 'xyz', 251, 1), +(199, 'xyz', 'xyz', 'xyz', 0, 1), +(20, 'xyz', 'xyz', 'xyz', 0, 1), +(201, 'xyz', 'xyz', 'xyz', 2501, 1), +(202, 'xyz', 'xyz', 'xyz', 0, 1), +(203, 'xyz', 'xyz', 'xyz', 0, 1), +(204, 'xyz', 'xyz', 'xyz', 2501, 1), +(205, 'xyz', 'xyz', 'xyz', 2501, 1), +(206, 'xyz', 'xyz', 'xyz', 0, 1), +(207, 'xyz', 'xyz', 'xyz', 123, 1), +(208, 'xyz', 'xyz', 'xyz', 123, 1), +(209, 'xyz', 'xyz', 'xyz', 123, 1), +(210, 'xyz', 'xyz', 'xyz', 0, 1), +(211, 'xyz', 'xyz', 'xyz', 123, 1), +(212, 'xyz', 'xyz', 'xyz', 123, 1), +(213, 'xyz', 'xyz', 'xyz', 0, 1), +(214, 'xyz', 'xyz', 'xyz', 123, 1), +(215, 'xyz', 'xyz', 'xyz', 123, 1), +(216, 'xyz', 'xyz', 'xyz', 0, 1), +(217, 'xyz', 'xyz', 'xyz', 123, 1), +(218, 'xyz', 'xyz', 'xyz', 123, 1), +(219, 'xyz', 'xyz', 'xyz', 0, 1), +(220, 'xyz', 'xyz', 'xyz', 123, 1), +(221, 'xyz', 'xyz', 'xyz', 123, 1), +(222, 'xyz', 'xyz', 'xyz', 0, 1), +(223, 'xyz', 'xyz', 'xyz', 123, 1), +(224, 'xyz', 'xyz', 'xyz', 123, 1), +(225, 'xyz', 'xyz', 'xyz', 0, 1), +(226, 'xyz', NULL, 'xyz', 123, 1), +(227, 'xyz', NULL, 'xyz', 123, 1), +(228, 'xyz', NULL, 'xyz', 0, 1), +(229, 'xyz', 'xyz', 'xyz', 0, 1), +(230, 'xyz', 'xyz', 'xyz', 251, 1), +(231, 'xyz', 'xyz', 'xyz', 251, 1), +(232, 'xyz', 'xyz', 'xyz', 0, 1), +(233, 'xyz', 'xyz', 'xyz', 0, 1), +(234, 'xyz', 'xyz', 'xyz', 0, 1), +(235, 'xyz', 'xyz', 'xyz', 0, 1), +(236, 'xyz', 'xyz', 'xyz', 123, 1), +(237, 'xyz', 'xyz', 'xyz', 123, 1), +(238, 'xyz', 'xyz', 'xyz', 101, 1), +(239, 'xyz', 'xyz', 'xyz', 123, 1), +(240, 'xyz', 'xyz', 'xyz', 101, 1), +(241, 'xyz', 'xyz', 'xyz', 123, 1), +(242, 'xyz', 'xyz', 'xyz', 123, 1), +(243, 'xyz', 'xyz', 'xyz', 123, 1), +(244, 'xyz', 'xyz', 'xyz', 123, 1), +(245, 'xyz', 'xyz', 'xyz', 123, 1), +(246, 'xyz', 'xyz', 'xyz', 123, 1), +(247, 'xyz', 'xyz', 'xyz', 123, 1), +(248, 'xyz', 'xyz', 'xyz', 123, 1), +(249, 'xyz', 'xyz', 'xyz', 123, 1), +(250, 'xyz', 'xyz', 'xyz', 123, 1), +(251, 'xyz', 'xyz', 'xyz', 123, 1), +(252, 'xyz', 'xyz', 'xyz', 123, 1), +(253, 'xyz', 'xyz', 'xyz', 123, 1), +(254, 'xyz', 'xyz', 'xyz', 123, 1), +(255, 'xyz', 'xyz', 'xyz', 123, 1), +(256, 'xyz', 'xyz', 'xyz', 123, 1), +(257, 'xyz', 'xyz', 'xyz', 123, 1), +(258, 'xyz', 'xyz', 'xyz', 123, 1), +(259, 'xyz', 'xyz', 'xyz', 123, 1), +(260, 'xyz', 'xyz', 'xyz', 123, 1), +(261, 'xyz', 'xyz', 'xyz', 123, 1), +(262, 'xyz', 'xyz', 'xyz', 123, 1), +(263, 'xyz', 'xyz', 'xyz', 123, 1), +(264, 'xyz', 'xyz', 'xyz', 123, 1), +(265, 'xyz', 'xyz', 'xyz', 123, 1), +(266, 'xyz', 'xyz', 'xyz', 123, 1), +(267, 'xyz', 'xyz', 'xyz', 123, 1), +(268, 'xyz', 'xyz', 'xyz', 123, 1), +(269, 'xyz', 'xyz', 'xyz', 123, 1), +(270, 'xyz', 'xyz', 'xyz', 123, 1), +(271, 'xyz', 'xyz', 'xyz', 123, 1), +(272, 'xyz', 'xyz', 'xyz', 123, 1), +(273, 'xyz', 'xyz', 'xyz', 123, 1), +(274, 'xyz', 'xyz', 'xyz', 0, 1), +(275, 'xyz', 'xyz', 'xyz', 0, 1), +(276, 'xyz', 'xyz', 'xyz', 123, 1), +(277, 'xyz', 'xyz', 'xyz', 123, 1), +(278, 'xyz', 'xyz', 'xyz', 0, 1), +(279, 'xyz', 'xyz', 'xyz', 123, 1), +(280, 'xyz', 'xyz', 'xyz', 123, 1), +(281, 'xyz', 'xyz', 'xyz', 123, 1), +(282, 'xyz', 'xyz', 'xyz', 123, 1), +(283, 'xyz', 'xyz', 'xyz', 123, 1), +(284, 'xyz', 'xyz', 'xyz', 123, 1), +(285, 'xyz', 'xyz', 'xyz', 123, 1), +(286, 'xyz', 'xyz', 'xyz', 123, 1), +(287, 'xyz', 'xyz', 'xyz', 123, 1), +(288, 'xyz', 'xyz', 'xyz', 123, 1), +(289, 'xyz', 'xyz', 'xyz', 123, 1), +(290, 'xyz', 'xyz', 'xyz', 123, 1), +(291, 'xyz', 'xyz', 'xyz', 123, 1), +(292, 'xyz', 'xyz', 'xyz', 123, 1), +(293, 'xyz', 'xyz', 'xyz', 123, 1), +(294, 'xyz', 'xyz', 'xyz', 123, 1), +(295, 'xyz', 'xyz', 'xyz', 123, 1), +(296, 'xyz', 'xyz', 'xyz', 123, 1), +(297, 'xyz', 'xyz', 'xyz', 123, 1), +(298, 'xyz', 'xyz', 'xyz', 123, 1), +(299, 'xyz', 'xyz', 'xyz', 123, 1), +(300, 'xyz', 'xyz', 'xyz', 123, 1) +) as T(f1,f2,f3,f4,f5,f6) diff --git a/sql-compiler/src/test/scala/com/rawlabs/sql/compiler/TestSqlParser.scala b/sql-compiler/src/test/scala/com/rawlabs/sql/compiler/TestSqlParser.scala index 2ce018ac2..94658e3be 100644 --- a/sql-compiler/src/test/scala/com/rawlabs/sql/compiler/TestSqlParser.scala +++ b/sql-compiler/src/test/scala/com/rawlabs/sql/compiler/TestSqlParser.scala @@ -21,8 +21,7 @@ import com.rawlabs.sql.compiler.antlr4.{ SqlProjNode, SqlStatementNode, SqlStringLiteralNode, - SqlSyntaxAnalyzer, - SqlWithComaSeparatorNode + SqlSyntaxAnalyzer } import org.bitbucket.inkytonik.kiama.util.Positions import org.scalatest.funsuite.AnyFunSuite @@ -223,9 +222,8 @@ class TestSqlParser extends AnyFunSuite { assert(result.isSuccess) val SqlProgramNode(statement) = result.tree val SqlStatementNode(statementItems) = statement - assert(statementItems.size == 4) - val SqlWithComaSeparatorNode(inStatements) = statementItems(1) - inStatements(1) match { + assert(statementItems.size == 5) + statementItems(2) match { case SqlFunctionCall(name, arguments) => assert(name == "NOW") assert(arguments.isEmpty) @@ -626,4 +624,38 @@ class TestSqlParser extends AnyFunSuite { assert(result.positions.getFinish(stmt).flatMap(_.optOffset).isDefined) } + test("large query 1") { + val largeQ = getClass.getClassLoader.getResourceAsStream("large-query-that-generates.sql") + try { + val content = io.Source.fromInputStream(largeQ) + try { + val code = content.mkString + for (i <- 0 to 10) { + val result = doTest(code) + checkStartEnd(result) + } + } finally { + content.close() + } + } finally { + largeQ.close() + } + } + + test("large query 2") { + val largeQ = getClass.getClassLoader.getResourceAsStream("large-query-with-list.sql") + try { + val content = io.Source.fromInputStream(largeQ) + try { + val code = content.mkString + val result = doTest(code) + checkStartEnd(result) + } finally { + content.close() + } + } finally { + largeQ.close() + } + } + } From 3f7eaf8c15077a38c347625328fd2bd333fd389b Mon Sep 17 00:00:00 2001 From: Benjamin Gaidioz Date: Fri, 30 Aug 2024 15:02:01 +0200 Subject: [PATCH 2/2] Fixed RD-14664 --- .../sql/compiler/antlr4/SqlVisitor.scala | 21 ------------------- .../rawlabs/sql/parser/grammar/PsqlParser.g4 | 3 +-- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/sql-compiler/src/main/scala/com/rawlabs/sql/compiler/antlr4/SqlVisitor.scala b/sql-compiler/src/main/scala/com/rawlabs/sql/compiler/antlr4/SqlVisitor.scala index 3beaf8c14..d0265532c 100644 --- a/sql-compiler/src/main/scala/com/rawlabs/sql/compiler/antlr4/SqlVisitor.scala +++ b/sql-compiler/src/main/scala/com/rawlabs/sql/compiler/antlr4/SqlVisitor.scala @@ -630,27 +630,6 @@ class SqlVisitor( .getOrElse(SqlErrorNode()) } - override def visitCommaSeparated(ctx: PsqlParser.CommaSeparatedContext): SqlBaseNode = { - Option(ctx) - .map { context => - val statements = Option(context.stmt_items()) - .map(s => - s.asScala.map(st => - Option(st) - .flatMap(mdContext => Option(visit(mdContext))) - .getOrElse(SqlErrorNode()) - .asInstanceOf[SqlBaseNode] - ) - ) - .getOrElse(Vector.empty) - .toVector - val withComaSeparator = SqlWithComaSeparatorNode(statements) - positionsWrapper.setPosition(ctx, withComaSeparator) - withComaSeparator - } - .getOrElse(SqlErrorNode()) - } - override def visitTypeCast(ctx: PsqlParser.TypeCastContext): SqlBaseNode = { Option(ctx) .flatMap { context => diff --git a/sql-parser/src/main/java/com/rawlabs/sql/parser/grammar/PsqlParser.g4 b/sql-parser/src/main/java/com/rawlabs/sql/parser/grammar/PsqlParser.g4 index 866f354d0..959314775 100644 --- a/sql-parser/src/main/java/com/rawlabs/sql/parser/grammar/PsqlParser.g4 +++ b/sql-parser/src/main/java/com/rawlabs/sql/parser/grammar/PsqlParser.g4 @@ -76,12 +76,11 @@ multiline_word_or_star: ML_WORD | ML_STAR; stmt: L_PAREN stmt R_PAREN #parenStmt | L_SQ_BRACKET stmt R_SQ_BRACKET #parenStmtSqureBr - | (stmt_items)+ #stmtItems + | (COMMA? stmt_items)+ #stmtItems ; stmt_items: L_PAREN stmt R_PAREN #nestedStmt | L_SQ_BRACKET stmt R_SQ_BRACKET #nestedStmtSqureBr - | stmt_items (COMMA stmt_items)+ #commaSeparated | proj #projStmt | literal #literalStmt | (reserved_keyword | idnt) L_PAREN (stmt_items)? R_PAREN #funCallStmt