null+****@clear*****
null+****@clear*****
2010年 11月 4日 (木) 21:41:08 JST
Kouhei Sutou 2010-11-04 12:41:08 +0000 (Thu, 04 Nov 2010)
New Revision: 472bb76b2d80b565fecae5af8742ed61b8f68e82
Log:
do equal Int8/UInt8/Int16/UInt16 explicitly. #660
Modified files:
lib/expr.c
test/unit/core/test-command-select.c
Modified: lib/expr.c (+36 -0)
===================================================================
--- lib/expr.c 2010-11-07 03:21:22 +0000 (c5e1c77)
+++ lib/expr.c 2010-11-04 12:41:08 +0000 (9824f18)
@@ -1437,6 +1437,18 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
#define DO_EQ_SUB {\
switch (y->header.domain) {\
+ case GRN_DB_INT8 :\
+ r = (x_ == GRN_INT8_VALUE(y));\
+ break;\
+ case GRN_DB_UINT8 :\
+ r = (x_ == GRN_UINT8_VALUE(y));\
+ break;\
+ case GRN_DB_INT16 :\
+ r = (x_ == GRN_INT16_VALUE(y));\
+ break;\
+ case GRN_DB_UINT16 :\
+ r = (x_ == GRN_UINT16_VALUE(y));\
+ break;\
case GRN_DB_INT32 :\
r = (x_ == GRN_INT32_VALUE(y));\
break;\
@@ -1475,6 +1487,30 @@ grn_expr_compile(grn_ctx *ctx, grn_obj *expr)
case GRN_DB_VOID :\
r = 0;\
break;\
+ case GRN_DB_INT8 :\
+ {\
+ int8_t x_ = GRN_INT8_VALUE(x);\
+ DO_EQ_SUB;\
+ }\
+ break;\
+ case GRN_DB_UINT8 :\
+ {\
+ uint8_t x_ = GRN_UINT8_VALUE(x);\
+ DO_EQ_SUB;\
+ }\
+ break;\
+ case GRN_DB_INT16 :\
+ {\
+ int16_t x_ = GRN_INT16_VALUE(x);\
+ DO_EQ_SUB;\
+ }\
+ break;\
+ case GRN_DB_UINT16 :\
+ {\
+ uint16_t x_ = GRN_UINT16_VALUE(x);\
+ DO_EQ_SUB;\
+ }\
+ break;\
case GRN_DB_INT32 :\
{\
int32_t x_ = GRN_INT32_VALUE(x);\
Modified: test/unit/core/test-command-select.c (+53 -0)
===================================================================
--- test/unit/core/test-command-select.c 2010-11-07 03:21:22 +0000 (8e20a27)
+++ test/unit/core/test-command-select.c 2010-11-04 12:41:08 +0000 (652dd8e)
@@ -43,6 +43,8 @@ void data_less_than(void);
void test_less_than(gconstpointer data);
void data_less_than_or_equal(void);
void test_less_than_or_equal(gconstpointer data);
+void data_equal_numeric(void);
+void test_equal_numeric(gconstpointer data);
static gchar *tmp_directory;
@@ -608,3 +610,54 @@ test_less_than_or_equal(gconstpointer data)
"--output_columns _key,score "
"--filter 'score >= 4'"));
}
+
+void
+data_equal_numeric(void)
+{
+#define ADD_DATA(type) \
+ gcut_add_datum(type, \
+ "type", G_TYPE_STRING, type, \
+ NULL)
+
+ ADD_DATA("Int8");
+ ADD_DATA("UInt8");
+ ADD_DATA("Int16");
+ ADD_DATA("UInt16");
+ ADD_DATA("Int32");
+ ADD_DATA("UInt32");
+ ADD_DATA("Int64");
+ ADD_DATA("UInt64");
+
+#undef ADD_DATA
+}
+
+void
+test_equal_numeric(gconstpointer data)
+{
+ const gchar *type;
+
+ type = gcut_data_get_string(data, "type");
+
+ assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
+ assert_send_command(
+ cut_take_printf("column_create Sites score COLUMN_SCALAR %s", type));
+
+ cut_assert_equal_string(
+ "3",
+ send_command("load --table Sites --columns '_key, score' \n"
+ "[\n"
+ " [\"groonga.org\", 5],\n"
+ " [\"ruby-lang.org\", 4],\n"
+ " [\"qwik.jp/senna/\", 3]\n"
+ "]"));
+ cut_assert_equal_string(
+ cut_take_printf("[[[1],"
+ "[[\"_key\",\"ShortText\"],"
+ "[\"score\",\"%s\"]],"
+ "[\"ruby-lang.org\",4]]]",
+ type),
+ send_command("select Sites "
+ "--sortby -score "
+ "--output_columns _key,score "
+ "--filter 'score == 4'"));
+}