[Groonga-commit] groonga/groonga.org at 1bb71b7 [gh-pages] blog ja: add more release topics

Back to archive index

Kentaro Hayashi null+****@clear*****
Sat May 28 17:05:10 JST 2016


Kentaro Hayashi	2016-05-28 17:05:10 +0900 (Sat, 28 May 2016)

  New Revision: 1bb71b7b19c4c8b0053634bfa61d9d5dfd4dad20
  https://github.com/groonga/groonga.org/commit/1bb71b7b19c4c8b0053634bfa61d9d5dfd4dad20

  Message:
    blog ja: add more release topics

  Modified files:
    ja/_posts/2016-05-29-groonga-6.0.3.md

  Modified: ja/_posts/2016-05-29-groonga-6.0.3.md (+149 -1)
===================================================================
--- ja/_posts/2016-05-29-groonga-6.0.3.md    2016-05-27 22:39:03 +0900 (d3ff6f9)
+++ ja/_posts/2016-05-29-groonga-6.0.3.md    2016-05-28 17:05:10 +0900 (44ec6b9)
@@ -87,7 +87,155 @@ Groongaには[コマンドにバージョン](http://groonga.org/ja/docs/referen
 
 ![betweenの最適化対数グラフ](/images/blog/ja/2016-05-29-groonga-between-optimization/benchmark-between-optimization.png)
 
-#### 
+#### 新規プラグインを2つ追加しました
+
+今回のリリースでは、新規プラグインが2つ追加されました。``time``プラグインと``number``プラグインです。
+どちらも、特定の範囲の値を同じ値とみなすことができるようになります。これにより、``number``プラグインを使うと同一価格帯のものをまとめたりできます。
+``time``プラグインを使うと同時期のデータをまとめることができるようになります。
+
+``number``プラグインは``number_classify``関数を提供しています。
+
+どんなふうに使えるのかサンプルを紹介します。価格がキーであるデータがいくつか登録されているとします。これを100円ごとのデータは同一価格帯の商品として分類してみましょう。
+スキーマとサンプルは以下の通りです。
+
+    plugin_register functions/number
+    table_create Prices TABLE_PAT_KEY Int32
+
+    load --table Prices
+    [
+    {"_key": 0},
+    {"_key": 1},
+    {"_key": 99},
+    {"_key": 100},
+    {"_key": 101},
+    {"_key": 199},
+    {"_key": 200},
+    {"_key": 201}
+    ]
+
+``number_classify``を使って実現するには次のようなクエリを実行します。
+    
+    select Prices --sortby _id --limit -1 --output_columns '_key, number_classify(_key, 100)'
+
+``number_classify(_key, 100)``は分類には``_key``の値を使うこと、値の範囲は100区切りで分類する、というのを指定しています。
+
+    [
+      [
+        [8],
+        [
+          ["_key","Int32"],
+          ["number_classify",null]
+        ],
+        [0,0],
+        [1,0],
+        [99,0],
+        [100,100],
+        [101,100],
+        [199,100],
+        [200,200],
+        [201,200]
+      ]
+    ]
+
+100円ごと、なので100から199までは同一価格帯の100としてみなしていることがわかりますね。
+
+``time``プラグインも時刻に関して似たようなことができます。次のような分類用の関数を提供しています。
+
+* time_classify_second
+* time_classify_minute
+* time_classify_hour
+* time_classify_day
+* time_classify_week
+* time_classify_month
+* time_classify_year
+
+こんどは10分ごとを同一のタイムスタンプだとみなして分類してみましょう。サンプルのスキーマとデータは次の通りです。
+
+    plugin_register functions/time
+    table_create Timestamps TABLE_PAT_KEY Time
+    load --table Timestamps
+    [
+    {"_key": "2016-05-05 22:29:59.999999"},
+    {"_key": "2016-05-05 22:30:00.000000"},
+    {"_key": "2016-05-05 22:30:00.000001"},
+    {"_key": "2016-05-05 22:39:59.999999"},
+    {"_key": "2016-05-05 22:40:00.000000"},
+    {"_key": "2016-05-05 22:40:00.000001"}
+    ]
+
+分ごとなので、``time_classify_minute``を使います。次のようなクエリを実行してみましょう。
+
+    select Timestamps --sortby _id --limit -1 --output_columns '_key, time_classify_minute(_key, 10)'
+
+結果はこんなふうになります。
+
+    [
+      [
+        [6],
+        [
+          ["_key","Time"],
+          ["time_classify_minute",null]
+        ],
+        [1462454999.999999,1462454400.0],
+        [1462455000.0,1462455000.0],
+        [1462455000.000001,1462455000.0],
+        [1462455599.999999,1462455000.0],
+        [1462455600.0,1462455600.0],
+        [1462455600.000001,1462455600.0]
+      ]
+    ]
+
+10分ごとなので、22:30分から22:39分までのデータが同一時刻(1462455000.0)としてみなされていることがわかります。
+
+#### ウィンドウ関数をサポートしました
+
+今回のリリースでは、ウィンドウ関数をサポートしました。
+例えば、連番を振る``record_number``を利用することができるようになりました。
+
+サンプルのスキーマとデータは次の通りです。
+
+    table_create Items TABLE_HASH_KEY ShortText
+    column_create Items price COLUMN_SCALAR UInt32
+
+    load --table Items
+    [
+    {"_key": "item1", "price": 666},
+    {"_key": "item2", "price": 999},
+    {"_key": "item3", "price": 777},
+    {"_key": "item4", "price": 111},
+    {"_key": "item5", "price": 333},
+    {"_key": "item6", "price": 222}
+    ]
+    
+これをもとに、価格の安い順だと何番目のレコードになるかを取得してみましょう。クエリは次のようになります。
+
+    select Items \
+      --columns[nth_record].stage initial \
+      --columns[nth_record].value 'record_number()' \
+      --columns[nth_record].type UInt32 \
+      --columns[nth_record].window.sort_keys price \
+      --output_columns '_key, price, nth_record'
+
+動的カラム``nth_record``に``record_number()``の値を設定しているのがポイントです。
+
+    [
+      [
+        [6],
+        [
+          ["_key","ShortText"],
+          ["price","UInt32"],
+          ["nth_record","UInt32"]
+        ],
+        ["item1",666,4],
+        ["item2",999,6],
+        ["item3",777,5],
+        ["item4",111,1],
+        ["item5",333,3],
+        ["item6",222,2]
+      ]
+    ]
+
+それぞれのアイテムが価格の安い順だと何番目のレコードになっているのかがこれでわかります。
 
 ### お知らせ
 
-------------- next part --------------
HTML����������������������������...
Download 



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