Skip to content

Commit 025e138

Browse files
author
Kirill
committed
code improvement
1 parent 1a1faee commit 025e138

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/sql/parser.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,19 @@ AST<Expr> Parser::parse_expr(std::string_view ctxt, Tok::Prec cur_prec) {
109109

110110
while (true) {
111111
if (accept(Tok::Tag::K_NOT)){
112-
if(accept(Tok::Tag::K_LIKE)){
113-
auto rhs = parse_expr("right-hand side of binary expression with NOT in front of operator", *Tok::bin_prec(Tok::Tag::K_LIKE));
114-
lhs = ast<BinExprWithPreTag>(track, std::move(lhs), Tok::Tag::K_NOT, Tok::Tag::K_LIKE, std::move(rhs));
115-
} else if(accept(Tok::Tag::K_BETWEEN)){
116-
auto rhs = parse_expr("right-hand side of binary expression with NOT in front of operator", *Tok::bin_prec(Tok::Tag::K_BETWEEN));
117-
lhs = ast<BinExprWithPreTag>(track, std::move(lhs), Tok::Tag::K_NOT, Tok::Tag::K_BETWEEN, std::move(rhs));
112+
switch(ahead().tag()){
113+
case Tok::Tag::K_LIKE:
114+
case Tok::Tag::K_BETWEEN: {
115+
auto tag = lex().tag();
116+
auto rhs = parse_expr("right-hand side of binary expression with NOT in front of operator", *Tok::bin_prec(tag));
117+
lhs = ast<BinExprWithPreTag>(track, std::move(lhs), Tok::Tag::K_NOT, tag, std::move(rhs));
118+
break;
119+
}
120+
default:
121+
err("binary expr with NOT", ctxt);
122+
return nullptr;
118123
}
124+
119125
} else
120126
if (auto prec = Tok::bin_prec(ahead().tag())) {
121127
if (*prec < cur_prec) break;

test/select.sql

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1-
SELECT note
2-
FROM company_type
3-
WHERE production_year between 2005 and 2010;
1+
SELECT MIN(mc.note) AS production_note,
2+
MIN(t.title) AS movie_title,
3+
MIN(t.production_year) AS movie_year
4+
FROM company_type AS ct,
5+
info_type AS it,
6+
movie_companies AS mc,
7+
movie_info_idx AS mi_idx,
8+
title AS t
9+
WHERE ct.kind = 'production companies' AND
10+
it.info = 'bottom 10 rank' AND
11+
mc.note not like '%(as Metro-Goldwyn-Mayer Pictures)%' AND
12+
t.production_year between 2005 and 2010 AND
13+
ct.id = mc.company_type_id AND
14+
t.id = mc.movie_id AND
15+
t.id = mi_idx.movie_id AND
16+
mc.movie_id = mi_idx.movie_id
17+
AND it.id = mi_idx.info_type_id;

0 commit comments

Comments
 (0)