Skip to content

Instantly share code, notes, and snippets.

Tzach Livyatan tzach

Block or report user

Report or block tzach

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tzach
tzach / core.clj
Last active Jun 14, 2019
create a large cell in Scylla using Clojure alia
View core.clj
(ns cassandra-project.core
(:require [qbits.alia :as alia]))
(def cluster (alia/cluster {:contact-points ["172.17.0.2"]}))
(def session (alia/connect cluster))
(alia/execute session "USE mykeyspace;")
(dotimes [n 2000000]
(alia/execute session (str "UPDATE mykeyspace.gr SET link = link + {" n " : 'ABC'} WHERE id=1 AND r=1;")))
View Use emacs as Tmux
# install emacs
sudo yum install emacs -y
# run emacs as a daemon
emacs --daemon
# connect
export TERM=xterm-color
emacsclient -nw
# run shell
c-x shell
# reconnect after connection drop
@tzach
tzach / Demo Scylla Manager with Docker
Last active Jun 4, 2019
Running a demo of a 3 node Scylla cluster, Scylla Manager and Monitoring
View Demo Scylla Manager with Docker
# Start a Scylla cluster
########################
docker run --name some-scylla -d scylladb/scylla --smp 1 --memory 750M --overprovisioned 1 --api-address 0.0.0.0
# Do not use the above --api-address for production. Exposing API IP is not secure.
SEED=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' some-scylla)
echo $SEED
docker run --name some-scylla2 -d scylladb/scylla --smp 1 --memory 750M --overprovisioned 1 --api-address 0.0.0.0 --seeds="$SEED"
docker run --name some-scylla3 -d scylladb/scylla --smp 1 --memory 750M --overprovisioned 1 --api-address 0.0.0.0 --seeds="$SEED"
View CQL TTL Example
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
USE mykeyspace;
CREATE TABLE heartrate_ttl (
pet_chip_id uuid,
time timestamp,
heart_rate int,
PRIMARY KEY (pet_chip_id, time))
WITH default_time_to_live = 604800
ALTER TABLE heartrate_ttl WITH default_time_to_live = 3600;
View CQL Counter example
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
UPDATE cf SET my_counter = my_counter + 6 WHERE pk = 0;
SELECT * FROM cf;
View CQL MV Example
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;
CREATE TABLE buildings (name text, city text, height int, PRIMARY KEY (name));
CREATE MATERIALIZED VIEW building_by_city AS
SELECT * FROM buildings
WHERE city IS NOT NULL AND name IS NOT NULL
PRIMARY KEY(city, name);
INSERT INTO buildings(name,city,height) VALUES ('Burj Khalifa','Dubai',828);
INSERT INTO buildings(name,city,height) VALUES ('Shanghai Tower','Shanghai',632);
INSERT INTO buildings(name,city,height) VALUES ('Abraj Al-Bait Clock Tower','Mecca',601);
View Large Partitions Example
### First Try
CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
USE mykeyspace;
CREATE TABLE heartrate (
pet_chip_id uuid,
time timestamp,
heart_rate int,
PRIMARY KEY (pet_chip_id, time));
INSERT INTO heartrate(pet_chip_id, time, heart_rate) VALUES (123e4567-e89b-12d3-a456-426655440b23, '2019-03-04 07:01:00', 100);
View HiveSparkScylla_datasource.yaml
databases:
- allow_run_async: true
database_name: HiveSparkScylla
expose_in_sqllab: true
extra: "{\r\n \"metadata_params\": {},\r\n \"engine_params\": {}\r\n}\r\n"
sqlalchemy_uri: hive://172.17.0.3:10000/default
tables:
- columns:
- {avg: true, column_name: co_ppm, sum: true, type: INT}
- {column_name: sensor_id, filterable: true, groupby: true, type: STRING}
View data.cql
CREATE KEYSPACE IF NOT EXISTS mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
USE mykeyspace;
CREATE TABLE IF NOT EXISTS air_quality_data (sensor_id text,time timestamp,location text, co_ppm int,PRIMARY KEY (sensor_id, time));
INSERT INTO air_quality_data(sensor_id, time, location, co_ppm) VALUES ('my_home', '2018-06-05 07:01:00', 'ISR', 17);
INSERT INTO air_quality_data(sensor_id, time, location, co_ppm) VALUES ('my_home', '2018-06-06 07:02:01', 'ISR', 18);
INSERT INTO air_quality_data(sensor_id, time, location, co_ppm) VALUES ('my_home', '2018-06-07 07:03:02', 'ISR', 19);
INSERT INTO air_quality_data(sensor_id, time, location, co_ppm) VALUES ('my_home', '2018-06-08 07:04:03', 'ISR', 20);
INSERT INTO air_quality_data(sensor_id, time, location, co_ppm) VALUES ('my_home', '2018-06-09 07:05:04', 'ISR', 30);
INSERT INTO air_quality_data(sensor_id, time, location, co_ppm) VALUES ('my_home', '2018-06-10 07:06:04', 'ISR', 31);
INSERT INTO air_quality_data(sensor_id, time, loc
@tzach
tzach / scylla_spark_superset
Created May 30, 2018
Using Scylla with Spark, Hive and Superset
View scylla_spark_superset
### Scylla
docker run --name some-scylla -d scylladb/scylla:2.1.3
docker cp data.cql some-scylla:/data.cql
docker exec -it some-scylla cqlsh -f data.cql
### Spark
docker run -it -p 4040:4040 -p 8080:8080 -p 8081:8081 -p 10000:10000 -h spark --name=spark -d p7hb/docker-spark
docker exec -it spark /usr/local/spark-2.2.0-bin-hadoop2.7/sbin/start-thriftserver.sh \
--conf hive.server2.thrift.bind.host=0.0.0.0 \
--conf spark.cassandra.connection.host=172.17.0.2 \
You can’t perform that action at this time.