使用Hector和Scala持久化Cassandra資料庫
[i=s] 本帖最後由 jieforest 於 2012-12-19 15:31 編輯
I am going to show you how I went about solving how to persist instances in Cassandra, using Hector, in the function insert(instance) in Scala. To work out how these instances are going to be persisted, I shall use type classes. More than just the code, I will explain & show every step of my design.
Crash course in Cassandra
Cassandra is a schema-free database; to understand it, here are the most important concepts and their loose mapping to the relational databases counterparts:
keyspace – schema; database
column family – table, with key and rows
key – primary key
row – collection of columns; the rows in the column family may have completely different columns
column – column
When inserting data into Cassandra, we must be able to serialise the data to be inserted. To do that, we must know the key type and the names and types of all columns.
Back to Scala
Let’s turn back to our insert(instance) function. Intuitively, we would understand what should happen if we were to insert a simple case class:
2.password: String,
3.firstName: String,
4.lastName: String,
5.id: UUID)
I am going to show you how I went about solving how to persist instances in Cassandra, using Hector, in the function insert(instance) in Scala. To work out how these instances are going to be persisted, I shall use type classes. More than just the code, I will explain & show every step of my design.
Crash course in Cassandra
Cassandra is a schema-free database; to understand it, here are the most important concepts and their loose mapping to the relational databases counterparts:
keyspace – schema; database
column family – table, with key and rows
key – primary key
row – collection of columns; the rows in the column family may have completely different columns
column – column
When inserting data into Cassandra, we must be able to serialise the data to be inserted. To do that, we must know the key type and the names and types of all columns.
Back to Scala
Let’s turn back to our insert(instance) function. Intuitively, we would understand what should happen if we were to insert a simple case class:
CODE:
1.case class User(username: String,2.password: String,
3.firstName: String,
4.lastName: String,
5.id: UUID)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-751354/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- cassandra&hector版本問題
- Cassandra資料庫資料庫
- Python SqlAlchemy資料庫持久化使用方法PythonSQL資料庫持久化
- 資料持久化,好高階~哎,資料庫啊!!持久化資料庫
- Redis資料持久化—RDB持久化與AOF持久化Redis持久化
- 使用Room持久庫儲存資料OOM
- 什麼是Cassandra資料庫資料庫
- Redis——Redis用作資料庫(持久化/RDB/AOF)Redis資料庫持久化
- Quzrtz.net-sqlite 資料庫持久化配置SQLite資料庫持久化
- MongoDB、Cassandra 和 HBase 三種 NoSQL 資料庫比較MongoDBSQL資料庫
- fabric資料持久化持久化
- Redis 資料持久化Redis持久化
- web 資料持久化Web持久化
- Docker資料持久化Docker持久化
- 使用Spark和Cassandra進行資料處理(一)Spark
- linux安裝Cassandra資料庫Linux資料庫
- 非關係型資料庫:Cassandra資料庫
- Flutter持久化儲存之資料庫儲存Flutter持久化資料庫
- MVVM的資料持久化(二)——ROOM的使用MVVM持久化OOM
- Docker之 資料持久化Docker持久化
- Redis的資料持久化Redis持久化
- 鴻蒙資料持久化sqlite鴻蒙持久化SQLite
- Docker最全教程——資料庫容器化之持久儲存資料(十一)Docker資料庫
- Docker的持久化儲存和資料共享(四)Docker持久化
- 1.05 docker的持久化儲存和資料共享Docker持久化
- 資料的序列化&持久化持久化
- 在 Apache Cassandra 中定義和最佳化資料分割槽Apache
- 資料庫持久連線理解資料庫
- Cassandra 資料模型模型
- iOS資料持久化設計iOS持久化
- 詳解 ZooKeeper 資料持久化持久化
- iOS中的資料持久化iOS持久化
- ActiveMQ 訊息資料持久化MQ持久化
- Kafka實戰-資料持久化Kafka持久化
- redis學習 - 資料持久化Redis持久化
- 可持久化資料結構持久化資料結構
- UI(十六)資料持久化和歸檔NSCoding序列化UI持久化
- 【許曉笛】EOS 資料庫與持久化 API —— 架構資料庫持久化API架構