[Groonga-commit] droonga/droonga-engine at 3f05c88 [master] select: support Time type

Back to archive index

Kouhei Sutou null+****@clear*****
Tue May 27 18:13:18 JST 2014


Kouhei Sutou	2014-05-27 18:13:18 +0900 (Tue, 27 May 2014)

  New Revision: 3f05c88273dded4f911bad6a0250b3b3d8582c8d
  https://github.com/droonga/droonga-engine/commit/3f05c88273dded4f911bad6a0250b3b3d8582c8d

  Message:
    select: support Time type

  Added files:
    test/command/suite/groonga/select/type/time.catalog.json
    test/command/suite/groonga/select/type/time.expected
    test/command/suite/groonga/select/type/time.test
  Modified files:
    lib/droonga/plugins/groonga/select.rb

  Modified: lib/droonga/plugins/groonga/select.rb (+15 -1)
===================================================================
--- lib/droonga/plugins/groonga/select.rb    2014-05-27 18:08:59 +0900 (92fd9b7)
+++ lib/droonga/plugins/groonga/select.rb    2014-05-27 18:13:18 +0900 (75b2f27)
@@ -196,7 +196,7 @@ module Droonga
           def convert_search_result(result)
             count      = result["count"]
             attributes = convert_attributes(result["attributes"])
-            records    = result["records"] || []
+            records    = convert_records(attributes, result["records"] || [])
             [[count], attributes, *records]
           end
 
@@ -208,6 +208,20 @@ module Droonga
               [name, type]
             end
           end
+
+          def convert_records(attributes, records)
+            records.collect do |record|
+              record.collect.each_with_index do |value, i|
+                name, type = attributes[i]
+                case type
+                when "Time"
+                  normalize_time(value).to_f
+                else
+                  value
+                end
+              end
+            end
+          end
         end
 
         class Adapter < Droonga::Adapter

  Added: test/command/suite/groonga/select/type/time.catalog.json (+19 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/groonga/select/type/time.catalog.json    2014-05-27 18:13:18 +0900 (9d4cd23)
@@ -0,0 +1,19 @@
+{
+  "datasets": {
+    "Droonga": {
+      "fact": "Memos",
+      "schema": {
+        "Memos": {
+          "type": "Hash",
+          "keyType": "ShortText",
+          "columns": {
+            "created_at": {
+              "type": "Scalar",
+              "valueType": "Time"
+            }
+          }
+        }
+      }
+    }
+  }
+}

  Added: test/command/suite/groonga/select/type/time.expected (+37 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/groonga/select/type/time.expected    2014-05-27 18:13:18 +0900 (f0fb76b)
@@ -0,0 +1,37 @@
+{
+  "inReplyTo": "request-id",
+  "statusCode": 200,
+  "type": "select.result",
+  "body": [
+    [
+      0,
+      0.0,
+      0.0
+    ],
+    [
+      [
+        [
+          2
+        ],
+        [
+          [
+            "_key",
+            "ShortText"
+          ],
+          [
+            "created_at",
+            "Time"
+          ]
+        ],
+        [
+          "Droonga is fun",
+          1401170395.0
+        ],
+        [
+          "Ruby is also fun",
+          1401341365.0
+        ]
+      ]
+    ]
+  ]
+}

  Added: test/command/suite/groonga/select/type/time.test (+34 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/groonga/select/type/time.test    2014-05-27 18:13:18 +0900 (b53aa01)
@@ -0,0 +1,34 @@
+# -*- js -*-
+#@require-catalog-version 2
+#@disable-logging
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Memos",
+    "key": "Droonga is fun",
+    "values": {
+      "created_at": "2014-05-27T14:59:55+09:00"
+    }
+  }
+}
+{
+  "type": "add",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Memos",
+    "key": "Ruby is also fun",
+    "values": {
+      "created_at": "2014-05-29T14:29:25+09:00"
+    }
+  }
+}
+#@enable-logging
+{
+  "type": "select",
+  "dataset": "Droonga",
+  "body": {
+    "table": "Memos",
+    "output_columns": "_key, created_at"
+  }
+}
-------------- next part --------------
HTML����������������������������...
Download 



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