[Groonga-commit] groonga/groonga [master] support loading vector for integer. #395

Back to archive index

null+****@clear***** null+****@clear*****
2010年 7月 22日 (木) 16:51:20 JST


Kouhei Sutou	2010-07-22 07:51:20 +0000 (Thu, 22 Jul 2010)

  New Revision: d6120e29697b745a69ea7a56cb7e32f0ff56a2a1

  Log:
    support loading vector for integer. #395

  Modified files:
    lib/db.c
    test/unit/core/test-command-select.c

  Modified: lib/db.c (+10 -8)
===================================================================
--- lib/db.c    2010-07-22 02:12:45 +0000 (e101779)
+++ lib/db.c    2010-07-22 07:51:20 +0000 (40b57b9)
@@ -7303,16 +7303,18 @@ set_vector(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *vector)
       grn_id value_size = ((grn_db_obj *)grn_ctx_at(ctx, range_id))->range;
       GRN_VALUE_FIX_SIZE_INIT(&buf, GRN_OBJ_VECTOR, range_id);
       while (n--) {
-        if (v->header.domain == GRN_DB_TEXT) {
-          grn_obj cast_element, *element = v;
-          if (range_id != element->header.domain) {
-            GRN_OBJ_INIT(&cast_element, GRN_BULK, 0, range_id);
-            grn_obj_cast(ctx, element, &cast_element, 1);
-            element = &cast_element;
+        int cast_failed = 0;
+        grn_obj cast_element, *element = v;
+        if (range_id != element->header.domain) {
+          GRN_OBJ_INIT(&cast_element, GRN_BULK, 0, range_id);
+          if (grn_obj_cast(ctx, element, &cast_element, 1)) {
+            cast_failed = 1;
+            ERR(GRN_ERROR, "bad syntax.");
           }
+          element = &cast_element;
+        }
+        if (!cast_failed) {
           grn_bulk_write(ctx, &buf, GRN_TEXT_VALUE(element), value_size);
-        } else {
-          ERR(GRN_ERROR, "bad syntax.");
         }
         v = values_next(ctx, v);
       }

  Modified: test/unit/core/test-command-select.c (+19 -0)
===================================================================
--- test/unit/core/test-command-select.c    2010-07-22 02:12:45 +0000 (771357f)
+++ test/unit/core/test-command-select.c    2010-07-22 07:51:20 +0000 (35f2498)
@@ -27,6 +27,7 @@ void test_output_columns_with_space(void);
 void test_vector_geo_point(void);
 void test_vector_geo_point_with_query(void);
 void test_unmatched_output_columns(void);
+void test_vector_int32(void);
 void test_vector_text(void);
 void test_vector_reference_id(void);
 void test_nonexistent_id(void);
@@ -216,6 +217,24 @@ test_unmatched_output_columns(void)
 }
 
 void
+test_vector_int32(void)
+{
+  assert_send_command("table_create Students TABLE_HASH_KEY ShortText");
+  assert_send_command("column_create Students scores COLUMN_VECTOR Int32");
+
+  cut_assert_equal_string("1",
+                          send_command("load --table Students\n"
+                                       "[{\"_key\": \"Daijiro MORI\", "
+                                         "\"scores\": [5, 5, 5]}]"));
+  cut_assert_equal_string("[[[1],"
+                           "[[\"_id\",\"UInt32\"],"
+                            "[\"_key\",\"ShortText\"],"
+                            "[\"scores\",\"Int32\"]],"
+                           "[1,\"Daijiro MORI\",[5,5,5]]]]",
+                          send_command("select Students"));
+}
+
+void
 test_vector_text(void)
 {
   assert_send_command("table_create Blogs TABLE_HASH_KEY ShortText");




Groonga-commit メーリングリストの案内
Back to archive index