[Groonga-commit] groonga/groonga at 217b444 [master] load: support max UInt64

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Jul 2 00:45:32 JST 2017


Kouhei Sutou	2017-07-02 00:45:32 +0900 (Sun, 02 Jul 2017)

  New Revision: 217b444487342df02e87e61421dd94e1a4611572
  https://github.com/groonga/groonga/commit/217b444487342df02e87e61421dd94e1a4611572

  Message:
    load: support max UInt64
    
    GitHub: fix #722
    
    Reported by Kentaro Hayashi. Thanks!!!

  Added files:
    test/command/suite/load/uint64/max.expected
    test/command/suite/load/uint64/max.test
  Modified files:
    lib/load.c

  Modified: lib/load.c (+18 -12)
===================================================================
--- lib/load.c    2017-07-01 23:22:45 +0900 (3a27d28)
+++ lib/load.c    2017-07-02 00:45:32 +0900 (ee0a1e2)
@@ -841,19 +841,25 @@ json_read(grn_ctx *ctx, grn_loader *loader, const char *str, unsigned int str_le
             loader->last->header.domain = GRN_DB_INT64;
             GRN_INT64_SET(ctx, loader->last, i);
           } else if (cur != str) {
-            double d;
-            char *end;
-            grn_obj buf;
-            GRN_TEXT_INIT(&buf, 0);
-            GRN_TEXT_PUT(ctx, &buf, str, GRN_BULK_VSIZE(loader->last));
-            GRN_TEXT_PUTC(ctx, &buf, '\0');
-            errno = 0;
-            d = strtod(GRN_TEXT_VALUE(&buf), &end);
-            if (!errno && end + 1 == GRN_BULK_CURR(&buf)) {
-              loader->last->header.domain = GRN_DB_FLOAT;
-              GRN_FLOAT_SET(ctx, loader->last, d);
+            uint64_t i = grn_atoull(str, str_end, &cur);
+            if (cur == str_end) {
+              loader->last->header.domain = GRN_DB_UINT64;
+              GRN_UINT64_SET(ctx, loader->last, i);
+            } else if (cur != str) {
+              double d;
+              char *end;
+              grn_obj buf;
+              GRN_TEXT_INIT(&buf, 0);
+              GRN_TEXT_PUT(ctx, &buf, str, GRN_BULK_VSIZE(loader->last));
+              GRN_TEXT_PUTC(ctx, &buf, '\0');
+              errno = 0;
+              d = strtod(GRN_TEXT_VALUE(&buf), &end);
+              if (!errno && end + 1 == GRN_BULK_CURR(&buf)) {
+                loader->last->header.domain = GRN_DB_FLOAT;
+                GRN_FLOAT_SET(ctx, loader->last, d);
+              }
+              GRN_OBJ_FIN(ctx, &buf);
             }
-            GRN_OBJ_FIN(ctx, &buf);
           }
         }
         loader->stat = GRN_BULK_VSIZE(&loader->level) ? GRN_LOADER_TOKEN : GRN_LOADER_END;

  Added: test/command/suite/load/uint64/max.expected (+38 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/load/uint64/max.expected    2017-07-02 00:45:32 +0900 (fdcf2b1)
@@ -0,0 +1,38 @@
+table_create Numbers TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Numbers value COLUMN_SCALAR UInt64
+[[0,0.0,0.0],true]
+load --table Numbers
+[
+{"value": 18446744073709551615}
+]
+[[0,0.0,0.0],1]
+select Numbers
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "value",
+          "UInt64"
+        ]
+      ],
+      [
+        1,
+        18446744073709551615
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/load/uint64/max.test (+9 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/load/uint64/max.test    2017-07-02 00:45:32 +0900 (bc4470b)
@@ -0,0 +1,9 @@
+table_create Numbers TABLE_NO_KEY
+column_create Numbers value COLUMN_SCALAR UInt64
+
+load --table Numbers
+[
+{"value": 18446744073709551615}
+]
+
+select Numbers
-------------- next part --------------
HTML����������������������������...
Download 



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