SlideShare ist ein Scribd-Unternehmen logo
1 von 12
CQL – CASSANDRA QUERY LANGUAGE




       Courtney Robinson – crlog.info
       @ Eric Evans (Python tests and CQL Spec)
THRIFT OR AVRO?

 External dependency
 Community activity dissipates

 Too generic

 Many user reported problems caused by Thrift or
  the misuse thereof...




    Its thrift!
    Its Avro!
    Its CQL....
WHAT IS IT?
   Effectively a structured query language

   Replacement for clients? Not really...

   Attempting to push as much server-side as possible

   Familiar syntax

   User friendly API for Cassandra new comers
CQL V1.0.0 - KEYWORDS
 USE
 SELECT
                         That’s right!
 UPDATE

 DELETE
                        No INSERT...?
 TRUNCATE

 DROP

 BATCH
          SPECIAL STATEMENTS
 CREATE KEYSPACE
 CREATE COLUMNFAMILY

 CREATE INDEX
SPECIFYING CONSISTENCY
   ... USING <CONSISTENCY> ...

   Made up of the keyword USING, followed by a consistency level identifier.

   Valid consistency levels are:

   CONSISTENCY ZERO

   CONSISTENCY ONE (default)

   CONSISTENCY QUORUM

   CONSISTENCY ALL

   CONSISTENCY DCQUORUM

   CONSISTENCY DCQUORUMSYNC

   E.g BEGIN BATCH USING CONSISTENCY ONE
CREATE KEYSPCE
   CREATE KEYSPACE WITH replication_factor = AND strategy_class = [AND
    strategy_options. = [AND strategy_options. = ]];


   E.g CREATE KEYSPACE TestKeyspace WITH strategy_options:DC1 = '1‘ AND
    strategy_class = 'NetworkTopologyStrategy‘



                       CREATE COLUMN FAMILY
   CREATE COLUMNFAMILY [(name1 type, name2 type, ...)] [WITH keyword1 = arg1 [AND
    keyword2 = arg2 [AND ...]]];

                                 Set column type:
   CREATE COLUMNFAMILY (name1 type, name2 type) ...;



                       CREATE INDEX
   CREATE INDEX [index_name] ON <column_family> (column_name);


   Used to create a new, automatic secondary index for the named column.
USE
   USE <KEYSPACE>;
   Use keyword followed by a valid Keyspace name
   Set working Keyspace per-connection


                      DROP
   DROP <KEYSPACE|COLUMNFAMILY>;
   DROP KEYSPACE KSName;
   DROP COLUMNFAMILY CFName;
    Immediate, irreversible removal of keyspace and column family
    namespaces.


                    TRUNCATE
   TRUNCATE <COLUMN FAMILY>
   Accepts a single argument (CF) name
   permanently removes all data from said column family.
UPDATE (values)
   UPDATE [USING CONSISTENCY ]
    SET name1 = value1, name2 = value2 WHERE KEY = keyname;

   UPDATE is used to write one or more columns to a record in a Cassandra
    column family.

   No results are returned.


 Creates        or updates rows

   UPDATE CFName SET ‘name' = 10 WHERE KEY = ‘1234’

   UPDATE <COLUMN FAMILY> ...

   Begin with the UPDATE keyword followed by CF name.

   Followed by an optional consistency level specification.
BATCH UPDATES
   Where‟s my batch mutate gone?
   Similar to code blocks/structs
   Has begining (Begin Batch) and end (Apply Batch)

BEGIN BATCH [USING ]
UPDATE CF1 SET name1 = value1, name2 = value2 WHERE KEY = keyname1;
UPDATE CF1 SET name3 = value3 WHERE KEY = keyname2;
UPDATE CF2 SET name4 = value4, name5 = value5 WHERE KEY = keyname3;
APPLY BATCH

   BEGIN BATCH USING CONSISTENCY QUORUM
       UPDATE CFname SET 1='1', 2='2', 3='3', 4='4' WHERE KEY='aa‘
       UPDATE CFname2 SET 5='5', 6='6', 7='8', 9='9' WHERE KEY='ab'
       UPDATE CFname SET 9='9', 8='8', 7='7', 6='6' WHERE KEY='ac'
       UPDATE CFname3 SET 5='5', 4='4', 3='3', 2='2' WHERE KEY='ad'
       UPDATE CFname SET 1='1', 2='2', 3='3', 4='4' WHERE KEY='ae'

   APPLY BATCH
DELETE
   DELETE [COLUMNS] FROM [USING ] WHERE KEY =
    keyname1

   DELETE [COLUMNS] FROM [USING ] WHERE KEY IN
    (keyname1, keyname2);

o   Remove one or more columns from one or more rows.

o   Optional comma-delimited list of column names following
    DELETE

o   Removes entire row(s) if no columns are specified

o   DELETE „col1', 'col2' FROM CF WHERE KEY = 'key„
o
    DELETE „col1', 'col2' FROM CF WHERE KEY = ('key„, „key2‟,
    „key3‟)
SELECT
   SELECT [FIRST N] [REVERSED] <SELECT EXPR> FROM <COLUMN FAMILY>
    [USING <CONSISTENCY>] [WHERE <CLAUSE>] [LIMIT N];
   FIRST = number of columns, N
   REVERSED = Reverses sort order


   Return a result set, key + columns per row


                                        Specify columns:
   SELECT [FIRST N] [REVERSED] name1, name2, name3 FROM ...


                                    Request a range of columns:
   SELECT [FIRST N] [REVERSED] name1..nameN FROM ...


   “..” Notation specifies range
   Inclusive of start and end columns


   E.g SELECT FIRST 2 REVERSED 3..1 FROM CF WHERE KEY = 'aa'
COURTNEY ROBINSON @ZCOURTS


           Thank you for listening.


           Questions?
                               Links:
  http://crlog.info/2011/03/29/cassandra-query-language-aka-cql-syntax/
 https://svn.apache.org/viewvc/cassandra/trunk/doc/cql/CQL.html?view=co
        https://issues.apache.org/jira/browse/CASSANDRA-1703

Weitere ähnliche Inhalte

Kürzlich hochgeladen

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Kürzlich hochgeladen (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Cql cassandra query language

  • 1. CQL – CASSANDRA QUERY LANGUAGE Courtney Robinson – crlog.info @ Eric Evans (Python tests and CQL Spec)
  • 2. THRIFT OR AVRO?  External dependency  Community activity dissipates  Too generic  Many user reported problems caused by Thrift or the misuse thereof... Its thrift! Its Avro! Its CQL....
  • 3. WHAT IS IT?  Effectively a structured query language  Replacement for clients? Not really...  Attempting to push as much server-side as possible  Familiar syntax  User friendly API for Cassandra new comers
  • 4. CQL V1.0.0 - KEYWORDS  USE  SELECT That’s right!  UPDATE  DELETE No INSERT...?  TRUNCATE  DROP  BATCH SPECIAL STATEMENTS  CREATE KEYSPACE  CREATE COLUMNFAMILY  CREATE INDEX
  • 5. SPECIFYING CONSISTENCY  ... USING <CONSISTENCY> ...  Made up of the keyword USING, followed by a consistency level identifier.  Valid consistency levels are:  CONSISTENCY ZERO  CONSISTENCY ONE (default)  CONSISTENCY QUORUM  CONSISTENCY ALL  CONSISTENCY DCQUORUM  CONSISTENCY DCQUORUMSYNC  E.g BEGIN BATCH USING CONSISTENCY ONE
  • 6. CREATE KEYSPCE  CREATE KEYSPACE WITH replication_factor = AND strategy_class = [AND strategy_options. = [AND strategy_options. = ]];  E.g CREATE KEYSPACE TestKeyspace WITH strategy_options:DC1 = '1‘ AND strategy_class = 'NetworkTopologyStrategy‘ CREATE COLUMN FAMILY  CREATE COLUMNFAMILY [(name1 type, name2 type, ...)] [WITH keyword1 = arg1 [AND keyword2 = arg2 [AND ...]]]; Set column type:  CREATE COLUMNFAMILY (name1 type, name2 type) ...; CREATE INDEX  CREATE INDEX [index_name] ON <column_family> (column_name);  Used to create a new, automatic secondary index for the named column.
  • 7. USE  USE <KEYSPACE>;  Use keyword followed by a valid Keyspace name  Set working Keyspace per-connection DROP  DROP <KEYSPACE|COLUMNFAMILY>;  DROP KEYSPACE KSName;  DROP COLUMNFAMILY CFName; Immediate, irreversible removal of keyspace and column family namespaces. TRUNCATE  TRUNCATE <COLUMN FAMILY>  Accepts a single argument (CF) name  permanently removes all data from said column family.
  • 8. UPDATE (values)  UPDATE [USING CONSISTENCY ] SET name1 = value1, name2 = value2 WHERE KEY = keyname;  UPDATE is used to write one or more columns to a record in a Cassandra column family.  No results are returned.  Creates or updates rows  UPDATE CFName SET ‘name' = 10 WHERE KEY = ‘1234’  UPDATE <COLUMN FAMILY> ...  Begin with the UPDATE keyword followed by CF name.  Followed by an optional consistency level specification.
  • 9. BATCH UPDATES  Where‟s my batch mutate gone?  Similar to code blocks/structs  Has begining (Begin Batch) and end (Apply Batch) BEGIN BATCH [USING ] UPDATE CF1 SET name1 = value1, name2 = value2 WHERE KEY = keyname1; UPDATE CF1 SET name3 = value3 WHERE KEY = keyname2; UPDATE CF2 SET name4 = value4, name5 = value5 WHERE KEY = keyname3; APPLY BATCH  BEGIN BATCH USING CONSISTENCY QUORUM UPDATE CFname SET 1='1', 2='2', 3='3', 4='4' WHERE KEY='aa‘ UPDATE CFname2 SET 5='5', 6='6', 7='8', 9='9' WHERE KEY='ab' UPDATE CFname SET 9='9', 8='8', 7='7', 6='6' WHERE KEY='ac' UPDATE CFname3 SET 5='5', 4='4', 3='3', 2='2' WHERE KEY='ad' UPDATE CFname SET 1='1', 2='2', 3='3', 4='4' WHERE KEY='ae'  APPLY BATCH
  • 10. DELETE  DELETE [COLUMNS] FROM [USING ] WHERE KEY = keyname1  DELETE [COLUMNS] FROM [USING ] WHERE KEY IN (keyname1, keyname2); o Remove one or more columns from one or more rows. o Optional comma-delimited list of column names following DELETE o Removes entire row(s) if no columns are specified o DELETE „col1', 'col2' FROM CF WHERE KEY = 'key„ o DELETE „col1', 'col2' FROM CF WHERE KEY = ('key„, „key2‟, „key3‟)
  • 11. SELECT  SELECT [FIRST N] [REVERSED] <SELECT EXPR> FROM <COLUMN FAMILY> [USING <CONSISTENCY>] [WHERE <CLAUSE>] [LIMIT N];  FIRST = number of columns, N  REVERSED = Reverses sort order  Return a result set, key + columns per row Specify columns:  SELECT [FIRST N] [REVERSED] name1, name2, name3 FROM ... Request a range of columns:  SELECT [FIRST N] [REVERSED] name1..nameN FROM ...  “..” Notation specifies range  Inclusive of start and end columns  E.g SELECT FIRST 2 REVERSED 3..1 FROM CF WHERE KEY = 'aa'
  • 12. COURTNEY ROBINSON @ZCOURTS Thank you for listening. Questions? Links: http://crlog.info/2011/03/29/cassandra-query-language-aka-cql-syntax/ https://svn.apache.org/viewvc/cassandra/trunk/doc/cql/CQL.html?view=co https://issues.apache.org/jira/browse/CASSANDRA-1703

Hinweis der Redaktion

  1. http://wiki.apache.org/cassandra/API#StructuresWritesLevelBehaviorANYEnsure that the write has been written to at least 1 node, including HintedHandoff recipients.ONEEnsure that the write has been written to at least 1 replica&apos;s commit log and memory table before responding to the client.QUORUMEnsure that the write has been written to N / 2 + 1 replicas before responding to the client.LOCAL_QUORUMEnsure that the write has been written to &lt;ReplicationFactor&gt; / 2 + 1 nodes, within the local datacenter (requires NetworkTopologyStrategy)EACH_QUORUMEnsure that the write has been written to &lt;ReplicationFactor&gt; / 2 + 1 nodes in each datacenter (requires NetworkTopologyStrategy)ALLEnsure that the write is written to all N replicas before responding to the client. Any unresponsive replicas will fail the operation.ReadsLevelBehaviorANYNot supported. You probably want ONE instead.ONEWill return the record returned by the first replica to respond. A consistency check is always done in a background thread to fix any consistency issues whenConsistencyLevel.ONE is used. This means subsequent calls will have correct data even if the initial read gets an older value. (This is called ReadRepair)QUORUMWill query all replicas and return the record with the most recent timestamp once it has at least a majority of replicas (N / 2 + 1) reported. Again, the remaining replicas will be checked in the background.LOCAL_QUORUMReturns the record with the most recent timestamp once a majority of replicas within the local datacenter have replied.EACH_QUORUMReturns the record with the most recent timestamp once a majority of replicas within each datacenter have replied.ALLWill query all replicas and return the record with the most recent timestamp once all replicas have replied. Any unresponsive replicas will fail the operation.
  2. The CREATE KEYSPACE statement creates a new top-level namespace (aka “keyspace”). Valid names are any string constructed of alphanumeric characters and underscores, but must begin with a letter. Properties such as replication strategy and count are specified during creation using the following accepted keyword arguments:Keywordrequireddescriptionreplication_factor yes Numeric argument that specifies the number of replicas for this keyspace.strategy_class yes Class name to use for managing replica placement. Any of the shipped strategies can be used by specifying the class name relative to org.apache.cassandra.locator, others will need to be fully-qualified and located on the classpath.strategy_options no Some strategies require additional arguments which can be supplied by appending the option name to the strategy_options keyword, separated by a colon (:). For example, a strategy option of “DC1″ with a value of “1″ would be specified as strategy_options:DC1 = 1.Synopsis:CREATE COLUMNFAMILY [(name1 type, name2 type, ...)] [WITH keyword1 = arg1 [AND keyword2 = arg2 [AND ...]]]; CREATE COLUMNFAMILY statements create new column family namespaces under the current keyspace. Valid column family names are strings of alphanumeric characters and underscores, which begin with a letter.Specifying Column Type (optional)CREATE COLUMNFAMILY (name1 type, name2 type) ...; It is possible to assign columns a type during column family creation. Columns configured with a type are validated accordingly when a write occurs. Column types are specified as a parenthesized, comma-separated list of column term and type pairs. The list of recognized types are:Type descriptionBytes Arbitrary bytes (no validation)AsciiASCII character stringUtf8 UTF8 encoded stringTimeuuid Type 1 UUIDUuid Type 4 UUIDInt 4-byte integerLong 8-byte longNote: In addition to the recognized types listed above, it is also possible to supply a string containing the name of a class (a sub-class of AbstractType), either fully qualified, or relative to theorg.apache.cassandra.db.marshalpackage.Column Family Options (optional)CREATE COLUMNFAMILY ... WITH keyword1 = arg1 AND keyword2 = arg2; A number of optional keyword arguments can be supplied to control the configuration of a new column family.Keyword default descriptionComparator utf8 Determines sorting and validation of column names. Valid values are identical to the types listed in Specifying Column Type above.Comment none A free-form, human-readable comment.row_cache_size 0 Number of rows whose entire contents to cache in memory.key_cache_size 200000 Number of keys per SSTable whose locations are kept in memory in “mostly LRU” order.read_repair_chance 1.0 The probability with which read repairs should be invoked on non-quorum reads.gc_grace_seconds 864000 Time to wait before garbage collecting tombstones (deletion markers).default_validation utf8 Determines validation of column values. Valid values are identical to the types listed in Specifying Column Type above.min_compaction_threshold 4 Minimum number of SSTables needed to start a minor compaction.max_compaction_threshold 32 Maximum number of SSTables allowed before a minor compaction is forced.row_cache_save_period_in_seconds 0 Number of seconds between saving row caches.key_cache_save_period_in_seconds 14400 Number of seconds between saving key caches.memtable_flush_after_mins 60 Maximum time to leave a dirty table unflushed.memtable_throughput_in_mb dynamic Maximum size of the memtable before it is flushed.memtable_operations_in_millions dynamic Number of operations in millions before the memtable is flushed.replicate_on_write false
  3. Synopsis:USE &lt;KEYSPACE&gt;; A USE statement consists of the USE keyword, followed by a valid keyspace name. Its purpose is to assign the per-connection, current working keyspace. All subsequent keyspace-specific actions will be performed in the context of the supplied value.Synopsis:DROP &lt;KEYSPACE|COLUMNFAMILY&gt; namespace; DROP statements result in the immediate, irreversible removal of keyspace and column family namespaces.
  4. Synopsis:UPDATE [USING CONSISTENCY ] SET name1 = value1, name2 = value2 WHERE KEY = keyname; An UPDATE is used to write one or more columns to a record in a Cassandra column family. No results are returned.Column FamilyUPDATE &lt;COLUMN FAMILY&gt; ... Statements begin with the UPDATE keyword followed by a Cassandra column family name.Consistency LevelUPDATE ... [USING &lt;CONSISTENCY&gt;] ... Following the column family identifier is an optional consistency level specification.Specifying Columns and RowUPDATE ... SET name1 = value1, name2 = value2 WHERE KEY = keyname; Rows are created or updated by supplying column names and values in term assignment format. Multiple columns can be set by separating the name/value pairs using commas. Each update statement requires exactly one key to be specified using a WHERE clause and the KEY keyword.Additionally, it is also possible to send multiple UPDATES to a node at once using a batch syntax:BEGIN BATCH [USING ] UPDATE CF1 SET name1 = value1, name2 = value2 WHERE KEY = keyname1; UPDATE CF1 SET name3 = value3 WHERE KEY = keyname2; UPDATE CF2 SET name4 = value4, name5 = value5 WHERE KEY = keyname3; APPLY BATCH When batching UPDATEs, a single consistency level is used for the entire batch, it appears after the BEGIN BATCHstatement, and uses the standard consistency level specification. Batch UPDATEs default toCONSISTENCY.ONEwhen left unspecified.NOTE: While there are no isolation guarantees, UPDATE queries are atomic within a give record.
  5. Synopsis:DELETE [COLUMNS] FROM [USING ] WHERE KEY = keyname1 DELETE [COLUMNS] FROM [USING ] WHERE KEY IN (keyname1, keyname2); A DELETE is used to perform the removal of one or more columns from one or more rows.Specifying ColumnsDELETE [COLUMNS] ... Following the DELETE keyword is an optional comma-delimited list of column name terms. When no column names are specified, the remove applies to the entire row(s) matched by the WHERE clauseColumn FamilyDELETE ... FROM &lt;COLUMN FAMILY&gt; ... The column family name follows the list of column names.Consistency LevelUPDATE ... [USING &lt;CONSISTENCY&gt;] ... Following the column family identifier is an optional consistency level specification.Specifying RowsUPDATE ... WHERE KEY = keyname1 UPDATE ... WHERE KEY IN (keyname1, keyname2) The WHERE clause is used to determine which row(s) a DELETE applies to. The first form allows the specification of a single keyname using the KEY keyword and the = operator. The second form allows a list of keyname terms to be specified using the IN notation and a parenthesized list of comma-delimited keyname terms.
  6. Synopsis:SELECT [FIRST N] [REVERSED] &lt;SELECT EXPR&gt; FROM &lt;COLUMN FAMILY&gt; [USING &lt;CONSISTENCY&gt;] [WHERE &lt;CLAUSE&gt;] [LIMIT N]; A SELECT is used to read one or more records from a Cassandra column family. It returns a result-set of rows, where each row consists of a key and a collection of columns corresponding to the query.Specifying ColumnsSELECT [FIRST N] [REVERSED] name1, name2, name3 FROM ... SELECT [FIRST N] [REVERSED] name1..nameN FROM ... The SELECT expression determines which columns will appear in the results and takes the form of either a comma separated list of names, or a range. The range notation consists of a start and end column name separated by two periods (..). The set of columns returned for a range is start and end inclusive.The FIRST option accepts an integer argument and can be used to apply a limit to the number of columns returned per row. When this limit is left unset it defaults to 10,000 columns.The REVERSED option causes the sort order of the results to be reversed.It is worth noting that unlike the projection in a SQL SELECT, there is no guarantee that the results will contain all of the columns specified. This is because Cassandra is schema-less and there are no guarantees that a given column exists.Column FamilySELECT ... FROM &lt;COLUMN FAMILY&gt; ... The FROM clause is used to specify the Cassandra column family applicable to a SELECT query.Consistency LevelSELECT ... [USING &lt;CONSISTENCY&gt;] ... Following the column family clause is an optional consistency level specification.Filtering rowsSELECT ... WHERE KEY = keyname AND name1 = value1 SELECT ... WHERE KEY &gt;= startkey and KEY =&lt; endkey AND name1 = value1 The WHERE clause provides for filtering the rows that appear in results. The clause can filter on a key name, or range of keys, and in the case of indexed columns, on column values. Key filters are specified using the KEYkeyword, a relational operator, (one of =, &gt;, &gt;=, &lt;, and &lt;=), and a term value. When terms appear on both sides of a relational operator it is assumed the filter applies to an indexed column. With column index filters, the term on the left of the operator is the name, the term on the right is the value to filter on.Note: The greater-than and less-than operators (&gt; and &lt;) result in key ranges that are inclusive of the terms. There is no supported notion of “strictly” greater-than or less-than; these operators are merely supported as aliases to &gt;=and &lt;=.LimitsSELECT ... WHERE &lt;CLAUSE&gt; [LIMIT N] ... Limiting the number of rows returned can be achieved by adding the LIMIT option to a SELECT expression. LIMITdefaults to 10,000 when left unset.