Navigation Menu

Skip to content

Commit

Permalink
Accept Integer as hash slicer's key
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 7, 2014
1 parent 8b0924a commit b86e22b
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/droonga/catalog/collection_volume.rb
Expand Up @@ -48,7 +48,7 @@ def select_slices(range=0..-1)
def choose_slice(record)
return slices.first unless ratio_scaled_slicer?

key = record[dimension]
key = stringify_key(record[dimension])
hash = Zlib.crc32(key)
min = 0
max = @continuum.size - 1
Expand Down Expand Up @@ -92,6 +92,15 @@ def compute_total_weight
result + slice.weight
end
end

def stringify_key(key)
case key
when Integer
key.to_s
else
key
end
end
end
end
end
19 changes: 19 additions & 0 deletions test/command/suite/add/dimension/integer.catalog.json
@@ -0,0 +1,19 @@
{
"datasets": {
"Droonga": {
"schema": {
"Products": {
"type": "Hash",
"keyType": "Integer",
"columns": {
"name": {
"type": "Scalar",
"valueType": "ShortText"
}
}
}
},
"fact": "Products"
}
}
}
57 changes: 57 additions & 0 deletions test/command/suite/add/dimension/integer.expected
@@ -0,0 +1,57 @@
[
"droonga.message",
0,
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "add.result",
"body": true
}
]
[
"droonga.message",
0,
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "add.result",
"body": true
}
]
[
"droonga.message",
0,
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "add.result",
"body": true
}
]
[
"droonga.message",
0,
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "search.result",
"body": {
"products": {
"records": [
[
1,
"Groonga"
],
[
2,
"Droonga"
],
[
3,
"Ruby"
]
]
}
}
}
]
51 changes: 51 additions & 0 deletions test/command/suite/add/dimension/integer.test
@@ -0,0 +1,51 @@
#@require-catalog-version 2
{
"type": "add",
"dataset": "Droonga",
"body": {
"table": "Products",
"key": 1,
"values": {
"name": "Groonga"
}
}
}
{
"type": "add",
"dataset": "Droonga",
"body": {
"table": "Products",
"key": 2,
"values": {
"name": "Droonga"
}
}
}
{
"type": "add",
"dataset": "Droonga",
"body": {
"table": "Products",
"key": 3,
"values": {
"name": "Ruby"
}
}
}
{
"type": "search",
"dataset": "Droonga",
"body": {
"queries": {
"products": {
"source": "Products",
"sortBy": ["_key"],
"output": {
"elements": ["records"],
"attributes": ["_key", "name"],
"limit": -1
}
}
}
}
}

0 comments on commit b86e22b

Please sign in to comment.