> We didn't write this parser by hand because, at least pre-AI-coding, parsers were extremely difficult to maintain. Writing one without AI would have taken months [...] > Instead, we use ANTLR, a state-of-the-art, open source parser generator. I don't agree with this (pre-AI-coding) take. Hand-rolled parsers are much easier to write well and maintain than people think. They also tend to be much faster and produce mu…
I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code
71–79 of 79 posts
Re: I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code
#72Earlier quoted context omitted.
I think you should clarify that (or whether) while you didn't look at the generated code, you are actually going to adjust it in the future. How did the two approaches compare in terms of code readability?
The previous parser is mostly a declarative grammar file, which is extremely readable. It codegens a C++ parser, which is hard to read. It depends which of those you count as the previous parser's source code! In the future, we'd make changes by modifying the ANTLR parser first, then using the same approach as in the blog post to get the new parser to parity. We have no plans to get rid of the C++ parser as an oracle…
Sort of unexpected that you're keeping the old one as an oracle—but a very good idea for anyone that writes such a complicated parser, indeed!
Re: I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code
#73Is this even true? I tried it in SQLite and there's a syntax error after first SELECT. It would work when "SELECT", "FROM" etc. are quoted, but that's not the same thing.
Re: I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code
#74Re: I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code
#75> there’s a test for SELECT SELECT FROM FROM WHERE WHERE AND AND which is completely valid SQL Is this even true? I tried it in SQLite and there's a syntax error after first SELECT. It would work when "SELECT", "FROM" etc. are quoted, but that's not the same thing.
Re: I rewrote PostHog's SQL parser, 70x faster, while barely looking at the code
#76I have a tool I make as a data-plane to a graph engine, and it uses cap'n proto to help (And sqlite as a sort've IPC option). One of the biggest things I have is, I know I am not testing all of it to completion. I am not even really fuzzing, yet.
Thanks for sharing!