CREATE KEYSPACE IF NOT EXISTS balboa WITH REPLICATION = { 
   'class' : 'SimpleStrategy', 
   'replication_factor' : 2 
};

CREATE TABLE balboa.observations_by_rdata (
    rrname text,
    rdata text,
    rrtype text,
    sensor_id text,
    last_seen timestamp,
    PRIMARY KEY (rdata, rrname, rrtype, sensor_id)
);
CREATE CUSTOM INDEX ON balboa.observations_by_rdata (rrname) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {
   'analyzed' : 'true', 
   'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 
   'case_sensitive' : 'false', 
   'mode' : 'CONTAINS' 
}; 
ALTER TABLE balboa.observations_by_rdata
WITH COMPRESSION = {'sstable_compression': 'LZ4Compressor',
                    'chunk_length_kb': 64};

CREATE TABLE balboa.observations_by_rrname (
    rrname text,
    rdata text,
    rrtype text,
    sensor_id text,
    last_seen timestamp,
    PRIMARY KEY (rrname, rdata, rrtype, sensor_id)
);
CREATE CUSTOM INDEX ON balboa.observations_by_rrname (rdata) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = {
   'analyzed' : 'true', 
   'analyzer_class' : 'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', 
   'case_sensitive' : 'false', 
   'mode' : 'CONTAINS' 
};
ALTER TABLE balboa.observations_by_rrname
WITH COMPRESSION = {'sstable_compression': 'LZ4Compressor',
                    'chunk_length_kb': 64};

CREATE TABLE balboa.observations_counts (
    rrname text,
    rdata text,
    rrtype text,
    sensor_id text,
    count counter,
    PRIMARY KEY (rrname, rdata, rrtype, sensor_id)
);
ALTER TABLE balboa.observations_counts
WITH COMPRESSION = {'sstable_compression': 'LZ4Compressor',
                    'chunk_length_kb': 64};

CREATE TABLE balboa.observations_firstseen (
    rrname text,
    rdata text,
    rrtype text,
    sensor_id text,
    first_seen timestamp,
    PRIMARY KEY (rrname, rdata, rrtype, sensor_id)
);
ALTER TABLE balboa.observations_firstseen
WITH COMPRESSION = {'sstable_compression': 'LZ4Compressor',
                    'chunk_length_kb': 64};
