-
Notifications
You must be signed in to change notification settings - Fork 1
/
cassandra-part.r
67 lines (57 loc) · 1.58 KB
/
cassandra-part.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
source("part-api.r")
as_cass_part <- function(x) {
ret <- list(key=guid())
class(ret) <- c(class(ret), "cassandra_part")
cass_insert(ret$key, serialize(x, NULL))
ret
}
init_cassandra_part <- function() {
options(default_part_constructor=as_cass_part)
invisible(TRUE)
}
cass_insert <- function(key, value) {
iq <- casslite::cl.prepare("insert into test.block (key, v) values (?, ?)")
insert <- function(key, value) casslite::cl.execute(iq, 0, key, value)
insert(key, value)
}
cass_retrieve <- function(key) {
q <- casslite::cl.prepare("select v from test.block where key=?")
query <- function(key) casslite::cl.execute(q, -1, key)
query(key)
}
get_values.cassandra_part <- function(part, i, ...) {
x <- unserialize(cass_retrieve(part$key))
if (!missing(i) && !missing(...)) {
x[i, ...]
} else if (missing(i) && !missing(...)) {
x[...]
} else if (!missing(i) && missing(...)) {
x[i]
} else {
x
}
}
get_attributes.cassandra_part <- function(part, labels) {
x <- unserialize(cass_retrieve(part$key))
if (missing(labels)) {
attributes(x)
} else {
attributes(x)[[labels]]
}
}
get_object_size.cassandra_part <- function(part) {
x <- unserialize(cass_retrieve(part$key))
object.size(x)
}
get_typeof.cassandra_part <- function(part) {
x <- unserialize(cass_retrieve(part$key))
typeof(x)
}
get_class.cassandra_part <- function(part) {
x <- unserialize(cass_retrieve(part$key))
class(x)
}
delete_part.cassandra_part <- function(part) {
iq <- casslite::cl.preapare("DELETE FROM test.block WHERE key=?")
cl.execute(iq, part$key)
}