[Groonga-commit] groonga/groonga at 4caedfe [master] cast_loose: add

Back to archive index
Yasuhiro Horimoto null+****@clear*****
Thu Oct 11 12:45:31 JST 2018


Yasuhiro Horimoto	2018-10-11 12:45:31 +0900 (Thu, 11 Oct 2018)

  Revision: 4caedfe919178a8f161d93870587f54b78c59587
  https://github.com/groonga/groonga/commit/4caedfe919178a8f161d93870587f54b78c59587

  Merged 9539921: Merge pull request #876 from komainu8/add_cast_loose

  Message:
    cast_loose: add

  Added files:
    lib/proc/proc_cast.c
  Modified files:
    lib/grn_proc.h
    lib/proc.c
    lib/proc/sources.am
    test/command/suite/select/function/cast_loose/number_only.expected

  Modified: lib/grn_proc.h (+1 -0)
===================================================================
--- lib/grn_proc.h    2018-10-11 09:57:15 +0900 (dfa4a6956)
+++ lib/grn_proc.h    2018-10-11 12:45:31 +0900 (fdb010069)
@@ -36,6 +36,7 @@ void grn_proc_init_from_env(void);
 GRN_VAR const char *grn_document_root;
 void grn_db_init_builtin_commands(grn_ctx *ctx);
 
+void grn_proc_init_cast_loose(grn_ctx *ctx);
 void grn_proc_init_clearlock(grn_ctx *ctx);
 void grn_proc_init_column_copy(grn_ctx *ctx);
 void grn_proc_init_column_create(grn_ctx *ctx);

  Modified: lib/proc.c (+2 -0)
===================================================================
--- lib/proc.c    2018-10-11 09:57:15 +0900 (4f5b29a18)
+++ lib/proc.c    2018-10-11 12:45:31 +0900 (5192fb9bc)
@@ -4339,4 +4339,6 @@ grn_db_init_builtin_commands(grn_ctx *ctx)
   grn_proc_init_query_log_flags_set(ctx);
   grn_proc_init_query_log_flags_add(ctx);
   grn_proc_init_query_log_flags_remove(ctx);
+
+  grn_proc_init_cast_loose(ctx);
 }

  Added: lib/proc/proc_cast.c (+48 -0) 100644
===================================================================
--- /dev/null
+++ lib/proc/proc_cast.c    2018-10-11 12:45:31 +0900 (ca1443e0b)
@@ -0,0 +1,48 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2018 Horimoto Yasuhiro <horim****@clear*****>
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "../grn_proc.h"
+#include "../grn_expr.h"
+
+#include <groonga/plugin.h>
+
+static grn_obj *
+func_cast_loose(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
+{
+  grn_obj *casted_value = NULL;
+
+  if (nargs == 3) {
+    grn_obj *cast_type = args[0];
+    grn_obj *cast_value = args[1];
+    grn_obj *default_value = args[2];
+
+    casted_value =
+      grn_plugin_proc_alloc(ctx, user_data, grn_obj_id(ctx, cast_type), 0);
+
+    grn_obj_cast(ctx, cast_value, casted_value, GRN_FALSE);
+  }
+
+  return casted_value;
+}
+
+void
+grn_proc_init_cast_loose(grn_ctx *ctx)
+{
+  grn_proc_create(ctx, "cast_loose", -1, GRN_PROC_FUNCTION,
+                  func_cast_loose, NULL, NULL, 0, NULL);
+}

  Modified: lib/proc/sources.am (+1 -0)
===================================================================
--- lib/proc/sources.am    2018-10-11 09:57:15 +0900 (3ca24ee9f)
+++ lib/proc/sources.am    2018-10-11 12:45:31 +0900 (aa4782dce)
@@ -1,4 +1,5 @@
 libgrnproc_la_SOURCES =				\
+	proc_cast.c				\
 	proc_column.c				\
 	proc_config.c				\
 	proc_dump.c				\

  Modified: test/command/suite/select/function/cast_loose/number_only.expected (+1 -28)
===================================================================
--- test/command/suite/select/function/cast_loose/number_only.expected    2018-10-11 09:57:15 +0900 (04d22492e)
+++ test/command/suite/select/function/cast_loose/number_only.expected    2018-10-11 12:45:31 +0900 (3cb5a2c54)
@@ -6,31 +6,4 @@ load --table Data
 ]
 [[0,0.0,0.0],1]
 select Data   --output_columns '_key, cast_loose(Int64, _key, 10)'
-[
-  [
-    0,
-    0.0,
-    0.0
-  ],
-  [
-    [
-      [
-        1
-      ],
-      [
-        [
-          "_key",
-          "ShortText"
-        ],
-        [
-          "cast_loose",
-          null
-        ]
-      ],
-      [
-        "100",
-        100
-      ]
-    ]
-  ]
-]
+[[0,0.0,0.0],[[[1],[["_key","ShortText"],["cast_loose",null]],["100",100]]]]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181011/20f32b5f/attachment-0001.html>


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