Skip to content

Instantly share code, notes, and snippets.

@alexott
Created February 22, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexott/98337bf651294902afeff09882758ae7 to your computer and use it in GitHub Desktop.
Save alexott/98337bf651294902afeff09882758ae7 to your computer and use it in GitHub Desktop.
cqlsh:test> DESCRIBE table log;
CREATE TABLE test.log (
module text,
yyyymmdd text,
created timeuuid,
logmessage text,
PRIMARY KEY ((module, yyyymmdd), created)
) WITH CLUSTERING ORDER BY (created ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_thresho
ld': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';
CREATE MATERIALIZED VIEW test.log_mv AS
SELECT yyyymmdd, module, created, logmessage
FROM test.log
WHERE yyyymmdd IS NOT NULL AND module IS NOT NULL AND created IS NOT NULL
PRIMARY KEY ((yyyymmdd, module), created)
WITH CLUSTERING ORDER BY (created ASC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
AND comment = ''
AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 864000
AND max_index_interval = 2048
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99PERCENTILE';
>node test.js 12:56 130
Obtained result after table: ResultSet {
info:
{ queriedHost: '192.168.0.10:9042',
triedHosts:
{ '172.19.0.3:9042': 'Host considered as DOWN',
'172.19.0.2:9042': 'Host considered as DOWN',
'192.168.0.10:9042': null },
speculativeExecutions: 0,
achievedConsistency: 10,
traceId: undefined,
warnings: undefined,
customPayload: undefined },
rows: undefined,
rowLength: undefined,
columns: null,
pageState: null,
nextPage: undefined }
Obtained result after MV: ResultSet {
info:
{ queriedHost: '192.168.0.10:9042',
triedHosts:
{ '172.19.0.2:9042': 'Host considered as DOWN',
'192.168.0.10:9042': null },
speculativeExecutions: 0,
achievedConsistency: 10,
traceId: undefined,
warnings: undefined,
customPayload: undefined },
rows: undefined,
rowLength: undefined,
columns: null,
pageState: null,
nextPage: undefined }
"use strict";
const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['192.168.0.10']});
client.connect()
.then(function () {
return client.execute('CREATE TABLE test.log(yyyymmdd varchar, created timeuuid, logMessage text, module text, PRIMARY KEY((module,yyyymmdd), created));');
})
.then(function (result) {
console.log('Obtained result after table: ', result);
return client.execute('create MATERIALIZED VIEW test.log_mv AS SELECT yyyymmdd,module,created,logmessage FROM test.log where yyyymmdd is not null and module is not null and created is not null PRIMARY KEY ((yyyymmdd,module),created);');
})
.then(function (result) {
console.log('Obtained result after MV: ', result);
return client.shutdown();
})
.catch(function (err) {
console.error('There was an error when connecting', err);
return client.shutdown();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment