Skip to content

Instantly share code, notes, and snippets.

@chermehdi
Created December 21, 2018 18:16
Show Gist options
  • Save chermehdi/afafb07ac593234b9d759c4e35b618d5 to your computer and use it in GitHub Desktop.
Save chermehdi/afafb07ac593234b9d759c4e35b618d5 to your computer and use it in GitHub Desktop.

TP Cassendra

Exercice 1:

Création de la base resto_Fez :
CREATE KEYSPACE IF NOT EXISTS resto_Fez 
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor': 1};
# pour les requetes qui suivents 
use resto_Fez;
Création des Column Family:
# Création de la table restaurant, et les tables necessaires 
# pour modéliser les relations necessaires

CREATE TABLE Restaurant (
   id INT PRIMARY KEY,
   name TEXT,
   street TEXT,
   building_number INT,
   phone TEXT,
   cuisine_type text
 );

# Création de la table Inspection, et les tables necessaires 

CREATE TABLE Inspection (
   restaurant_id INT,
   inspection_date DATE, 
   violation_code TEXT,
   violation_description TEXT,
   score INT,
   grade TEXT,
   PRIMARY KEY ( restaurant_id, inspection_date )
 );

Exercice 2:

SELECT * FROM Restaurant;
SELECT name FROM Restaurant;
SELECT name, street FROM Restaurant WHERE id=412;
SELECT inspection_date, grade from Inspection WHERE restaurant_id=412;
SELECT name FROM Restaurant where cuisine_type=‘mexicaine’ ALLOW FILTERING;
SELECT name FROM Restaurant where street=‘Florence’ ALLOW FILTERING;
SELECT grade, score FROM Inspection WHERE restaurant_id=412
AND score >= 10 ALLOW FILTERING;
SELECT grade FROM Inspection WHERE score > 30 AND grade > '' ALLOW FILTERING;
SELECT count(*) FROM Inspection WHERE score > 30 AND grade > '' ALLOW FILTERING;
SELECT name FROM Restaurant WHERE token(id) > 400 LIMIT 3;
CREATE INDEX retaurant_name ON restaurant (name);
SELECT name FROM restaurant
WHERE id IN (SELECT restaurant_id FROM Inspection WHERE Grade >= ‘A’);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment