How to see the column names of Dynamic CF in cassandra? - cassandra

Am trying to get the column names of my column family which are created dynamically.
I created the CF
[default#test] CREATE COLUMN FAMILY blog_entry
WITH comparator = TimeUUIDType
AND key_validation_class=UTF8Type
AND default_validation_class = UTF8Type;
[default#test] show schema;
create column family blog_entry
with column_type = 'Standard'
and comparator = 'TimeUUIDType'
and default_validation_class = 'UTF8Type'
and key_validation_class = 'UTF8Type'
and read_repair_chance = 0.1
and dclocal_read_repair_chance = 0.0
and populate_io_cache_on_flush = false
and gc_grace = 864000
and min_compaction_threshold = 4
and max_compaction_threshold = 32
and replicate_on_write = true
and compaction_strategy = 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy'
and caching = 'KEYS_ONLY'
and compression_options = {'sstable_compression' : 'org.apache.cassandra.io.compress.SnappyCompressor'};
I inserted some data into it with the column names but now how to see my column names?

You have to query row by row to see any column names that aren't declared (by you) in the column metadata. If you want to add columns to the column metadata then you need to alter the column family definition. Cassandra will not automatically do this for you.

Related

DAX: SUM a data from column C, filtering by column B where relationship is on column A

I need help,
I have to data sources in Excel where table A has a UID and table B has that same UID related many to single (many on table B, the single value on table A).
I want to add all the numerical data in column C on file B but only when column B value is "yes" and show that on table A based on the UID relationship between tables.
You should be able to do this with a SUMX in a calculated column:
YesSumC = SUMX(TableB,
IF(TableB[Column B] = "yes" &&
TableB[UID] = TableA[UID],
TableB[Column C], 0))
Instead of explicitly matching on UID you could also use RELATEDTABLE like this:
YesSumC = SUMX(RELATEDTABLE(TableB),
IF(TableB[Column B] = "yes",
TableB[Column C], 0))

Incrementing Cassandra Counter Column Family in NodeJs

I am trying to do an insert/increment in cassandra database through node.js...
Suppose I have this table:
CREATE COLUMN FAMILY MsCounter
WITH comparator = UTF8Type
AND key_validation_class=UTF8Type
AND default_validation_class = CounterColumnType;
then let's say i want to insert/increment a row key and a value on MsCounter:
rowKey: 'Tim', columnName1: columnName1 + 1
Is there any way to do this programatically in Node Js using
cassandra-client ?
I am aware they show an example of inserting and updating a regular column family, but does the same applied for counter column family ?
After reading this sample , I realize that it is possible to do the CQL without using the optional parameter. Here is how I do it in my case:
con.execute('UPDATE MsCounter SET columnName = columnName + 1 WHERE key=?', ['Tim'], function(err) {});

Hector: how to delete a composite colums inside a row

I have composite columns on the column family Tags
RowKey: A
=> (column=B:C, value=432b442b492b4b2b552b582b592b7465787433, timestamp=1338402672044003)
=> (column=C:D, value=442b492b4b2b552b582b592b7465787433, timestamp=1338402672044004)
=> (column=E:T, value=492b582b592b5a2b5a5a2b5a5a5a2b7465787434, timestamp=1338402672049002)
How could I delete in row A, column (C:D) for example
it seems:
Mutator<String> mutator = HFactory.createMutator(ks, se);
mutator.addDeletion(..
takes only 2 arguments the row and the CF
for people interested it's as easy as their creation;
CompositeSerializer ce = new CompositeSerializer();
Composite c = new Composite();
c.add(0, "John");
c.add(1, "Connor");
mutator.addDeletion("key", "MyCF", c, ce);

Cassandra: How to create column in a super column family?

I am defining my database model in a schema file in order to easily create the keyspace and column families from scratch later on. I looked at the schema-sample.txt that comes with the Cassandra distribution and it shows how to create standard column families using the column_metadata such as this:
create column family User
with comparator = UTF8Type
and default_validation_class = UTF8Type
and column_metadata = [
{column_name : name, validation_class : UTF8Type}
{column_name : username, validation_class : UTF8Type}
{column_name : City, validation_class : UTF8Type}
];
But how can I use a similar syntax to create a super column family? I would like to define the column names of the super columns I will put in the super column family.
To create a Super Column Family you only need to add the column_type property:
create column family User
with column_type = 'Super'
and comparator = UTF8Type
and default_validation_class = UTF8Type;
You can't define the names of the super columns in the metadata. The metadata is used for either validating column values or creating indexes. Since you can't validate the value of a super column (the value is more columns) and you can't create indexes on super columns, there is no reason to set metadata for them.
You can create metadata about the sub columns with super columns but it will apply to all super columns in the row. For example:
create column family User
with column_type = 'Super'
and comparator = UTF8Type
and default_validation_class = UTF8Type
and column_metadata = [
{column_name : name, validation_class : UTF8Type}
{column_name : age, validation_class : LongType}
];
In this super column family any sub column called 'name' will have to be UTF8 and any sub column called age will have to be a long.

create super column and key

I not too familiar with creating a super column. Is column_type=Super the right way to assign Super1 as super column?
I could not get the id as index_type: KEYS to:
create column family Super1 with comparator=UTF8Type and
column_type=Super and key_validation_class=UTF8Type and
column_metadata = [
{column_name: id, validation_class:UTF8Type, index_type: KEYS},
{column_name: username, validation_class:UTF8Type},
{column_name: email, validation_class:UTF8Type}];
Please advice.
As found in \apache-cassandra-0.8.0\conf\schema-sample.txt:
create column family Super1
with column_type = Super
and comparator = BytesType
and subcomparator = BytesType;
create column family Super2
with column_type = Super
and subcomparator = UTF8Type
and rows_cached = 10000
and keys_cached = 50
and comment = 'A column family with supercolumns, whose column and subcolumn names are UTF8 strings';
create column family Super3
with column_type = Super
and comparator = LongType
and comment = 'A column family with supercolumns, whose column names are Longs (8 bytes)';
Three different examples to suit your needs...
You can't create column indexes on supercolumns.

Resources