At the Forge - Cassandra
Restart Cassandra, and reconnect via the CLI. Then, type:
cassandra> show keyspaces
Your new keyspace, “People”, now should appear in the list:
cassandra> show keyspaces Keyspace1 system People
You can ask for a description of your keyspace:
cassandra> describe keyspace People People.Users Column Family Type: Standard Columns Sorted By: org.apache.cassandra.db.marshal.BytesType@1b22920 Column Family Type: Standard Column Sorted By: org.apache.cassandra.db.marshal.BytesType flush period: null minutes ------
You now can see that your People keyspace contains a single “Users” column family. With this in place, you can start to set and retrieve data:
cassandra> get People.Users['1'] Returned 0 results. cassandra> set People.Users['1']['email'] = 'firstname.lastname@example.org' cassandra> set People.Users['1']['first_name'] = 'Reuven' cassandra> set People.Users['1']['last_name'] = 'Lerner'
In Cassandra-ese, you would say that you now have set three column values ('email', 'first_name' and 'last_name'), for one key ('1') under a single column family (“Users”), within a single Keyspace (“People”). If you're used to working with a language like Ruby or Python, you might feel a bit underwhelmed—after all, it looks like you just set a multilevel hash. But that makes sense, given that Cassandra is a super-version of a key-value store, right?
Now, let's try to retrieve the data. You can do that with the key:
cassandra> get People.Users['1'] => (column=6c6173745f6e616d65, value=Lerner, ↪timestamp=1279024194314000) => (column=66697273745f6e616d65, value=Reuven, ↪timestamp=1279024183326000) => (column=656d61696c, email@example.com, timestamp=1279024170585000) Returned 3 results.
Notice how each column has its own unique ID and that the data was stored with a timestamp. Such timestamps are crucial when you are running multiple Cassandra nodes, and they update one another without your knowledge to achieve complete consistency.
You can add additional information too:
cassandra> set People.Users['2']['first_name'] = 'Atara' cassandra> set People.Users['2']['last_name'] = 'Lerner-Friedman' cassandra> set People.Users['2']['school'] = 'Yachad' cassandra> set People.Users['3']['first_name'] = 'Shikma' cassandra> set People.Users['3']['last_name'] = 'Lerner-Friedman' cassandra> set People.Users['3']['school'] = 'Yachad'
Now you have information about three users, and as you can see, the columns that you used within the “Users” column family were not determined by the configuration file and can be added on the spot. Moreover, there is no rule saying that you must set a value for the “email” column; such enforcement doesn't exist in Cassandra. But what is perhaps most amazing to relational database veterans is that there isn't any way to retrieve all the values that have a last_name of 'Lerner-Friedman' or a school named 'Yachad'. Everything is based on the key (which I have set to an integer in this case); you can drill down, but not across, as it were.
You can ask Cassandra how many columns were set for a given key, but you won't know what columns those were:
cassandra> count People.Users['1'] 3 columns cassandra> count People.Users['2'] 3 columns
However, if you're trying to store information about many users, and those users are going to be updating their information on a regular basis, Cassandra can be quite helpful.
Now that you've got the hang of columns, I'll mention a particularly interesting part of the Cassandra data model. Instead of defining columns, you instead can define “super columns”. Each super column is just like a regular column, except it can contain multiple columns within it (rather than a name-value pair). In order to define a super column, set the ColumnType attribute in the storage-conf.xml file to “Super”. For example:
<ColumnFamily Name="Users" CompareWith="BytesType" ↪ColumnType="Super" />
Note that if you restart Cassandra with this changed definition, and then try to retrieve People.Users['1'], you'll probably get an error. That's because you effectively have changed the schema without changing the data, which always is a bad idea. Now you can store and retrieve finer-grained information:
cassandra> set People.Users['1']['address']['city'] = 'Modiin' cassandra> get People.Users['1']['address']['city'] => (column=63697479, value=Modiin, timestamp=1279026442675000)
- Epiq Solutions' Sidekiq M.2
- Android Browser Security--What You Haven't Been Told
- Readers' Choice Awards 2013
- The Many Paths to a Solution
- Nativ Disc
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Synopsys' Coverity
- Securing the Programmer
- Tech Tip: Really Simple HTTP Server with Python
- Naztech's Roadstar 5 Car Charger
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide