null+****@clear*****
null+****@clear*****
2011年 9月 11日 (日) 18:15:58 JST
Kouhei Sutou 2011-09-11 09:15:58 +0000 (Sun, 11 Sep 2011)
New Revision: 6d982133c3d97bd78646a409abefe2d895ed6976
Log:
[select][query-expansion] support error report for nonexistent query expansion column.
Modified files:
lib/proc.c
test/unit/core/test-command-select-query-expansion.c
Modified: lib/proc.c (+24 -8)
===================================================================
--- lib/proc.c 2011-09-11 09:04:20 +0000 (a4cfd6a)
+++ lib/proc.c 2011-09-11 09:15:58 +0000 (da39669)
@@ -268,16 +268,31 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len,
}
if (query_len) {
grn_expr_flags flags;
- grn_obj query_expand_buf, *query_expand_column, *query_expand_table;
+ grn_obj query_expand_buf;
GRN_TEXT_INIT(&query_expand_buf, 0);
flags = GRN_EXPR_SYNTAX_QUERY|GRN_EXPR_ALLOW_PRAGMA|GRN_EXPR_ALLOW_COLUMN;
- if (query_expand_len &&
- (query_expand_column = grn_ctx_get(ctx, query_expand, query_expand_len)) &&
- (query_expand_table = grn_column_table(ctx, query_expand_column))) {
- expand_query(ctx, query_expand_table, query_expand_column, flags,
- query, query_len, &query_expand_buf);
- query = GRN_TEXT_VALUE(&query_expand_buf);
- query_len = GRN_TEXT_LEN(&query_expand_buf);
+ if (query_expand_len) {
+ grn_obj *query_expand_column;
+ query_expand_column = grn_ctx_get(ctx, query_expand, query_expand_len);
+ if (query_expand_column) {
+ grn_obj *query_expand_table;
+ query_expand_table = grn_column_table(ctx, query_expand_column);
+ if (query_expand_table) {
+ expand_query(ctx, query_expand_table, query_expand_column, flags,
+ query, query_len, &query_expand_buf);
+ query = GRN_TEXT_VALUE(&query_expand_buf);
+ query_len = GRN_TEXT_LEN(&query_expand_buf);
+ grn_obj_unlink(ctx, query_expand_table);
+ }
+ grn_obj_unlink(ctx, query_expand_column);
+ } else {
+ ERR(GRN_INVALID_ARGUMENT,
+ "nonexistent query expansion column: <%.*s>",
+ query_expand_len, query_expand);
+ grn_obj_unlink(ctx, cond);
+ GRN_OBJ_FIN(ctx, &query_expand_buf);
+ goto exit;
+ }
}
grn_expr_parse(ctx, cond, query, query_len,
match_columns_, GRN_OP_MATCH, GRN_OP_AND, flags);
@@ -438,6 +453,7 @@ grn_select(grn_ctx *ctx, const char *table, unsigned table_len,
} else {
ERR(GRN_INVALID_ARGUMENT, "invalid table name: <%.*s>", table_len, table);
}
+exit:
if (match_escalation_threshold_len) {
grn_ctx_set_match_escalation_threshold(ctx, original_threshold);
}
Modified: test/unit/core/test-command-select-query-expansion.c (+13 -0)
===================================================================
--- test/unit/core/test-command-select-query-expansion.c 2011-09-11 09:04:20 +0000 (86fd84f)
+++ test/unit/core/test-command-select-query-expansion.c 2011-09-11 09:15:58 +0000 (964a73a)
@@ -24,6 +24,8 @@
#include "../lib/grn-assertions.h"
void test_expand(void);
+void test_no_expand(void);
+void test_nonexistent_expansion_column(void);
static gchar *tmp_directory;
@@ -130,3 +132,14 @@ test_no_expand(void)
send_command("select Diaries --match_columns content --query rroonga "
"--query_expand Synonyms.words"));
}
+
+void
+test_nonexistent_expansion_column(void)
+{
+ grn_test_assert_send_command_error(
+ context,
+ GRN_INVALID_ARGUMENT,
+ "nonexistent query expansion column: <Synonyms.nonexistent>",
+ "select Diaries --match_columns content --query groonga "
+ "--query_expand Synonyms.nonexistent");
+}