Slide 1

Slide 1 text

memefish the Spanner SQL parser and analyzer make.now.just @Go Expert Engineer Team

Slide 2

Slide 2 text

memefish Cloud Spanner SQL parser and analyzer 2 https://github.com/MakeNowJust/memefish

Slide 3

Slide 3 text

Analyze? 3 > SELECT * FROM customers “SELECT *” contains private information: customer_super_private_column

Slide 4

Slide 4 text

memefish: features ● Parse Spanner SQL ○ AST with source code location for diagnostics ○ Also, generate Spanner SQL from AST ● Check expression type and semantics in SQL ○ SELECT X + 1 FROM (SELECT “foo” AS X) type error: operator + requires two INT64/FLOAT64 ○ SELECT X, Y FROM (SELECT 1 AS X, 2 AS Y) AS T GROUP BY T.X semantic error: cannot use non-aggregate key: Y ○ SELECT X FROM (SELECT 1 AS X), (SELECT 2 AS X) semantic error: ambiguous name: X 4 Establish foundation to analyze Spanner SQL

Slide 5

Slide 5 text

memefish: future work memefish is the just foundation, and it can use for general purpose. e.g. ● migration tool like ridgepole ● SQL linter in Go source code ● local Spanner emulator 5

Slide 6

Slide 6 text

Other Contributions I published utilities and contributed some OSS in this internship. 6

Slide 7

Slide 7 text

enumcase Check switch statement in Go handles all enum values. 7 https://github.com/MakeNowJust/enumcase switch op { case Add: // ... case Sub: // ... case Mul: // ... case Div: // ... } missing handling enum value: Mod

Slide 8

Slide 8 text

bluesoul Detect duplicate articles (e.g. the the). Note that many famous OSS codes have such grammar errors... 8 https://github.com/MakeNowJust/bluesoul

Slide 9

Slide 9 text

#44490: spanner/spansql: add parser for all forms of string and bytes literal Contribute to Spanner SQL parser in official GCP Go library. diff size: +332, -32 9

Slide 10

Slide 10 text

Conclusion ● Develop the Go library “memefish” to analyze Spanner SQL. ● Create some Go static analysis tools. ● Contribute Go OSS library. 10 Thank you for listening!

Slide 11

Slide 11 text

Appendix: what’s Spanner SQL? SQL accepted by Spanner. ● poor syntax ○ no WITH clause (of course no WITH RECURSIVE) ○ no analytic (window) function ● Spanner specific features ○ TABLESAMPLE clause ○ hints (@{...}) and query parameters (@foo) But, parsing SQL is hard task... 11