Skip to content

Commit

Permalink
Compile join operator
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
zombiezen committed Feb 16, 2024
1 parent 2a1be1a commit 40e2b3e
Show file tree
Hide file tree
Showing 34 changed files with 413 additions and 123 deletions.
399 changes: 290 additions & 109 deletions pql.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions testdata/Goldens/Join/input.pql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LexResults
| join (Tokens) on Kind
| sort by SpanStart asc
| project TokenConstant, Value
3 changes: 3 additions & 0 deletions testdata/Goldens/Join/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TokenIdentifier,foo
TokenPipe,
TokenIdentifier,bar
3 changes: 3 additions & 0 deletions testdata/Goldens/Join/output.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WITH "subquery0" AS (SELECT * FROM "Tokens"),
"subquery1" AS (SELECT * FROM (SELECT DISTINCT * FROM "LexResults") AS "$left" JOIN "subquery0" AS "$right" ON "$left"."Kind" = "$right"."Kind" ORDER BY "SpanStart" ASC NULLS FIRST)
SELECT "TokenConstant" AS "TokenConstant", "Value" AS "Value" FROM "subquery1";
4 changes: 4 additions & 0 deletions testdata/Goldens/JoinExplicit/input.pql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LexResults
| join (Tokens) on $left.Kind == $right.Kind
| sort by SpanStart asc
| project TokenConstant, Value
3 changes: 3 additions & 0 deletions testdata/Goldens/JoinExplicit/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
TokenIdentifier,foo
TokenPipe,
TokenIdentifier,bar
3 changes: 3 additions & 0 deletions testdata/Goldens/JoinExplicit/output.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WITH "subquery0" AS (SELECT * FROM "Tokens"),
"subquery1" AS (SELECT * FROM (SELECT DISTINCT * FROM "LexResults") AS "$left" JOIN "subquery0" AS "$right" ON "$left"."Kind" = "$right"."Kind" ORDER BY "SpanStart" ASC NULLS FIRST)
SELECT "TokenConstant" AS "TokenConstant", "Value" AS "Value" FROM "subquery1";
4 changes: 4 additions & 0 deletions testdata/Goldens/JoinExtraCond/input.pql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LexResults
| join (Tokens) on Kind, Value != "bar"
| sort by SpanStart asc
| project TokenConstant, Value
2 changes: 2 additions & 0 deletions testdata/Goldens/JoinExtraCond/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TokenIdentifier,foo
TokenPipe,
3 changes: 3 additions & 0 deletions testdata/Goldens/JoinExtraCond/output.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WITH "subquery0" AS (SELECT * FROM "Tokens"),
"subquery1" AS (SELECT * FROM (SELECT DISTINCT * FROM "LexResults") AS "$left" JOIN "subquery0" AS "$right" ON ("$left"."Kind" = "$right"."Kind") AND (coalesce("Value" <> 'bar', FALSE)) ORDER BY "SpanStart" ASC NULLS FIRST)
SELECT "TokenConstant" AS "TokenConstant", "Value" AS "Value" FROM "subquery1";
4 changes: 4 additions & 0 deletions testdata/Goldens/JoinInner/input.pql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
StormEvents
| project State
| join kind=inner (StateCapitals | project State = upper(State), StateCapital) on State
| sort by State asc
4 changes: 4 additions & 0 deletions testdata/Goldens/JoinInner/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FLORIDA,FLORIDA,Tallahassee
FLORIDA,FLORIDA,Tallahassee
GEORGIA,GEORGIA,Atlanta
MISSISSIPPI,MISSISSIPPI,Jackson
3 changes: 3 additions & 0 deletions testdata/Goldens/JoinInner/output.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WITH "subquery0" AS (SELECT "State" AS "State" FROM "StormEvents"),
"subquery1" AS (SELECT upper("State") AS "State", "StateCapital" AS "StateCapital" FROM "StateCapitals")
SELECT * FROM "subquery0" AS "$left" JOIN "subquery1" AS "$right" ON "$left"."State" = "$right"."State" ORDER BY "State" ASC NULLS FIRST;
4 changes: 4 additions & 0 deletions testdata/Goldens/JoinInnerUnique/input.pql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
StormEvents
| project State
| join kind=innerunique (StateCapitals | project State = upper(State), StateCapital) on State
| sort by State asc
3 changes: 3 additions & 0 deletions testdata/Goldens/JoinInnerUnique/output.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FLORIDA,FLORIDA,Tallahassee
GEORGIA,GEORGIA,Atlanta
MISSISSIPPI,MISSISSIPPI,Jackson
3 changes: 3 additions & 0 deletions testdata/Goldens/JoinInnerUnique/output.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
WITH "subquery0" AS (SELECT "State" AS "State" FROM "StormEvents"),
"subquery1" AS (SELECT upper("State") AS "State", "StateCapital" AS "StateCapital" FROM "StateCapitals")
SELECT * FROM (SELECT DISTINCT * FROM "subquery0") AS "$left" JOIN "subquery1" AS "$right" ON "$left"."State" = "$right"."State" ORDER BY "State" ASC NULLS FIRST;
4 changes: 2 additions & 2 deletions testdata/Goldens/OpParens/input.pql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Tokens
| where Value - 3 > 0
| sort by Value asc
| where Kind - 3 > 0
| sort by Kind asc
1 change: 1 addition & 0 deletions testdata/Goldens/OpParens/output.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
4,TokenString
5,TokenAnd
6,TokenOr
7,TokenPipe
2 changes: 1 addition & 1 deletion testdata/Goldens/OpParens/output.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM "Tokens" WHERE ("Value" - 3) > 0 ORDER BY "Value" ASC NULLS FIRST;
SELECT * FROM "Tokens" WHERE ("Kind" - 3) > 0 ORDER BY "Kind" ASC NULLS FIRST;
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereFunc/input.pql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Tokens
| where abs(Value) == 1
| where abs(Kind) == 1
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereFunc/output.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM "Tokens" WHERE coalesce(abs("Value") = 1, FALSE);
SELECT * FROM "Tokens" WHERE coalesce(abs("Kind") = 1, FALSE);
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereIsNotNull/input.pql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Tokens
| where isnotnull(Value)
| where isnotnull(Kind)
1 change: 1 addition & 0 deletions testdata/Goldens/WhereIsNotNull/output.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
4,TokenString
5,TokenAnd
6,TokenOr
7,TokenPipe
-1,TokenError
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereIsNotNull/output.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM "Tokens" WHERE "Value" IS NOT NULL;
SELECT * FROM "Tokens" WHERE "Kind" IS NOT NULL;
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereIsNull/input.pql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Tokens
| where isnull(Value)
| where isnull(Kind)
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereIsNull/output.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM "Tokens" WHERE "Value" IS NULL;
SELECT * FROM "Tokens" WHERE "Kind" IS NULL;
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereNot/input.pql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Tokens
| where not(Value > 0)
| where not(Kind > 0)
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereNot/output.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM "Tokens" WHERE NOT ("Value" > 0);
SELECT * FROM "Tokens" WHERE NOT ("Kind" > 0);
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereNotEqualsNegative/input.pql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Tokens
| where Value != -1
| where Kind != -1
1 change: 1 addition & 0 deletions testdata/Goldens/WhereNotEqualsNegative/output.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
4,TokenString
5,TokenAnd
6,TokenOr
7,TokenPipe
2 changes: 1 addition & 1 deletion testdata/Goldens/WhereNotEqualsNegative/output.sql
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SELECT * FROM "Tokens" WHERE coalesce("Value" <> -1, FALSE);
SELECT * FROM "Tokens" WHERE coalesce("Kind" <> -1, FALSE);
4 changes: 4 additions & 0 deletions testdata/Tables/LexResults.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Kind,SpanStart,SpanEnd,Value
1,0,3,foo
7,4,5,""
1,6,9,bar
51 changes: 51 additions & 0 deletions testdata/Tables/StateCapitals.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"State","StateCapital"
Alabama,Montgomery
Alaska,Juneau
Arizona,Phoenix
Arkansas,Little
California,Sacramento
Colorado,Denver
Connecticut,Hartford
Delaware,Dover
Florida,Tallahassee
Georgia,Atlanta
Hawaii,Honolulu
Idaho,Boise
Illinois,Springfield
Indiana,Indianapolis
Iowa,Des
Kansas,Topeka
Kentucky,Frankfort
Louisiana,Baton
Maine,Augusta
Maryland,Annapolis
Massachusetts,Boston
Michigan,Lansing
Minnesota,Saint
Mississippi,Jackson
Missouri,Jefferson
Montana,Helena
Nebraska,Lincoln
Nevada,Carson
New Hampshire,Concord
New Jersey,Trenton
New Mexico,Santa
New York,Albany
North Carolina,Raleigh
North Dakota,Bismarck
Ohio,Columbus
Oklahoma,Oklahoma
Oregon,Salem
Pennsylvania,Harrisburg
Rhode Island,Providence
South Carolina,Columbia
South Dakota,Pierre
Tennessee,Nashville
Texas,Austin
Utah,Salt
Vermont,Montpelier
Virginia,Richmond
Washington,Olympia
West Virginia,Charleston
Wisconsin,Madison
Wyoming,Cheyenne
3 changes: 2 additions & 1 deletion testdata/Tables/Tokens.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Value,Name
Kind,TokenConstant
1,TokenIdentifier
2,TokenQuotedIdentifier
3,TokenNumber
4,TokenString
5,TokenAnd
6,TokenOr
7,TokenPipe
-1,TokenError

0 comments on commit 40e2b3e

Please sign in to comment.