Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grn_pat_get_key2() returns 1 for id == 0 (GRN_ID_NIL) #432

Closed
s-yata opened this issue Nov 20, 2015 · 3 comments
Closed

grn_pat_get_key2() returns 1 for id == 0 (GRN_ID_NIL) #432

s-yata opened this issue Nov 20, 2015 · 3 comments
Assignees

Comments

@s-yata
Copy link
Contributor

s-yata commented Nov 20, 2015

Description

grn_pat_get_key2() is a function that returns the length of a key, but grn_pat_get_key2() returns 1 for id == 0 (GRN_ID_NIL).

The original reports are as follows:

Groongaの参照型ベクターカラムでブランクのタグが入っていると
出力に適当なタグの1文字目だけが出力されます。

https://gist.github.com/naoa/6bd6c19244b37ced2ce9

これを出力されないようにするか、ブランクが出力できるようにできませんか?
こちら少しデバッグしたのですが、思ったより深いようでした。
grn_pat_get_key2にid=0を渡した時、なんかnodeが見つかるようで
長さが0でなく1で返ります。
これのせいで1つ前にかかれたバッファから1の長さでとってしまうようです。

https://github.com/groonga/groonga/blob/master/lib/pat.c#L1470-L1472

他方、grn_hash_get_key2やgrn_dat_get_key2では長さ0で返ります。

Thanks to Naoya Murakami!

@s-yata s-yata added the Bug label Nov 20, 2015
@s-yata s-yata self-assigned this Nov 20, 2015
@s-yata
Copy link
Contributor Author

s-yata commented Nov 20, 2015

単純に, grn_pat_get_key() および grn_pat_get_key2()id == 0 のときに対する例外処理を追加すれば解決できそうです.

grn_pat のノードに保存される length が 1 以上 4,096 以下なので,例外処理で回避しないと id == 0 に対応するダミーノードでも length == 1 と出てしまうようです.
なお,短いキーしか存在しない状況では immediate == 1 なノードばかりでキー保存用の領域が確保されず, pat_node_get_key() が NULL を返すために再現しませんでした.

@s-yata
Copy link
Contributor Author

s-yata commented Nov 20, 2015

上述の修正を加えると,結果は以下のようになりました.

$ rm -rf /tmp/groonga/* && src/groonga -n /tmp/gonga/db
> table_create Tags TABLE_PAT_KEY ShortText
[[0,1447980288.16017,0.00117969512939453],true]
> table_create Memos TABLE_HASH_KEY ShortText
[[0,1447980290.73807,0.00681185722351074],true]
> column_create Memos tags COLUMN_VECTOR Tags
[[0,1447980292.89716,0.00232911109924316],true]
> load --table Memos
> [
> {"_key": "Rroonga", "tags": ["Groonga", "Ruby"]},
> {"_key": "Groonga", "tags": ["Groonga"]},
> {"_key": "Blank", "tags": [""]},
> {"_key": "Nothing"}
> ]
[[0,1447980294.74791,16.7109251022339],4]
> select Memos --output_columns 'tags'
[[0,1447980313.97276,0.00151491165161133],
 [[[4],[["tags","Tags"]],[["Groonga","Ruby"]],[["Groonga"]],[[""]],[[]]]]]

s-yata added a commit that referenced this issue Nov 20, 2015
s-yata added a commit that referenced this issue Nov 20, 2015
These functions returned 1 as a key length for id = 0.

GitHub: #432
@s-yata
Copy link
Contributor Author

s-yata commented Nov 20, 2015

ユニットテスト,コマンドテストともに問題ないことを確認しました.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant