{"id":20911512,"url":"https://github.com/anant/example-cql-arithmetic-operators","last_synced_at":"2026-04-14T01:31:32.889Z","repository":{"id":112529275,"uuid":"490825736","full_name":"Anant/example-cql-arithmetic-operators","owner":"Anant","description":"CQL Arithmetic Operators are now supported in Cassandra 4.0!","archived":false,"fork":false,"pushed_at":"2022-05-11T19:31:27.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-12-31T17:52:51.160Z","etag":null,"topics":["cassandra","cql","docker","gitpod"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Anant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-10T19:00:14.000Z","updated_at":"2022-08-03T19:37:11.000Z","dependencies_parsed_at":"2023-05-15T17:00:34.916Z","dependency_job_id":null,"html_url":"https://github.com/Anant/example-cql-arithmetic-operators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Anant/example-cql-arithmetic-operators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anant%2Fexample-cql-arithmetic-operators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anant%2Fexample-cql-arithmetic-operators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anant%2Fexample-cql-arithmetic-operators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anant%2Fexample-cql-arithmetic-operators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Anant","download_url":"https://codeload.github.com/Anant/example-cql-arithmetic-operators/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Anant%2Fexample-cql-arithmetic-operators/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31778580,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T00:11:49.126Z","status":"ssl_error","status_checked_at":"2026-04-14T00:10:29.837Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra","cql","docker","gitpod"],"created_at":"2024-11-18T14:22:13.275Z","updated_at":"2026-04-14T01:31:32.865Z","avatar_url":"https://github.com/Anant.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# CQL Arithmetic Operators\nCQL Arithmetic Operators are now supported in Cassandra 4.0! In this walkthrough, we will show you some examples of how you can use the now supported CQL arithmetic operators.\n\n**We recommend going through this walkthrough in [Gitpod](https://gitpod.io/) as Gitpod will have everything we need for this walkthrough. Hit the button below to get started!**\n\u003c/br\u003e\n\u003c/br\u003e\n[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Anant/example-CQL-arithmetic-operators) \n\u003c/br\u003e\n\u003c/br\u003e\n\nOtherwise, the walkthrough can be followed via Docker!\n\n## **1. Cassandra**\n\n### 1.1 - Run Cassandra\nWe can run Docker on Gitpod, but as mentioned above, you can run this demo using your local Docker as well.\n\n**1.1.1 - Start Cassandra.**\n\n```bash\ndocker run --name cassandra -p 9042:9042 -d cassandra:latest\n```\n**If running on Gitpod, remember to make the 9042 port public when the dialog shows up on the bottom right-hand corner**\n\n**1.1.2 - Copy CQL File to Container**\n\n```bash\ndocker cp /workspace/example-CQL-arithmetic-operators/stats.cql cassandra:/\n```\n\n**1.1.3 - Run CQL File**\n\n```bash\ndocker exec -it cassandra cqlsh -f /stats.cql\n```\n\n### **1.2 - Start CQLSH.**\n\n```bash\ndocker exec -it cassandra cqlsh \n```\n\n## **2. Addition Operator**\nAt the time of creating this repo, the 2022 MLB season has just started up. Nowadays, data is heavily ingrained into professional sports, but baseball especially with [Sabermetrics](https://en.wikipedia.org/wiki/Sabermetrics) (list of just [offensive statistics](https://library.fangraphs.com/offense/offensive-statistics-list/))\n\n### **2.1 - Calculate OPS**\n```bash\nselect season, slg, obp, slg + obp as \"ops\" from demo.jeter_world_series_stats ;\n```\n\n## **3. Subtraction Operator**\n\n### **3.1 - Calculate At Bats**\n```bash\nselect season, ab, tpa - bb - ibb - sac - hbp as \"calc_ab\" from demo.jeter_world_series_stats ;\n```\n\n## **4. Division Operator**\n\n### **4.1 - Calculate OBP**\n```bash\nselect season, obp, (h + bb + ibb + hbp) / (ab + bb + ibb + hbp + sac) as \"calc_obp\" from demo.jeter_world_series_stats where season = 2000; \n```\nHmm, something doesn't look right...\nBecause h, bb, ibb, hbp, ab, and sac are int types according to the schema, they are doing integer arithemetic. Because we want to generate a decimal value, we need to `CAST` them to be something else like `FLOAT` for example.\n\n### **4.2 - Calculate OBP with `CAST`**\n```bash\nselect obp, (CAST(h as FLOAT) + CAST(bb as FLOAT) + CAST(ibb as FLOAT) + CAST(hbp as FLOAT)) / (CAST(ab as FLOAT) + CAST(bb as FLOAT) + CAST(ibb as FLOAT) + CAST(hbp as FLOAT) + CAST(sac as FLOAT)) as \"calc_obp\" from demo.jeter_world_series_stats where season = 2000; \n```\n## **5. Multiplication Operator**\n\n### **5.1 - Calculate ERA**\n```bash\nselect season, era, (er * 9) / ip as \"calc_era\" from demo.mariano_world_series_stats where season \u003e 1997 and season \u003c2001 ALLOW FILTERING;\n```\n\n## **6. Arithmetic Operator and Aggregrate Fuction**\n\n### **6.1 - Calculate Multiple Ratios using `SUM` and `CAST`**\n```bash\nselect SUM(ab) as \"total_at_bats\", SUM(r) as \"total_runs\", SUM(rbi) as \"total_rbis\", SUM(so) as \"total_strike_outs\", SUM(cast(rbi as FLOAT))/SUM(cast(ab as FLOAT)) as \"ab_rbi_ratio\",  SUM(cast(so as FLOAT))/SUM(cast(ab as FLOAT)) as \"ab_so_ratio\" from demo.jeter_world_series_stats;\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanant%2Fexample-cql-arithmetic-operators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanant%2Fexample-cql-arithmetic-operators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanant%2Fexample-cql-arithmetic-operators/lists"}