Monday, November 15, 2021

Apache Cassandra with Ubuntu 20.04

Apache Cassandra with docker.

1.     Installed from docker 

    $    docker pull cassandra:latest

    $   docker run --name you_cass_cluster cassandra:latest

    $   docker ps


    

$   docker exec -it you_cass_cluster cqlsh

    



    

2.    Supported Data Types.

Supported Data Types
CQL TypeDescription
asciiUS-ASCII character string
bigint64-bit signed long
blobArbitrary bytes (no validation), expressed as hexadecimal
booleantrue or false
counterDistributed counter value (64-bit long)
decimalVariable-precision decimal
double64-bit IEEE-754 floating point
float32-bit IEEE-754 floating point
int32-bit signed integer
textUTF-8 encoded string
timestampDate plus time, encoded as 8 bytes since epoch
uuidType 1 or type 4 UUID
timeuuidType 1 UUID only (CQL3)
varcharUTF-8 encoded string
varintArbitrary-precision integer


3.    Created on KEYSPACES with next command.

        CREATE KEYSPACE test_kesypace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = 'true';

4.     Created Tables 

    use test_kesypace;

    CREATE TABLE employee_by_id

  (
     id       INT PRIMARY KEY,
     name     TEXT,
     position TEXT
  ); 

CREATE TABLE employee_by_car_make
  (
     car_make  TEXT,
     id        INT,
     car_model TEXT,
     PRIMARY KEY(car_make, id)

  );    

CREATE TABLE employee_by_car_make_sorted
  (
     car_make TEXT,
     age      INT,
     id       INT,
     name     TEXT,
     PRIMARY KEY(car_make, age, id)
  ); 

CREATE TABLE employee_by_car_make_and_model
             (
                          car_make TEXT,
                          car_model TEXT,
                          id INT,
                          name TEXT,
                          PRIMARY KEY((car_make, car_model), id)
             );

5.     Insert and update

INSERT INTO employee_by_id
            (id,
             name,
             position)
VALUES      ( 1,
             'Henry',
             'Developer'); 


UPDATE employee_by_car_make
using  ttl 60
SET    car_model = 'Truck'
WHERE  car_make ='TOYOTA'
AND    id = 1;

6. SELECT 

Cassandra DB just search by id.

SELECT *
FROM   employee_by_id
WHERE  id = 1; 


            






References:

https://www.youtube.com/channel/UCHRnRlWQuZYDmnuB7SbXIpQ



        


No comments:

Post a Comment

Creating REST APIs with OpenAPI, Spring Boot 3.3.3, Java 21, and Jakarta

 Introduction In today's software landscape, designing robust and scalable REST APIs is a crucial aspect of application development. Wit...