[Groonga-commit] groonga/groonga [master] support loading vector for reference ID of no-key-table. #396

Back to archive index

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


Kouhei Sutou	2010-07-22 07:24:04 +0000 (Thu, 22 Jul 2010)

  New Revision: 3b6a33035d7c80712d7aa66a17e411725f37ee09

  Log:
    support loading vector for reference ID of no-key-table. #396

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

  Modified: lib/db.c (+18 -7)
===================================================================
--- lib/db.c    2010-07-22 02:08:57 +0000 (ddb5819)
+++ lib/db.c    2010-07-22 07:24:04 +0000 (e101779)
@@ -3652,8 +3652,15 @@ grn_obj_is_persistent(grn_ctx *ctx, grn_obj *obj)
     totext(ctx, dest, getvalue(src));\
     break;\
   default :\
-    rc = GRN_FUNCTION_NOT_IMPLEMENTED;\
-    break;\
+    {\
+      grn_obj *domain = grn_ctx_at(ctx, dest->header.domain);\
+      if (domain && domain->header.type == GRN_TABLE_NO_KEY) {\
+        GRN_RECORD_SET(ctx, dest, getvalue(src));\
+      } else {\
+        rc = GRN_FUNCTION_NOT_IMPLEMENTED;\
+      }\
+      break;\
+    }\
   }
 
 #define TEXT2DEST(type,tonum,setvalue) {\
@@ -7257,14 +7264,18 @@ set_vector(grn_ctx *ctx, grn_obj *column, grn_id id, grn_obj *vector)
   if (GRN_OBJ_TABLEP(range)) {
     GRN_RECORD_INIT(&buf, GRN_OBJ_VECTOR, range_id);
     while (n--) {
-      if (v->header.domain == GRN_DB_TEXT) {
-        grn_obj record, *element = v;
+      int cast_failed = 0;
+      grn_obj record, *element = v;
+      if (range_id != element->header.domain) {
         GRN_RECORD_INIT(&record, 0, range_id);
-        grn_obj_cast(ctx, element, &record, 1);
+        if (grn_obj_cast(ctx, element, &record, 1)) {
+          cast_failed = 1;
+          ERR(GRN_ERROR, "bad syntax.");
+        }
         element = &record;
+      }
+      if (!cast_failed) {
         GRN_UINT32_PUT(ctx, &buf, GRN_RECORD_VALUE(element));
-      } else {
-        ERR(GRN_ERROR, "bad syntax.");
       }
       v = values_next(ctx, v);
     }

  Modified: lib/output.c (+5 -1)
===================================================================
--- lib/output.c    2010-07-22 02:08:57 +0000 (aaab31d)
+++ lib/output.c    2010-07-22 07:24:04 +0000 (b7168b5)
@@ -818,7 +818,11 @@ grn_output_obj(grn_ctx *ctx, grn_obj *outbuf, grn_content_type output_type,
               grn_output_obj(ctx, outbuf, output_type, &key, NULL);
               GRN_BULK_REWIND(&key);
             } else {
-              grn_text_lltoa(ctx, outbuf, *v);
+              grn_obj id;
+              GRN_UINT32_INIT(&id, 0);
+              GRN_UINT32_SET(ctx, &id, *v);
+              grn_output_obj(ctx, outbuf, output_type, &id, NULL);
+              GRN_OBJ_FIN(ctx, &id);
             }
             v++;
             if (v < ve) {

  Modified: test/unit/core/test-command-select.c (+32 -0)
===================================================================
--- test/unit/core/test-command-select.c    2010-07-22 02:08:57 +0000 (7e4b582)
+++ test/unit/core/test-command-select.c    2010-07-22 07:24:04 +0000 (771357f)
@@ -28,6 +28,7 @@ void test_vector_geo_point(void);
 void test_vector_geo_point_with_query(void);
 void test_unmatched_output_columns(void);
 void test_vector_text(void);
+void test_vector_reference_id(void);
 void test_nonexistent_id(void);
 void test_bigram_split_symbol_tokenizer(void);
 void test_nonexistent_table(void);
@@ -255,6 +256,37 @@ test_vector_text(void)
 }
 
 void
+test_vector_reference_id(void)
+{
+  assert_send_command("table_create Users TABLE_NO_KEY");
+  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
+  assert_send_command("table_create Comments TABLE_PAT_KEY ShortText");
+  assert_send_command("column_create Comments text COLUMN_SCALAR ShortText");
+  assert_send_command("column_create Comments authors COLUMN_VECTOR Users");
+
+  cut_assert_equal_string("2",
+                          send_command("load --table Users\n"
+                                       "[\n"
+                                       " [\"_id\", \"name\"],\n"
+                                       " [1, \"ryoqun\"],\n"
+                                       " [2, \"hayamiz\"]\n"
+                                       "]"));
+  cut_assert_equal_string("1",
+                          send_command("load --table Comments\n"
+                                       "[\n"
+                                       " [\"_key\", \"text\", \"authors\"],\n"
+                                       " [\"groonga\", \"it is fast\", [1, 2]]\n"
+                                       "]"));
+  cut_assert_equal_string("[[[1],"
+                           "[[\"_id\",\"UInt32\"],"
+                            "[\"_key\",\"ShortText\"],"
+                            "[\"text\",\"ShortText\"],"
+                            "[\"authors\",\"Users\"]],"
+                           "[1,\"groonga\",\"it is fast\",[1,2]]]]",
+                          send_command("select Comments"));
+}
+
+void
 test_nonexistent_id(void)
 {
   assert_send_commands("table_create Sites TABLE_PAT_KEY ShortText\n"




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