cqlsh> CREATE KEYSPACE cbd WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'}; #replication: replicacoes em nos, para disponibilidade e fault tolerance cqlsh> DESCRIBE KEYSPACE cbd; CREATE KEYSPACE cbd WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true; cqlsh> USE cbd; cqlsh:cbd> CREATE TABLE alunos ( id_aluno UUID PRIMARY KEY, nome text, sobrenome text, contactos set, endereco map, registro_em timestamp ); cqlsh:cbd> DESCRIBE TABLE alunos; CREATE TABLE cbd.alunos ( id_aluno uuid PRIMARY KEY, nome text, registro_em timestamp, sobrenome text, contactos set, endereco map ) WITH additional_write_policy = '99p' AND bloom_filter_fp_chance = 0.01 AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'} AND cdc = false AND comment = '' AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'} AND compression = {'chunk_length_in_kb': '16', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'} AND memtable = 'default' AND crc_check_chance = 1.0 AND default_time_to_live = 0 AND extensions = {} AND gc_grace_seconds = 864000 AND max_index_interval = 2048 AND memtable_flush_period_in_ms = 0 AND min_index_interval = 128 AND read_repair = 'BLOCKING' AND speculative_retry = '99p'; cqlsh:cbd> SELECT * from alunos; id_aluno | contactos | endereco | nome | registro_em | sobrenome ------------+-----------+----------+------+-------------+----------- (0 rows) cqlsh:cbd> INSERT INTO alunos (id_aluno, nome, sobrenome, contactos, endereco, registro_em) VALUES (uuid(), 'Ana', 'Loureiro', {'ana.sl@ua.pt'}, {'rua': 'Rua Calouste Gulbenkian', 'cidade': 'Aveiro'}, toTimestamp(now())); cqlsh:cbd> SELECT * FROM alunos; id_aluno | contactos | endereco | nome | registro_em | sobrenome --------------------------------------+------------------+--------------------------------------------------------+------+---------------------------------+----------- 0ae479a0-7716-46b7-9e16-ed0716c2ff88 | {'ana.sl@ua.pt'} | {'cidade': 'Aveiro', 'rua': 'Rua Calouste Gulbenkian'} | Ana | 2024-11-04 16:10:58.916000+0000 | Loureiro cqlsh:cbd> UPDATE alunos SET contactos = contactos + {'ana.wk.lsl@gmail.com'} WHERE id_aluno = 0ae479a0-7716-46b7-9e16-ed0716c2ff88; cqlsh:cbd> SELECT contactos FROM alunos WHERE id_aluno = 0ae479a0-7716-46b7-9e16-ed0716c2ff88; contactos ------------------------------------------ {'ana.sl@ua.pt', 'ana.wk.lsl@gmail.com'} cqlsh:cbd> DELETE FROM alunos WHERE id_aluno = 0ae479a0-7716-46b7-9e16-ed0716c2ff88; cqlsh:cbd> SELECT * FROM alunos; id_aluno | contactos | endereco | nome | registro_em | sobrenome ----------+-----------+----------+------+-------------+----------- cqlsh:cbd> INSERT INTO alunos (id_aluno, nome, sobrenome) VALUES (uuid(), 'Tiago', 'Guimaraes') USING TTL 60; cqlsh:cbd> SELECT TTL(nome) FROM alunos WHERE nome = 'Tiago' AND sobrenome = 'Guimaraes'; #InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING" cqlsh:cbd> SELECT TTL(nome) FROM alunos WHERE nome = 'Tiago' AND sobrenome = 'Guimaraes' ALLOW FILTERING; ttl(nome) ----------- 12 cqlsh:cbd> DROP table alunos; cqlsh:cbd> SELECT * FROM alunos; #InvalidRequest: Error from server: code=2200 [Invalid query] message="table alunos does not exist"