Title: 544
Tags: lec27

Q: Cassandra keyspaces contain tables.  If you want to access table T in keyspace K, but you don't want to type K.T every time you access T, what can you do?
A: Execute this first:
USE K

Q: What is the cluster and partition key for this Cassandra table?
CREATE TABLE ???? (
  ...
  PRIMARY KEY (x, y, z)
)
A: partition key: x
cluster key: (y,z)
If you wanted y to be part of the partition key, you would need to specify like this:
PRIMARY KEY ((x, y), z)

Q: What are two Cassandra functions to create a UUID value, and what is the difference between them?
A: UUID() and NOW()
NOW() does a better job of actually guaranteeing uniqueness because it uses several factors: MAC address (remember these are supposed to be globally unique), current time, and sequence number (in case it is called concurrently)

Q: What happens when you do a Cassandra INSERT with a key that already exists?
A: INSERT is really an upsert (update OR insert), so it will overwrite the previous value if already there.  No error.
The key could be the whole primary key, or just a partition key.

Q: Will this query be fast or slow in Cassandra if table T is large?
alter table T add (newcol sometype)
A: Fast because Cassandra tables are sparse.  Cassandra doesn't need to write a bunch of NULL values to fill out the new column.

Q: What are some advantages of prepared statements, in CQL or SQL?
A: 1. Only need to parse the query once.
2. Easier to call (just specify a few values to plug in).  We can also control default values more easily.

Q: When can you do GROUP BY with Cassandra?
A: When you're grouping on the columns of the primary key.

Q: If your Cassandra keyspace K has a table T, what does this do in Spark?
spark.conf.set("spark.sql.catalog.C", "com.datastax.spark.connector.datasource.CassandraCatalog")
spark.conf.set("spark.sql.catalog.C.spark.cassandra.connection.host", "????")
A: It creates a Spark catalog C containing all the keyspaces of the Cassandra cluster specified on the "host" line.  This means the T table can be queried from Spark as C.K.T.