database design - Cassandra: Which schema for table-like mappings? -
i have tried different approaches can't find solution problem: data table-like, meaning have 1 data point (float) each combination of inputs set of strings:
(a mapping of s × s → ℝ )
i want model schema can following lookups:
- all pairs of strings value in range
- for given input string, strings mapped value in range
- for given combination of input strings mapped value
since mapping symmetrical (m(x,y) == m(y,x)
), great if had store the
n*(n+1) / 2
unique values instead of n^2
total mappings.
what have tried far:
- s1+" "+s2 row key , value column name
- s1 row key , composite key of [s2:value] column name
- s1 row key, s2 column name, value column value.
but unfortunately, these approaches don't let me queries need. possible in cassandra?
cassandra not support first query --- all pairs of strings value in range --- since currently, cassandra allows range queries @ least 1 eq
on where
clause. however, second , third queries doable :)
example
consider following example:
cqlsh:so> desc table string_mappings; create table string_mappings ( s1 ascii, s2 ascii, value float, primary key (s1, s2, value) )
and have following tuples:
cqlsh:so> select * string_mappings; s1 | s2 | value -------+-------+------- hello | hello | 1 hello | world | 0.2 stack | hello | 0 stack | stack | 1 stack | world | 0 world | world | 1
your first query not work cassandra not support range queries without eq
on where
clause:
cqlsh:so> select * string_mappings value>0.5; bad request: primary key part value cannot restricted (preceding part s2 either not restricted or non-eq relation)
however, following range query (your second query) fine since has eq
:
cqlsh:so> select * string_mappings value > 0.5 , s2='hello' allow filtering; s1 | s2 | value -------+-------+------- hello | hello | 1
and remember put allow filtering
keyword, or following error:
cqlsh:so> select * string_mappings value > 0.5 , s2='hello'; bad request: cannot execute query might involve data filtering , may have unpredictable performance. if want execute query despite performance unpredictability, use allow filtering
finally, third query not problem :)
cqlsh:so> select * string_mappings s1='hello' , s2='world'; s1 | s2 | value -------+-------+------- hello | world | 0.2
Comments
Post a Comment