phantom-dsl


How do I query an optional column with a secondary index using phantom?


I have a secondary index on an optional column:
class Sessions extends CassandraTable[ConcreteSessions, Session] {
object matchId extends LongColumn(this) with PartitionKey[Long]
object userId extends OptionalLongColumn(this) with Index[Option[Long]]
...
}
However, the indexedToQueryColumn implicit conversion is not available for optional columns, so this does not compile:
def getByUserId(userId: Long): Future[Seq[Session]] = {
select.where(_.userId eqs userId).fetch()
}
Neither does this:
select.where(_.userId eqs Some(userId)).fetch()
Or changing the type of the index:
object userId extends OptionalLongColumn(this) with Index[Long]
Is there a way to perform such a query using phantom?
I know that I could denormalize, but it would involve some very messy housekeeping and triple our (substantial) data size. The query usually returns only a handful of results, so I'd be willing to use a secondary index in this case.
Short answer: You could not use optional fields in order to query things in phantom.
Long detailed answer:
But, if you really want to work with secondary optional columns, you should declare your entity field as Option but your phantom representation should not be an option in order to query.
object userId extends LongColumn(this) with Index[Long]
In the fromRow(r: Row) you can create your object like this:
Sessions(matchId(r), Some(userId(r)))
Then in the service part you could do the following:
.value(_.userId, t.userId.getOrElse(0))
You also have a better way to do that. You could duplicate the table, making a new kind of query like sessions_by_user_id where in this table your user_id would be the primary key and the match_id the clustering key.
Since user_id is optional, you would end with a table that contains only valid user ids, which is easy and fast to lookup.
Cassandra relies on queries, so use it in your favor.
Take a look up on my github project that helps you get up with multiple queries in the same table.
https://github.com/thiagoandrade6/cassandra-phantom

Related Links

Phantom's generated `store` method throws a ClassCastException at runtime
Connecting to Cassandra on startup, and monitoring session health
How do I query an optional column with a secondary index using phantom?
How to clean up RootConnector in phantom-dsl?
Phantom Cassandra batch insert

Categories

HOME
azure-stream-analytics
twitter-bootstrap-3
time-complexity
github-for-windows
powerpoint
hessian
pclxl
rendering
appcelerator
pdfbox
javacc
database-normalization
carousel
soa
nested-if
crystal-reports-2013
jtextpane
recordrtc
bing-maps
watson-conversation
startup
filechannel
flash-player
atlassian
event-sourcing
internationalization
sencha-touch
asciidoctor-pdf
easeljs
mount
itunes
asymptotic-complexity
8051
inversion-of-control
recurring-events
getpixel
reason
alphabetical
cd
node-mssql
demo
naming
phpdbg
flask-restful
getchar
proget
convex-optimization
magic-draw
pair-programming
custom-font
boo
flyout
donations
choice
builtins
redistributable
qtplugin
xcode-server
centrifuge
mongodb-php
dup
design-principles
libvlc
forwarding
ons-api
zen-cart
slash
viola-jones
skspritenode
mmwormhole
cryptographichashfunction
primitive-types
structuremap3
appserver
tinyxml
jquery-slider
koala
qscrollarea
hibernate-entitymanager
workitem
android-icons
windows-98
cascadingdropdown
redis-py
faye
isa-swizzling
entity-attribute-value
htdocs
matlab-load
webdev.webserver
entitydatasource
inline-formset
codebase
presentation-layer
interprocess
lobo-cobra
linfu-dynamicproxy
ifilter
xslcompiledtransform
blind

Resources

Encrypt Message