[Groonga-commit] groonga/groonga at cf754bc [master] Support vector index access

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 19 23:17:52 JST 2013


Kouhei Sutou	2013-04-19 23:17:52 +0900 (Fri, 19 Apr 2013)

  New Revision: cf754bcb34cfd8f9cb1b54b65b56027d4760c9cd
  https://github.com/groonga/groonga/commit/cf754bcb34cfd8f9cb1b54b65b56027d4760c9cd

  Merged 6d30137: Merge pull request #57 from groonga/support-vector-index-access

  Message:
    Support vector index access
    
    We can access N-th vector element by "vector[N]".

  Added files:
    test/command/suite/select/filter/vector/index_access/fixed_size_column.expected
    test/command/suite/select/filter/vector/index_access/fixed_size_column.test
    test/command/suite/select/filter/vector/index_access/reference_column.expected
    test/command/suite/select/filter/vector/index_access/reference_column.test
    test/command/suite/select/filter/vector/index_access/variable_size_column.expected
    test/command/suite/select/filter/vector/index_access/variable_size_column.test
  Modified files:
    include/groonga.h
    lib/ecmascript.c
    lib/ecmascript.y
    lib/expr.c

  Modified: include/groonga.h (+2 -1)
===================================================================
--- include/groonga.h    2013-04-19 22:55:21 +0900 (82e5971)
+++ include/groonga.h    2013-04-19 23:17:52 +0900 (b0fe5f4)
@@ -1218,7 +1218,8 @@ typedef enum {
   GRN_OP_TABLE_SELECT,
   GRN_OP_TABLE_SORT,
   GRN_OP_TABLE_GROUP,
-  GRN_OP_JSON_PUT
+  GRN_OP_JSON_PUT,
+  GRN_OP_GET_MEMBER
 } grn_operator;
 
 struct _grn_table_group_result {

  Modified: lib/ecmascript.c (+28 -22)
===================================================================
--- lib/ecmascript.c    2013-04-19 22:55:21 +0900 (83888d3)
+++ lib/ecmascript.c    2013-04-19 23:17:52 +0900 (9025efa)
@@ -1791,35 +1791,42 @@ static void yy_reduce(
 }
 #line 1793 "ecmascript.c"
         break;
+      case 112: /* member_expression_part ::= BRACKETL expression BRACKETR */
+#line 358 "ecmascript.y"
+{
+  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_GET_MEMBER, 2);
+}
+#line 1800 "ecmascript.c"
+        break;
       case 114: /* arguments ::= PARENL argument_list PARENR */
-#line 361 "ecmascript.y"
+#line 363 "ecmascript.y"
 { yygotominor.yy0 = yymsp[-1].minor.yy0; }
-#line 1798 "ecmascript.c"
+#line 1805 "ecmascript.c"
         break;
       case 115: /* argument_list ::= */
-#line 362 "ecmascript.y"
+#line 364 "ecmascript.y"
 { yygotominor.yy0 = 0; }
-#line 1803 "ecmascript.c"
+#line 1810 "ecmascript.c"
         break;
       case 116: /* argument_list ::= assignment_expression */
-#line 363 "ecmascript.y"
+#line 365 "ecmascript.y"
 { yygotominor.yy0 = 1; }
-#line 1808 "ecmascript.c"
+#line 1815 "ecmascript.c"
         break;
       case 117: /* argument_list ::= argument_list COMMA assignment_expression */
-#line 364 "ecmascript.y"
+#line 366 "ecmascript.y"
 { yygotominor.yy0 = yymsp[-2].minor.yy0 + 1; }
-#line 1813 "ecmascript.c"
+#line 1820 "ecmascript.c"
         break;
       case 118: /* output_columns ::= */
-#line 366 "ecmascript.y"
+#line 368 "ecmascript.y"
 {
   yygotominor.yy0 = 0;
 }
-#line 1820 "ecmascript.c"
+#line 1827 "ecmascript.c"
         break;
       case 119: /* output_columns ::= output_column */
-#line 369 "ecmascript.y"
+#line 371 "ecmascript.y"
 {
   if (yymsp[0].minor.yy0) {
     yygotominor.yy0 = 0;
@@ -1827,10 +1834,10 @@ static void yy_reduce(
     yygotominor.yy0 = 1;
   }
 }
-#line 1831 "ecmascript.c"
+#line 1838 "ecmascript.c"
         break;
       case 120: /* output_columns ::= output_columns COMMA output_column */
-#line 377 "ecmascript.y"
+#line 379 "ecmascript.y"
 {
   if (yymsp[0].minor.yy0) {
     yygotominor.yy0 = yymsp[-2].minor.yy0;
@@ -1841,10 +1848,10 @@ static void yy_reduce(
     yygotominor.yy0 = 1;
   }
 }
-#line 1845 "ecmascript.c"
+#line 1852 "ecmascript.c"
         break;
       case 121: /* output_column ::= STAR */
-#line 388 "ecmascript.y"
+#line 390 "ecmascript.y"
 {
   grn_ctx *ctx = efsi->ctx;
   grn_obj *expr = efsi->e;
@@ -1882,21 +1889,21 @@ static void yy_reduce(
     yygotominor.yy0 = GRN_TRUE;
   }
 }
-#line 1886 "ecmascript.c"
+#line 1893 "ecmascript.c"
         break;
       case 122: /* output_column ::= NONEXISTENT_COLUMN */
-#line 425 "ecmascript.y"
+#line 427 "ecmascript.y"
 {
   yygotominor.yy0 = GRN_TRUE;
 }
-#line 1893 "ecmascript.c"
+#line 1900 "ecmascript.c"
         break;
       case 123: /* output_column ::= assignment_expression */
-#line 428 "ecmascript.y"
+#line 430 "ecmascript.y"
 {
   yygotominor.yy0 = GRN_FALSE;
 }
-#line 1900 "ecmascript.c"
+#line 1907 "ecmascript.c"
         break;
       default:
       /* (0) input ::= query */ yytestcase(yyruleno==0);
@@ -1946,7 +1953,6 @@ static void yy_reduce(
       /* (109) property_name_and_value_list ::= property_name_and_value_list COMMA property_name_and_value */ yytestcase(yyruleno==109);
       /* (110) property_name_and_value ::= property_name COLON assignment_expression */ yytestcase(yyruleno==110);
       /* (111) property_name ::= IDENTIFIER|STRING|DECIMAL */ yytestcase(yyruleno==111);
-      /* (112) member_expression_part ::= BRACKETL expression BRACKETR */ yytestcase(yyruleno==112);
       /* (113) member_expression_part ::= DOT IDENTIFIER */ yytestcase(yyruleno==113);
         break;
   };
@@ -2020,7 +2026,7 @@ static void yy_syntax_error(
       GRN_OBJ_FIN(ctx, &buf);
     }
   }
-#line 2024 "ecmascript.c"
+#line 2030 "ecmascript.c"
   grn_expr_parserARG_STORE; /* Suppress warning about unused %extra_argument variable */
 }
 

  Modified: lib/ecmascript.y (+3 -1)
===================================================================
--- lib/ecmascript.y    2013-04-19 22:55:21 +0900 (16a8f0d)
+++ lib/ecmascript.y    2013-04-19 23:17:52 +0900 (1dc3cb6)
@@ -355,7 +355,9 @@ property_name_and_value_list ::= property_name_and_value_list COMMA property_nam
 property_name_and_value ::= property_name COLON assignment_expression.
 property_name ::= IDENTIFIER|STRING|DECIMAL.
 
-member_expression_part ::= BRACKETL expression BRACKETR.
+member_expression_part ::= BRACKETL expression BRACKETR. {
+  grn_expr_append_op(efsi->ctx, efsi->e, GRN_OP_GET_MEMBER, 2);
+}
 member_expression_part ::= DOT IDENTIFIER.
 
 arguments(A) ::= PARENL argument_list(B) PARENR. { A = B; }

  Modified: lib/expr.c (+63 -0)
===================================================================
--- lib/expr.c    2013-04-19 22:55:21 +0900 (1bbd565)
+++ lib/expr.c    2013-04-19 23:17:52 +0900 (3a9476a)
@@ -1208,6 +1208,21 @@ grn_expr_append_obj(grn_ctx *ctx, grn_obj *expr, grn_obj *obj, grn_operator op,
     case GRN_OP_COMMA :
       PUSH_CODE(e, op, obj, nargs, code);
       break;
+    case GRN_OP_GET_MEMBER :
+      DFI_POP(e, dfi);
+      DFI_POP(e, dfi);
+      if (dfi) {
+        type = dfi->type;
+        domain = dfi->domain;
+        if (dfi->code) {
+          if (dfi->code->op == GRN_OP_GET_VALUE) {
+            dfi->code->op = GRN_OP_GET_REF;
+          }
+        }
+      }
+      PUSH_CODE(e, op, obj, nargs, code);
+      DFI_PUT(e, type, domain, code);
+      break;
     default :
       break;
     }
@@ -2491,6 +2506,46 @@ pseudo_query_scan(grn_ctx *ctx, grn_obj *x, grn_obj *y, grn_obj *res)
   if (normalizer) { grn_obj_unlink(ctx, normalizer); }
 }
 
+inline static void
+grn_expr_exec_get_member(grn_ctx *ctx,
+                         grn_obj *expr,
+                         grn_obj *column_and_record_id,
+                         grn_obj *index,
+                         grn_obj *result)
+{
+  grn_obj *column;
+  grn_id record_id;
+  grn_obj values;
+  int i;
+
+  column = GRN_PTR_VALUE(column_and_record_id);
+  record_id = *((grn_id *)(&(GRN_PTR_VALUE_AT(column_and_record_id, 1))));
+  GRN_TEXT_INIT(&values, 0);
+  grn_obj_get_value(ctx, column, record_id, &values);
+
+  grn_obj_reinit(ctx, result, DB_OBJ(column)->range, 0);
+  i = GRN_UINT32_VALUE(index);
+  if (values.header.type == GRN_UVECTOR) {
+    int n_elements;
+    n_elements = GRN_BULK_VSIZE(&values) / sizeof(grn_id);
+    if (n_elements > i) {
+      grn_id value;
+      value = GRN_RECORD_VALUE_AT(&values, i);
+      GRN_RECORD_SET(ctx, result, value);
+    }
+  } else {
+    if (values.u.v.n_sections > i) {
+      grn_section *section = &(values.u.v.sections[i]);
+      grn_obj *body = values.u.v.body;
+      const char *value;
+      value = GRN_BULK_HEAD(body) + section->offset;
+      grn_bulk_write(ctx, result, value, section->length);
+    }
+  }
+
+  GRN_OBJ_FIN(ctx, &values);
+}
+
 grn_obj *
 grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
 {
@@ -3635,6 +3690,14 @@ grn_expr_exec(grn_ctx *ctx, grn_obj *expr, int nargs)
         }
         code++;
         break;
+      case GRN_OP_GET_MEMBER :
+        {
+          grn_obj *column_and_record_id, *index;
+          POP2ALLOC1(column_and_record_id, index, res);
+          grn_expr_exec_get_member(ctx, expr, column_and_record_id, index, res);
+          code++;
+        }
+        break;
       default :
         ERR(GRN_FUNCTION_NOT_IMPLEMENTED, "not implemented operator assigned");
         goto exit;

  Added: test/command/suite/select/filter/vector/index_access/fixed_size_column.expected (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/index_access/fixed_size_column.expected    2013-04-19 23:17:52 +0900 (7afc29f)
@@ -0,0 +1,49 @@
+table_create Sites TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Sites priorities COLUMN_VECTOR UInt32
+[[0,0.0,0.0],true]
+load --table Sites
+[
+["_key", "priorities"],
+["groonga.org", [9]],
+["mroonga.org", [2, 9]],
+["ranguba.org", [29, 2, 9]]
+]
+[[0,0.0,0.0],3]
+select Sites --filter 'priorities[1] == 9'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "priorities",
+          "UInt32"
+        ]
+      ],
+      [
+        2,
+        "mroonga.org",
+        [
+          2,
+          9
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/vector/index_access/fixed_size_column.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/index_access/fixed_size_column.test    2013-04-19 23:17:52 +0900 (dbdec85)
@@ -0,0 +1,12 @@
+table_create Sites TABLE_PAT_KEY ShortText
+column_create Sites priorities COLUMN_VECTOR UInt32
+
+load --table Sites
+[
+["_key", "priorities"],
+["groonga.org", [9]],
+["mroonga.org", [2, 9]],
+["ranguba.org", [29, 2, 9]]
+]
+
+select Sites --filter 'priorities[1] == 9'

  Added: test/command/suite/select/filter/vector/index_access/reference_column.expected (+51 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/index_access/reference_column.expected    2013-04-19 23:17:52 +0900 (49813c1)
@@ -0,0 +1,51 @@
+table_create Tags TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Sites TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Sites tags COLUMN_VECTOR Tags
+[[0,0.0,0.0],true]
+load --table Sites
+[
+["_key", "tags"],
+["groonga.org", ["search engine"]],
+["mroonga.org", ["MySQL", "groonga"]],
+["ranguba.org", ["groonga", "Ruby", "search system"]]
+]
+[[0,0.0,0.0],3]
+select Sites --filter 'tags[1] == "groonga"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "tags",
+          "Tags"
+        ]
+      ],
+      [
+        2,
+        "mroonga.org",
+        [
+          "MySQL",
+          "groonga"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/vector/index_access/reference_column.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/index_access/reference_column.test    2013-04-19 23:17:52 +0900 (420a683)
@@ -0,0 +1,14 @@
+table_create Tags TABLE_HASH_KEY ShortText
+
+table_create Sites TABLE_PAT_KEY ShortText
+column_create Sites tags COLUMN_VECTOR Tags
+
+load --table Sites
+[
+["_key", "tags"],
+["groonga.org", ["search engine"]],
+["mroonga.org", ["MySQL", "groonga"]],
+["ranguba.org", ["groonga", "Ruby", "search system"]]
+]
+
+select Sites --filter 'tags[1] == "groonga"'

  Added: test/command/suite/select/filter/vector/index_access/variable_size_column.expected (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/index_access/variable_size_column.expected    2013-04-19 23:17:52 +0900 (18d2109)
@@ -0,0 +1,49 @@
+table_create Sites TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Sites tags COLUMN_VECTOR ShortText
+[[0,0.0,0.0],true]
+load --table Sites
+[
+["_key", "tags"],
+["groonga.org", ["search engine"]],
+["mroonga.org", ["MySQL", "groonga"]],
+["ranguba.org", ["groonga", "Ruby", "search system"]]
+]
+[[0,0.0,0.0],3]
+select Sites --filter 'tags[1] == "groonga"'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "tags",
+          "ShortText"
+        ]
+      ],
+      [
+        2,
+        "mroonga.org",
+        [
+          "MySQL",
+          "groonga"
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/filter/vector/index_access/variable_size_column.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/vector/index_access/variable_size_column.test    2013-04-19 23:17:52 +0900 (8772baa)
@@ -0,0 +1,12 @@
+table_create Sites TABLE_PAT_KEY ShortText
+column_create Sites tags COLUMN_VECTOR ShortText
+
+load --table Sites
+[
+["_key", "tags"],
+["groonga.org", ["search engine"]],
+["mroonga.org", ["MySQL", "groonga"]],
+["ranguba.org", ["groonga", "Ruby", "search system"]]
+]
+
+select Sites --filter 'tags[1] == "groonga"'
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index