LoginSignup
1
1

More than 5 years have passed since last update.

Groongaドキュメント読書会3で学んだ事のメモ

Last updated at Posted at 2014-07-23

はじめに

この文章は、Groongaドキュメント読書会3で学んだ事のメモです。
元のテキストで分からなかった事を中心に書きました。
いよいよGroonga特有の機能に入って来た印象です。

4.2. リモートアクセス

4.2.1.1. GQTPサーバの起動

  • サーバとしての起動はデバッグの際などに使います。サービスなどで使う場合は、後述のデーモンを使う方が適切。

4.2.2. memcachedバイナリプロトコル

  • 通常のGroongaのデータにアクセスできるわけではなく、固定のテーブル名のみにアクセスするため、実用性はいまいちかも。

4.2.3.1. HTTPサーバの起動

  • コマンドの順番は意外と重要。DB_PATHは最後に置く必要がある。

4.3. いろいろなデータの保存

4.3.5. 日時

  • ドキュメントにはないが、小数ではなく文字列でYYYY/MM/DD hh:mm:ss.msecorYYYY-MM-DD hh:mm:ss.msecの書式で指定できる。
  • 1234567890.1234569999で入力したデータは小数点6桁で四捨五入されている事に注目。
  • Groongaストレージ内ではデータを64bit(整数部32bit+小数部32bit)で持っているので本来は上記のような丸めは発生しないが、Groongaストレージと外部とのIF部分でマイクロ秒部分が小数として表現されるのでそこで丸めが発生しうる。
    • RroongaのようにGroongaのIFを利用しないと誤差は生じない。
    • また、上記の文字列指定でも誤差は生じない。
      • 文字列で入れるのが無難かな。

4.3.6. 経緯度

  • 測地系は世界測地系(WGS84)と日本固有の測地系がある。
  • 両者は変換可能だが若干の誤差は生じるので、シビアな環境では注意が必要。
  • 度数表記とミリ秒表記は、一般的には度数表記の方が一般的(Googleマップなど)だが、内部的にはミリ秒で持っている(整数だから)

4.3.7. テーブル参照

  • 参照は必ず主キーで設定すること。IDは、自動発番なのでdump/restoreした際に同じ主キーでも違う番号が振られかねないので危険。

4.3.8. ベクターカラム

  • ベクターカラムの投入された順番は保持される。
  • 作成したベクターカラムへのデータ追加/削除は無理。上書きして登録する必要がある。
    • 内部的には出来るがJSONで表現できないため。

4.3が終わった時点でのデータベース作成メモ

以下のコマンドを順番に実行すると、4.3終了時点のデータが出来ます。

Groongaデータベースの用意(Try-Groongaの場合は不要)
$ groonga -n ~/testdb.db
$ groonga ~/testdb.db       #ログイン

4.1 基本的な操作

Groongaコマンド
table_create --name Site --flags TABLE_HASH_KEY --key_type ShortText

column_create --table Site --name title --type ShortText

load --table Site
[
{"_key":"http://example.org/","title":"This is test record 1!"},
{"_key":"http://example.net/","title":"test record 2."},
{"_key":"http://example.com/","title":"test test record three."},
{"_key":"http://example.net/afr","title":"test record four."},
{"_key":"http://example.org/aba","title":"test test test record five."},
{"_key":"http://example.com/rab","title":"test test test test record six."},
{"_key":"http://example.net/atv","title":"test test test record seven."},
{"_key":"http://example.org/gat","title":"test test record eight."},
{"_key":"http://example.com/vdw","title":"test test record nine."},
]

table_create --name Terms --flags TABLE_PAT_KEY|KEY_NORMALIZE --key_type ShortText --default_tokenizer TokenBigram

column_create --table Terms --name blog_title --flags COLUMN_INDEX|WITH_POSITION --type Site --source title

4.2 リモートアクセス

特になし

4.3 いろいろなデータの保存

Groongaコマンド
table_create --name ToyBox --flags TABLE_HASH_KEY --key_type ShortText

column_create --table ToyBox --name is_animal --type Bool

load --table ToyBox
[
{"_key":"Monkey","is_animal":true}
{"_key":"Flower","is_animal":false}
{"_key":"Block"}
]

column_create --table ToyBox --name price --type Int8

column_create --table ToyBox --name weight --type Float

load --table ToyBox
[
{"_key":"Monkey","price":15.9}
{"_key":"Flower","price":200,"weight":0.13}
{"_key":"Block","weight":25.7}
]

column_create --table ToyBox --name name --type ShortText

load --table ToyBox
[
{"_key":"Monkey","name":"Grease"}
{"_key":"Flower","name":"Rose"}
]

column_create --table ToyBox --name time --type Time

load --table ToyBox
[
{"_key":"Flower","time":1234567890.1234569999}
{"_key":"Block","time":-1234567890}
]

column_create --table ToyBox --name location --type WGS84GeoPoint

load --table ToyBox
[
{"_key":"Monkey","location":"128452975x503157902"}
{"_key":"Block","location":"35.6813819x139.7660839"}
]

column_create --table Site --name link --type Site

load --table Site
[{"_key":"http://example.org/","link":"http://example.net/"}]

column_create --table Site --name links --flags COLUMN_VECTOR --type Site

load --table Site
[{"_key":"http://example.org/","links":["http://example.net/","http://example.org/","http://example.com/"]}]


ここまでで、とりあえず4.3までの環境は整います。

1
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1