Navigation Menu

Skip to content

Commit

Permalink
query-log show-condition: (maybe) fix a crash bug
Browse files Browse the repository at this point in the history
We need to check scan_info that doesn't have corresponding expr_code.
  • Loading branch information
kou committed Jun 22, 2018
1 parent e42f41f commit 0a4561f
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/expr.c
Expand Up @@ -4762,10 +4762,16 @@ grn_table_select_inspect_condition(grn_ctx *ctx,
if (i > si->start) {
GRN_TEXT_PUTC(ctx, buffer, ' ');
}
if (code->value) {
grn_table_select_inspect_condition_argument(ctx, buffer, code->value);
if (i < expr->codes_curr) {
if (code->value) {
grn_table_select_inspect_condition_argument(ctx, buffer, code->value);
} else {
GRN_TEXT_PUTS(ctx, buffer, grn_operator_to_string(code->op));
}
} else {
GRN_TEXT_PUTS(ctx, buffer, grn_operator_to_string(code->op));
GRN_TEXT_PUTS(ctx, buffer, grn_operator_to_string(si->op));
GRN_TEXT_PUTS(ctx, buffer, ": ");
GRN_TEXT_PUTS(ctx, buffer, grn_operator_to_string(si->logical_op));
}
}
break;
Expand Down
91 changes: 91 additions & 0 deletions test/command/suite/select/function/sub_filter/and_or.expected
@@ -0,0 +1,91 @@
table_create Files TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
column_create Files revision COLUMN_SCALAR UInt32
[[0,0.0,0.0],true]
table_create Packages TABLE_PAT_KEY ShortText
[[0,0.0,0.0],true]
column_create Packages files COLUMN_VECTOR Files
[[0,0.0,0.0],true]
column_create Files packages_files_index COLUMN_INDEX Packages files
[[0,0.0,0.0],true]
table_create Revisions TABLE_PAT_KEY UInt32
[[0,0.0,0.0],true]
column_create Revisions files_revision_index COLUMN_INDEX Files revision
[[0,0.0,0.0],true]
table_create Names TABLE_PAT_KEY ShortText --default_tokenizer TokenBigramSplitSymbolAlpha
[[0,0.0,0.0],true]
column_create Names packages_key_index COLUMN_INDEX|WITH_POSITION Packages _key
[[0,0.0,0.0],true]
load --table Files
[
{"_key": "include/groonga.h", "revision": 100},
{"_key": "src/groonga.c", "revision": 29},
{"_key": "lib/groonga.rb", "revision": 12},
{"_key": "README.textile", "revision": 24},
{"_key": "ha_mroonga.cc", "revision": 40},
{"_key": "ha_mroonga.hpp", "revision": 6}
]
[[0,0.0,0.0],6]
load --table Packages
[
{"_key": "groonga", "files": ["include/groonga.h", "src/groonga.c"]},
{"_key": "rroonga", "files": ["lib/groonga.rb", "README.textile"]},
{"_key": "mroonga", "files": ["ha_mroonga.cc", "ha_mroonga.hpp"]}
]
[[0,0.0,0.0],3]
select Packages --filter 'sub_filter(files, "revision >= 10 && (_key @^ \\\"ha\\\" || _key @^ \\\"include/\\\")") && (_key == "groonga" || _key == "rroonga")' --output_columns '_key, _score, files, files.revision'
[
[
0,
0.0,
0.0
],
[
[
[
1
],
[
[
"_key",
"ShortText"
],
[
"_score",
"Int32"
],
[
"files",
"Files"
],
[
"files.revision",
"UInt32"
]
],
[
"groonga",
3,
[
"include/groonga.h",
"src/groonga.c"
],
[
100,
29
]
]
]
]
]
#>select --filter "sub_filter(files, \"revision >= 10 && (_key @^ \\\"ha\\\" || _key @^ \\\"include/\\\")\") && (_key == \"groonga\" || _key == \"rroonga\")" --output_columns "_key, _score, files, files.revision" --table "Packages"
#:000000000000000 filter(1): #<accessor _key(Packages)> equal "groonga"
#:000000000000000 filter(2): #<accessor _key(Packages)> equal "rroonga"
#:000000000000000 filter(0): #<accessor _key(Files)> "ha" prefix
#:000000000000000 filter(1): #<accessor _key(Files)> "include/" prefix
#:000000000000000 filter(1): Files.revision greater_equal 10
#:000000000000000 filter(1): nop: and
#:000000000000000 filter(1): sub_filter(Packages.files, "revision >= 10 && (_key @^ \"ha\" || _key @^ \"include/\")")
#:000000000000000 select(1)
#:000000000000000 output(1)
#<000000000000000 rc=0
41 changes: 41 additions & 0 deletions test/command/suite/select/function/sub_filter/and_or.test
@@ -0,0 +1,41 @@
table_create Files TABLE_PAT_KEY ShortText
column_create Files revision COLUMN_SCALAR UInt32

table_create Packages TABLE_PAT_KEY ShortText
column_create Packages files COLUMN_VECTOR Files

column_create Files packages_files_index COLUMN_INDEX Packages files

table_create Revisions TABLE_PAT_KEY UInt32
column_create Revisions files_revision_index COLUMN_INDEX Files revision

table_create Names TABLE_PAT_KEY ShortText \
--default_tokenizer TokenBigramSplitSymbolAlpha
column_create Names packages_key_index COLUMN_INDEX|WITH_POSITION Packages _key

load --table Files
[
{"_key": "include/groonga.h", "revision": 100},
{"_key": "src/groonga.c", "revision": 29},
{"_key": "lib/groonga.rb", "revision": 12},
{"_key": "README.textile", "revision": 24},
{"_key": "ha_mroonga.cc", "revision": 40},
{"_key": "ha_mroonga.hpp", "revision": 6}
]

load --table Packages
[
{"_key": "groonga", "files": ["include/groonga.h", "src/groonga.c"]},
{"_key": "rroonga", "files": ["lib/groonga.rb", "README.textile"]},
{"_key": "mroonga", "files": ["ha_mroonga.cc", "ha_mroonga.hpp"]}
]

#$GRN_QUERY_LOG_SHOW_CONDITION=yes
#@collect-query-log true
select Packages \
--filter 'sub_filter(files, \
"revision >= 10 && \
(_key @^ \\\"ha\\\" || _key @^ \\\"include/\\\")") && \
(_key == "groonga" || _key == "rroonga")' \
--output_columns '_key, _score, files, files.revision'
#@collect-query-log false

0 comments on commit 0a4561f

Please sign in to comment.