Navigation Menu

Skip to content

Commit

Permalink
NO_SYNTAX_ERROR: support queries with empty or only-and blocks
Browse files Browse the repository at this point in the history
Ref: #767
  • Loading branch information
s-yata committed Oct 18, 2017
1 parent 587e1b2 commit 5fa6f75
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
38 changes: 29 additions & 9 deletions lib/expr.c
Expand Up @@ -7458,18 +7458,35 @@ parse_query(grn_ctx *ctx, efs_info *q)
if (q->cur >= q->str_end) { goto exit; }
if (*q->cur == '\0') { goto exit; }

only_first_and = GRN_FALSE;
switch (*q->cur) {
case GRN_QUERY_PARENR :
if (q->paren_depth == 0 && q->flags & GRN_EXPR_QUERY_NO_SYNTAX_ERROR) {
const char parenr = GRN_QUERY_PARENR;
parse_query_flush_pending_token(ctx, q);
parse_query_accept_string(ctx, q, &parenr, 1);
} else {
parse_query_flush_pending_token(ctx, q);
PARSE(GRN_EXPR_TOKEN_PARENR);
q->paren_depth--;
if (q->flags & GRN_EXPR_QUERY_NO_SYNTAX_ERROR) {
if (q->paren_depth == 0) {
const char parenr = GRN_QUERY_PARENR;
parse_query_flush_pending_token(ctx, q);
parse_query_accept_string(ctx, q, &parenr, 1);
q->cur++;
break;
}
if (first_token) {
const char parenl = GRN_QUERY_PARENL;
const char parenr = GRN_QUERY_PARENR;
parse_query_flush_pending_token(ctx, q);
parse_query_accept_string(ctx, q, &parenl, 1);
parse_query_accept_string(ctx, q, &parenr, 1);
}
if (only_first_and) {
const char query_and[] = {GRN_QUERY_AND};
parse_query_flush_pending_token(ctx, q);
parse_query_accept_string(ctx,
q,
query_and,
1);
}
}
parse_query_flush_pending_token(ctx, q);
PARSE(GRN_EXPR_TOKEN_PARENR);
q->paren_depth--;
q->cur++;
break;
case GRN_QUERY_QUOTEL :
Expand Down Expand Up @@ -7634,6 +7651,9 @@ parse_query(grn_ctx *ctx, efs_info *q)
parse_query_word(ctx, q);
break;
}
if (!first_token) {
only_first_and = GRN_FALSE;
}
first_token = block_started;
block_started = GRN_FALSE;
}
Expand Down
@@ -0,0 +1,14 @@
table_create Names TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
table_create Tokens TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
[[0,0.0,0.0],true]
column_create Tokens names_key COLUMN_INDEX|WITH_POSITION Names _key
[[0,0.0,0.0],true]
load --table Names
[
{"_key": "name (x+y)"},
{"_key": "name (x y)"}
]
[[0,0.0,0.0],2]
select Names --match_columns "_key" --query "(+)" --query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR
[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","ShortText"]],[1,"name (x+y)"]]]]
@@ -0,0 +1,17 @@
table_create Names TABLE_PAT_KEY ShortText

table_create Tokens TABLE_PAT_KEY ShortText \
--default_tokenizer TokenBigram \
--normalizer NormalizerAuto
column_create Tokens names_key COLUMN_INDEX|WITH_POSITION Names _key

load --table Names
[
{"_key": "name (x+y)"},
{"_key": "name (x y)"}
]

select Names \
--match_columns "_key" \
--query "(+)" \
--query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR
@@ -0,0 +1,16 @@
table_create Names TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
table_create Tokens TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
[[0,0.0,0.0],true]
column_create Tokens names_key COLUMN_INDEX|WITH_POSITION Names _key
[[0,0.0,0.0],true]
load --table Names
[
{"_key": "name (x y)"},
{"_key": "name (x y "},
{"_key": "name x y)"},
{"_key": "name x y "}
]
[[0,0.0,0.0],4]
select Names --match_columns "_key" --query "( )" --query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR
[[0,0.0,0.0],[[[1],[["_id","UInt32"],["_key","ShortText"]],[1,"name (x y)"]]]]
@@ -0,0 +1,19 @@
table_create Names TABLE_PAT_KEY ShortText

table_create Tokens TABLE_PAT_KEY ShortText \
--default_tokenizer TokenBigram \
--normalizer NormalizerAuto
column_create Tokens names_key COLUMN_INDEX|WITH_POSITION Names _key

load --table Names
[
{"_key": "name (x y)"},
{"_key": "name (x y "},
{"_key": "name x y)"},
{"_key": "name x y "}
]

select Names \
--match_columns "_key" \
--query "( )" \
--query_flags ALLOW_PRAGMA|ALLOW_COLUMN|QUERY_NO_SYNTAX_ERROR

0 comments on commit 5fa6f75

Please sign in to comment.