Skip to content

Instantly share code, notes, and snippets.

View chbatey's full-sized avatar
🐯
WFH

Christopher Batey chbatey

🐯
WFH
View GitHub Profile
CREATE TABLE daily_aggregate_precip (
wsid text,
year int,
month int,
day int,
precipitation counter,
PRIMARY KEY ((wsid), year, month, day)
) WITH CLUSTERING ORDER BY (year DESC, month DESC, day DESC);
CREATE TABLE daily_aggregate_temperature (
wsid text,
year int,
month int,
day int,
high double,
low double,
mean double,
variance double,
stdev double,
@chbatey
chbatey / KillrWeatherRawData.cql
Created July 3, 2015 07:51
KillrWeather Raw data
CREATE TABLE raw_weather_data (
wsid text, // Composite of Air Force Datsav3 station number and NCDC WBAN number
year int, // Year collected
month int, // Month collected
day int, // Day collected
hour int, // Hour collected
temperature double, // Air temperature (degrees Celsius)
dewpoint double, // Dew point temperature (degrees Celsius)
pressure double, // Sea level pressure (hectopascals)
wind_direction int, // Wind direction in degrees. 0-359
CREATE FUNCTION state_group_and_total( state map<text, int>, type text, amount int )
CALLED ON NULL INPUT
RETURNS map<text, int>
LANGUAGE java AS '
Integer count = (Integer) state.get(type); if (count == null) count = amount; else count = count + amount; state.put(type, count); return state; ' ;
CREATE OR REPLACE AGGREGATE group_and_total(text, int)
SFUNC state_group_and_total
STYPE map<text, int>
CREATE OR REPLACE FUNCTION state_group_and_count( state map<text, int>, type text )
CALLED ON NULL INPUT
RETURNS map<text, int>
LANGUAGE java AS '
Integer count = (Integer) state.get(type); if (count == null) count = 1; else count++; state.put(type, count); return state; ' ;
CREATE OR REPLACE AGGREGATE group_and_count(text)
SFUNC state_group_and_count
STYPE map<text, int>
INITCOND {};
CREATE FUNCTION maxI(current int, candidate int)
CALLED ON NULL INPUT
RETURNS int LANGUAGE java AS
'if (current == null) return candidate; else return Math.max(current, candidate);' ;
CREATE AGGREGATE maxAgg(int)
SFUNC maxI
STYPE int
INITCOND null;
CREATE TABLE keyvalue(key text , value int );
INSERT INTO keyvalue (key, value ) VALUES ( 'chris', 5);
INSERT INTO keyvalue (key, value ) VALUES ( 'luke', 10);
INSERT INTO keyvalue (key, value ) VALUES ( 'patrick', 15);
INSERT INTO keyvalue (key, value ) VALUES ( 'haddad', 20);
import com.datastax.driver.core.*;
task buildSchema << {
Cluster cluster = Cluster.builder().addContactPoint("localhost").build()
Session session = cluster.connect()
new File("src/main/resources/schema/tables.cql").eachLine { line ->
println("Executing $line")
session.execute(line)
}
@chbatey
chbatey / build.gradle
Created March 17, 2015 16:34
build script dependencies
buildscript {
ext {
springBootVersion = '1.2.1.RELEASE'
cassandraDriverVersion = "2.1.4"
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
@Component
public class SpringConfiguringClass extends MetricsConfigurerAdapter {
@Inject
private Session session;
@Override
public MetricRegistry getMetricRegistry() {
return session.getCluster().getMetrics().getRegistry();
}