diff --git a/Examples/Language/Basic/create_ranges_of_numbers_and_dates.usql b/Examples/Language/Basic/create_ranges_of_numbers_and_dates.usql new file mode 100644 index 0000000..4f87d65 --- /dev/null +++ b/Examples/Language/Basic/create_ranges_of_numbers_and_dates.usql @@ -0,0 +1,41 @@ +DECLARE @StartDate = DateTime.Parse("1979-03-31"); + +@numbers_10 = + SELECT + * + FROM + (VALUES + (0), + (1), + (2), + (3), + (4), + (5), + (6), + (7), + (8), + (9) + ) AS T(Value); + +@numbers_100 = + SELECT (a.Value*10 + b.Value) AS Value + FROM @numbers_10 AS a CROSS JOIN @numbers_10 AS b; + +@numbers_10000 = + SELECT (a.Value*100 + b.Value) AS Value + FROM @numbers_100 AS a CROSS JOIN @numbers_100 AS b; + +@dates_10000 = + SELECT + Value, + @StartDate.AddDays( Value ) AS Date + FROM @numbers_10000; + +OUTPUT @numbers_10000 + TO "/Samples/Output/numbers_10000.csv" + USING Outputters.Csv(outputHeader:true); + +OUTPUT @dates_10000 + TO "/Samples/Output/dates_10000.csv" + USING Outputters.Csv(outputHeader:true); + diff --git a/Examples/Language/Catalog/create_table_as_select_new.usql b/Examples/Language/Catalog/create_table_as_select_new.usql new file mode 100644 index 0000000..f82d5dd --- /dev/null +++ b/Examples/Language/Catalog/create_table_as_select_new.usql @@ -0,0 +1,27 @@ +@projectmembers = + SELECT * + FROM + ( VALUES + ( "Website","Mallory", "PM" ), + ( "Website","Bob", "Dev" ), + ( "Website","Alice", "Dev" ) , + ( "Website","Stan", "Dev" ) , + ( "Website","Chris", "UX" ) , + ( "DB", "Ted", "Test" ), + ( "DB", "Joe", "Dev" ) , + ( "DB", "Chuck", "Dev" ) + ) +AS T(Project, Employee, Role); + + +CREATE DATABASE IF NOT EXISTS MyDB; + +DROP TABLE IF EXISTS MyDB.dbo.ProjectMembersRaw; + +CREATE TABLE MyDB.dbo.ProjectMembersRaw +( + INDEX idx + CLUSTERED(Project ASC) + DISTRIBUTED BY + RANGE(Project) +) AS SELECT * FROM @projectmembers; diff --git a/Examples/Language/ComplexTypes/map_agg_new.usql b/Examples/Language/ComplexTypes/map_agg_new.usql new file mode 100644 index 0000000..59de65e --- /dev/null +++ b/Examples/Language/ComplexTypes/map_agg_new.usql @@ -0,0 +1,30 @@ +@projectmembers_raw = + SELECT * + FROM + ( VALUES + ( "Website","Mallory", "PM" ), + ( "Website","Bob", "Dev" ), + ( "Website","Alice", "Dev" ) , + ( "Website","Stan", "Dev" ) , + ( "Website","Chris", "UX" ) , + ( "DB", "Ted", "Test" ), + ( "DB", "Joe", "Dev" ) , + ( "DB", "Chuck", "Dev" ) + ) +AS T(Project, Employee, Role); + +@projectmembers = + SELECT + Project, + MAP_AGG(Employee, Role) AS Members + FROM @projectmembers_raw + GROUP BY Project; + +@projectmembers = + SELECT Project, + string.Join(",", Members.Select(p => String.Format("{0}:{1}", p.Key, p.Value))) AS Members + FROM @projectmembers; + +OUTPUT @projectmembers + TO @"/Samples/Output/MAP_AGG_output.tsv" + USING Outputters.Tsv(); \ No newline at end of file diff --git a/Examples/Language/WindowFunctions/any_n_in_group_new.usql b/Examples/Language/WindowFunctions/any_n_in_group_new.usql new file mode 100644 index 0000000..0397604 --- /dev/null +++ b/Examples/Language/WindowFunctions/any_n_in_group_new.usql @@ -0,0 +1,27 @@ + +@num_per_group = 3; + +@querylog = + SELECT * FROM ( VALUES + ("Banana" , 300, "Image" ), + ("Cherry" , 300, "Image" ), + ("Durian" , 500, "Image" ), + ("Apple" , 100, "Web" ), + ("Fig" , 200, "Web" ), + ("Papaya" , 200, "Web" ), + ("Avocado" , 300, "Web" ), + ("Cherry" , 400, "Web" ), + ("Durian" , 500, "Web" ) ) + AS T(Query,Latency,Vertical); + +@result = + SELECT + *, + ROW_NUMBER() + OVER (PARTITION BY Vertical ORDER BY 1) AS RowNumber + FROM @querylog; + +@result = + SELECT * + FROM @result + WHERE RowNumber <= @num_per_group; \ No newline at end of file diff --git a/Examples/Language/WindowFunctions/percentile_new.usql b/Examples/Language/WindowFunctions/percentile_new.usql new file mode 100644 index 0000000..2b4346c --- /dev/null +++ b/Examples/Language/WindowFunctions/percentile_new.usql @@ -0,0 +1,30 @@ +@querylog = + SELECT * FROM ( VALUES + ("Banana" , 300, "Image" ), + ("Cherry" , 300, "Image" ), + ("Durian" , 500, "Image" ), + ("Apple" , 100, "Web" ), + ("Fig" , 200, "Web" ), + ("Papaya" , 200, "Web" ), + ("Avocado" , 300, "Web" ), + ("Cherry" , 400, "Web" ), + ("Durian" , 500, "Web" ) ) + AS T(Query,Latency,Vertical); + +@result = + SELECT + Vertical, + Query, + PERCENTILE_CONT(0.5) + WITHIN GROUP (ORDER BY Latency) + OVER ( PARTITION BY Vertical ) AS PercentileCont50, + PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY Latency) + OVER ( PARTITION BY Vertical ) AS PercentileDisc50 + FROM @querylog; + + +OUTPUT @result +TO @"/Samples/Output/percentile.tsv" +USING Outputters.Tsv(); + diff --git a/Examples/Language/WindowFunctions/ranking_new.usql b/Examples/Language/WindowFunctions/ranking_new.usql new file mode 100644 index 0000000..b3f19c6 --- /dev/null +++ b/Examples/Language/WindowFunctions/ranking_new.usql @@ -0,0 +1,26 @@ +@querylog = + SELECT * FROM ( VALUES + ("Banana" , 300, "Image" ), + ("Cherry" , 300, "Image" ), + ("Durian" , 500, "Image" ), + ("Apple" , 100, "Web" ), + ("Fig" , 200, "Web" ), + ("Papaya" , 200, "Web" ), + ("Avocado" , 300, "Web" ), + ("Cherry" , 400, "Web" ), + ("Durian" , 500, "Web" ) ) + AS T(Query,Latency,Vertical); + +@result = + SELECT + *, + ROW_NUMBER() OVER (PARTITION BY Vertical ORDER BY Latency) AS RowNumber, + RANK() OVER (PARTITION BY Vertical ORDER BY Latency) AS Rank, + DENSE_RANK() OVER (PARTITION BY Vertical ORDER BY Latency) AS DenseRank + FROM @querylog; + + +OUTPUT @result +TO @"/Samples/Output/ranking.tsv" +USING Outputters.Tsv(); + diff --git a/Examples/Language/WindowFunctions/top_n_in_group_new.usql b/Examples/Language/WindowFunctions/top_n_in_group_new.usql new file mode 100644 index 0000000..104ba74 --- /dev/null +++ b/Examples/Language/WindowFunctions/top_n_in_group_new.usql @@ -0,0 +1,27 @@ + +@num_per_group = 3; + +@querylog = + SELECT * FROM ( VALUES + ("Banana" , 300, "Image" ), + ("Cherry" , 300, "Image" ), + ("Durian" , 500, "Image" ), + ("Apple" , 100, "Web" ), + ("Fig" , 200, "Web" ), + ("Papaya" , 200, "Web" ), + ("Avocado" , 300, "Web" ), + ("Cherry" , 400, "Web" ), + ("Durian" , 500, "Web" ) ) + AS T(Query,Latency,Vertical); + +@result = + SELECT + *, + ROW_NUMBER() + OVER (PARTITION BY Vertical ORDER BY Latency) AS RowNumber + FROM @querylog; + +@result = + SELECT * + FROM @result + WHERE RowNumber <= @num_per_group; \ No newline at end of file