Skip to content

Commit

Permalink
Initial r.info() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lbguilherme committed Mar 1, 2020
1 parent f6026dc commit f8a2d43
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shard.lock
Expand Up @@ -2,5 +2,5 @@ version: 1.0
shards:
rocksdb:
github: lbguilherme/rocksdb-crystal
commit: 8b39de420d8001b9202f444063afa8db98d34dc9
commit: 5136ce80a3ad90904c429e3989c5d3625c1a16c8

41 changes: 41 additions & 0 deletions src/reql/terms/info.cr
@@ -0,0 +1,41 @@
require "../term"

module ReQL
class InfoTerm < Term
infix_inspect "info"

def check
expect_args 1
end
end

class Evaluator
def eval_term(term : InfoTerm)
target = eval(term.args[0])

case target.reql_type
when "TABLE"
table = target.as_table
storage = table.storage

Datum.new({
"db" => {
"id" => "", # TODO
"name" => table.db.name,
"type" => "DB",
},
"doc_count_estimates" => [
storage.is_a?(Storage::PhysicalTable) ? storage.estimated_count : 0,
],
"id" => "", # TODO
"indexes" => storage.is_a?(Storage::PhysicalTable) ? storage.get_index_list : [] of String,
"name" => table.name,
"primary_key" => storage.primary_key,
"type" => "TABLE",
})
else
raise "BUG: .info() not implemented for #{target.reql_type}"
end
end
end
end
4 changes: 4 additions & 0 deletions src/storage/kv.cr
Expand Up @@ -437,6 +437,10 @@ module Storage
end
end

def estimated_table_count(table_id : UUID)
@rocksdb.property_int(table_data_family(table_id), "rocksdb.estimate-num-keys").not_nil!.to_i64
end

struct SystemInfo
property id : UUID = UUID.random
property data_version : UInt8 = 0
Expand Down
4 changes: 4 additions & 0 deletions src/storage/table/physical_table.cr
Expand Up @@ -222,5 +222,9 @@ module Storage
end
end
end

def estimated_count
@manager.kv.estimated_table_count(@table.info.id)
end
end
end

0 comments on commit f8a2d43

Please sign in to comment.