Skip to content

Commit

Permalink
Add system.object-count command (mainly for internal use)
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 21, 2015
1 parent d61376b commit b38cf1a
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/droonga/plugins/system.rb
Expand Up @@ -25,4 +25,5 @@ module System
end

require "droonga/plugins/system/status"
require "droonga/plugins/system/object_count"
require "droonga/plugins/system/absorb_data"
53 changes: 53 additions & 0 deletions lib/droonga/plugins/system/object_count.rb
@@ -0,0 +1,53 @@
# Copyright (C) 2015 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "droonga/plugin"
require "droonga/database_scanner"

module Droonga
module Plugins
module System
class ObjectCountHandler < Droonga::Handler
include DatabaseScanner

def handle(message)
counts = {}
output = message.request["output"]
if output and output.is_a?(Array)
if output.include?("tables")
counts["tables"] = n_tables
end
if output.include?("columns")
counts["columns"] = n_columns
end
if output.include?("records")
counts["records"] = n_records
end
if output.include?("total")
counts["total"] = total_n_objects
end
end
counts
end
end

define_single_step do |step|
step.name = "system.object-count"
step.handler = ObjectCountHandler
step.collector = Collectors::Sum
end
end
end
end
11 changes: 11 additions & 0 deletions test/command/suite/system/object-count/empty.expected
@@ -0,0 +1,11 @@
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "system.object-count.result",
"body": {
"tables": 0,
"columns": 0,
"records": 0,
"total": 0
}
}
12 changes: 12 additions & 0 deletions test/command/suite/system/object-count/empty.test
@@ -0,0 +1,12 @@
{
"type": "system.object-count",
"dataset": "Default",
"body": {
"output": [
"tables",
"columns",
"records",
"total"
]
}
}
12 changes: 12 additions & 0 deletions test/command/suite/system/object-count/record.catalog.json
@@ -0,0 +1,12 @@
{
"datasets": {
"Default": {
"schema": {
"Users": {
"type": "PatriciaTrie",
"keyType": "ShortText"
}
}
}
}
}
11 changes: 11 additions & 0 deletions test/command/suite/system/object-count/record.expected
@@ -0,0 +1,11 @@
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "system.object-count.result",
"body": {
"tables": 2,
"columns": 0,
"records": 1,
"total": 3
}
}
23 changes: 23 additions & 0 deletions test/command/suite/system/object-count/record.test
@@ -0,0 +1,23 @@
#@require-catalog-version 2
#@disable-logging
{
"type": "add",
"dataset": "Source",
"body": {
"table": "Users",
"key": "Adam"
}
}
#@enable-logging
{
"type": "system.object-count",
"dataset": "Default",
"body": {
"output": [
"tables",
"columns",
"records",
"total"
]
}
}
12 changes: 12 additions & 0 deletions test/command/suite/system/object-count/schema.catalog.json
@@ -0,0 +1,12 @@
{
"datasets": {
"Default": {
"schema": {
"Users": {
"type": "PatriciaTrie",
"keyType": "ShortText"
}
}
}
}
}
11 changes: 11 additions & 0 deletions test/command/suite/system/object-count/schema.expected
@@ -0,0 +1,11 @@
{
"inReplyTo": "request-id",
"statusCode": 200,
"type": "system.object-count.result",
"body": {
"tables": 2,
"columns": 0,
"records": 0,
"total": 2
}
}
13 changes: 13 additions & 0 deletions test/command/suite/system/object-count/schema.test
@@ -0,0 +1,13 @@
#@require-catalog-version 2
{
"type": "system.object-count",
"dataset": "Default",
"body": {
"output": [
"tables",
"columns",
"records",
"total"
]
}
}

0 comments on commit b38cf1a

Please sign in to comment.