Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: JoinMethod handling is not correct #212

Closed
apstndb opened this issue Nov 24, 2024 · 1 comment
Closed

Bug: JoinMethod handling is not correct #212

apstndb opened this issue Nov 24, 2024 · 1 comment

Comments

@apstndb
Copy link
Contributor

apstndb commented Nov 24, 2024

TL;DR

  • The current JoinMethod is not correct.
  • APPLY and LOOP is not a valid JOIN prefixes.

Description

Only documented join_method(not hint) is HASH, so APPLY and LOOP are not valid join_method.

condition_join_operator:
  {
    [[INNER] [ join_method ] JOIN](https://cloud.google.com/spanner/docs/reference/standard-sql/query-syntax#inner_join)
    | [FULL [OUTER] [ join_method ] JOIN](https://cloud.google.com/spanner/docs/reference/standard-sql/query-syntax#full_join)
    | [LEFT [OUTER] [ join_method ] JOIN](https://cloud.google.com/spanner/docs/reference/standard-sql/query-syntax#left_join)
    | [RIGHT [OUTER] [ join_method ] JOIN](https://cloud.google.com/spanner/docs/reference/standard-sql/query-syntax#right_join)
  }

join_method:
  { HASH }
SELECT * FROM Singers APPLY JOIN Albums USING (SingerId);
SELECT * FROM Singers LOOP JOIN Albums USING (SingerId);

are interpreted as

SELECT * FROM Singers AS APPLY JOIN Albums USING (SingerId);
SELECT * FROM Singers AS LOOP JOIN Albums USING (SingerId);

It can be verified using .*.

spanner> SELECT APPLY.* FROM Singers APPLY JOIN Albums USING (SingerId);
+----------+-----------+----------+------------+------------+
| SingerId | FirstName | LastName | SingerInfo | BirthDate  |
+----------+-----------+----------+------------+------------+
| 1        | Marc      | Richards | NULL       | 1970-09-03 |
| 1        | Marc      | Richards | NULL       | 1970-09-03 |
| 2        | Catalina  | Smith    | NULL       | 1990-08-17 |
| 2        | Catalina  | Smith    | NULL       | 1990-08-17 |
| 2        | Catalina  | Smith    | NULL       | 1990-08-17 |
| 3        | Alice     | Trentor  | NULL       | 1991-10-02 |
| 4        | Lea       | Martin   | NULL       | 1991-11-09 |
+----------+-----------+----------+------------+------------+
7 rows in set (7.15 msecs)

spanner> SELECT LOOP.* FROM Singers LOOP JOIN Albums USING (SingerId);
+----------+-----------+----------+------------+------------+
| SingerId | FirstName | LastName | SingerInfo | BirthDate  |
+----------+-----------+----------+------------+------------+
| 1        | Marc      | Richards | NULL       | 1970-09-03 |
| 1        | Marc      | Richards | NULL       | 1970-09-03 |
| 2        | Catalina  | Smith    | NULL       | 1990-08-17 |
| 2        | Catalina  | Smith    | NULL       | 1990-08-17 |
| 2        | Catalina  | Smith    | NULL       | 1990-08-17 |
| 3        | Alice     | Trentor  | NULL       | 1991-10-02 |
| 4        | Lea       | Martin   | NULL       | 1991-11-09 |
+----------+-----------+----------+------------+------------+
7 rows in set (5.38 msecs)

I believe this bug can break valid queries, so it is needed to be fixed.

Note

There is a undocument LOOKUP join method. It is unimplemented, but it can be parsed.

https://github.com/google/zetasql/blob/a516c6b26d183efc4f56293256bba92e243b7a61/zetasql/parser/zetasql.tm#L7713-L7718

spanner> SELECT * FROM Singers LOOKUP JOIN Albums USING (SingerId);
ERROR: spanner: code = "InvalidArgument", desc = "Invalid value for join_type/join_method hint: LOOKUP_JOIN."

Related issue

@apstndb
Copy link
Contributor Author

apstndb commented Nov 26, 2024

Resolved #213

@apstndb apstndb closed this as completed Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant