惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy International News Feed
爱范儿
爱范儿
H
Help Net Security
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
博客园 - 叶小钗
Google DeepMind News
Google DeepMind News
GbyAI
GbyAI
T
Tenable Blog
Project Zero
Project Zero
腾讯CDC
Spread Privacy
Spread Privacy
V
Vulnerabilities – Threatpost
T
Threatpost
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Latest news
Latest news
L
Lohrmann on Cybersecurity
B
Blog RSS Feed
小众软件
小众软件
G
Google Developers Blog
T
Tor Project blog
P
Palo Alto Networks Blog
The Cloudflare Blog
Scott Helme
Scott Helme
D
Darknet – Hacking Tools, Hacker News & Cyber Security
A
Arctic Wolf
博客园 - 聂微东
AWS News Blog
AWS News Blog
L
LINUX DO - 热门话题
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
博客园 - Franky
Know Your Adversary
Know Your Adversary
人人都是产品经理
人人都是产品经理
博客园 - 【当耐特】
P
Privacy & Cybersecurity Law Blog
A
About on SuperTechFans
Cisco Talos Blog
Cisco Talos Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
C
Cisco Blogs
P
Proofpoint News Feed
雷峰网
雷峰网
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
B
Blog
Security Latest
Security Latest
C
Cybersecurity and Infrastructure Security Agency CISA
Jina AI
Jina AI
Y
Y Combinator Blog

Arpit Bhayani

Temporal Primer - Building Long-Running Systems What Matters in Production RAG Structure of Every LLM Chat How LLMs Really Work Your Monolith Is Already A Distributed System Databases Were Not Designed For This BM25 JOIN Algorithms Venting at Work Comes at a Reputation Cost Why Half Your Skills Expire Every Few Years Multi-Paxos - Consensus in Distributed Databases MySQL Replication Internals Bloom Filters When You Increase Kafka Partitions Product Quantization The Q, K, V Matrices The Day I Accidentally Deleted Production How LLM Inference Works What are Blocking Queues and Why We Need Them Heartbeats in Distributed Systems How Writes Work in Apache Cassandra Redis Replication Internals How to Handle Arrogant Colleagues at Work How Does a CDN Handle Content Replication You Can't Fix Everything on Day One When Emotions Spill Over at Work Why gRPC Uses HTTP2 Meetings With No Agenda Are a Waste of Time Career Longevity Beats Constant Job Hopping Stay Relevant at Higher Salary Levels Why Distributed Systems Need Consensus Algorithms Like Raft Why Do Databases Deadlock and How Do They Resolve It Why and How Cache Locality Can Make Your Code Faster Why Eventual Consistency is Preferred in Distributed Systems Why does DNS use both UDP and TCP Should You Do a Master's My Honest Take Empathy Makes Great Engineers Unstoppable Good Mentors Build People, Not Just Skills Why You Should Always Have Back-Burner Projects Before You Push Back, Know What You're Standing On Be the One They Can Count On How Much Are People Willing to Bet on You How to Get Leadership to Say Yes to Your Project Don't Let Your Best Ideas Die in Silence Be the Person Everyone Wants to Work With The XY Problem and How to Avoid It The Startup Hiring Lie Nobody Talks About You Won't Be Promoted Unless You Ask It's Not Enough to be Right; Learn to be Heard No One Ships Great Software Alone You Don't Win by Proving Others Wrong Appreciate Generously; It Costs Nothing, But Builds Everything Your Soft Skills Aren't Soft at All Before you form an opinion, experience it Why You Need Both Curiosity and Action to Thrive A Daily Worklog Changed Everything How We Handle Mistakes Defines Us Own Your Mistakes Don't Wait. Step Up. Temporary Fixes Are Permanent Why Interviews Are Biased And What Sets You Apart Saying 'This isn't my problem' is actually the problem How to Write Effective OKRs Never Lose a Battle due to Miscommunication When In Doubt, Code It Out How to Follow Up Without Annoying People Lead Projects That Land, Execution Over Everything Abstract Thinking Will Define Your Next Decade We Engineers Suck at Task Estimation Shiny Obect Syndrome in Tech When to Change Jobs - The 3P Framework Comfort and Competition - Know When to Switch Gears Paper Notes - On-demand Container Loading in AWS Lambda Paper Notes - NanoLog - A Nanosecond Scale Logging System Don't Wait, Learn - The Best Resource is Mythical Paper Notes - WTF - The Who to Follow Service at Twitter The Unexpected Benefit of Reading Random Engineering Articles Roadmaps Are Limiting Your Growth Stop Leaving Money on the Table - Negotiate Your Job Offer Never Bad-Mouth Your Past Employers Show You're a Culture Fit Quantify your resume, Know Your Numbers The Importance of Being Likeable in Interviews Questions to Ask Your Interviewer How to Build Trust Through Collaboration Do This, Once You Are Out of the Interview Cycle Stop Pitching Ideas, Start Pitching Projects Read Those Design Docs, Even the Ones That Seem Irrelevant The Best Engineering Lessons Happen During Outages Great Engineers Start Broad LLM Summaries are Ruining Your Learning Turn System Design Interviews into Discussions Title Inflation At Work, Find Your Own Projects 6 Simple Strategies to Cracking Any Tech Interview How to Remain Unblocked Solving the Knapsack Problem with Evolutionary Algorithms Generating Pseudorandom Numbers with LFSR Local vs Global Indexes in Partitioned Databases Partitioning Data - Range, Hash, and When to Use Them
Paper Notes - SQL Has Problems. We Can Fix Them Pipe Syntax In SQL
Arpit Bhayani · 2024-09-03 · via Arpit Bhayani

TL;DR

SQL has long been the dominant language for structured data processing, through this paper GoogleSQL team introduced a new pipe-structured data flow syntax that significantly improves SQL’s readability, extensibility, and ease of use.

The approach involves adding pipe operators (|>) to SQL which essentially breaks down complex queries into steps, making them easier to understand and maintain. This syntax enables operations to be composed arbitrarily, in any order, drastically simplifying complex queries and improving readability. Three things I found interesting were

  • pipe syntax that makes SQL more linear, extensible, and readable
  • “prefix property” that allows running partial queries to see intermediate results, aiding in debugging
  • experimental debugging operators (ASSERT, LOG, DESCRIBE)

SQL Has Problems. We Can Fix Them: Pipe Syntax In SQL

Notes and a quick explanation

SQL, the de facto standard for structured data processing, has stood the test of time for 50+ years. Google proposed an extension to SQL and introduced pipe-structured data flow syntax to improve its usability and extensibility.

The Fundamental Issues with Standard SQL

SQL’s rigid clause order (SELECT ... FROM ... WHERE ... GROUP BY) doesn’t reflect the actual data flow, which begins with table scans in the FROM clause. This structure also complicates the process of extending the language with new features This disconnect leads to several issues, like

  • SQL uses duplicate clauses (WHERE, HAVING, QUALIFY) to work around rigid clause order
  • many simple operations require subqueries, leading to deeply nested, hard-to-read code
  • SQL’s structure makes tracing logic difficult, especially in large queries
  • adding new query operations is challenging and there is an over-reliance on reserved keywords

The Pipe Syntax Solution

In traditional SQL, queries are typically written in a single, monolithic statement. GoogleSQL’s new pipe syntax allows for a sequential approach, where the output of one operation is “piped” as the input to the next. This approach is intuitive and also aligns with how data is processed.

With GoogleSQL’s pipe syntax, queries can have zero or more pipe operators as a suffix, delineated with ”|>”. Here’s a quick example of how a SQL query would look with pipe syntax

SELECT column1, column2
FROM table1
WHERE condition1
|> JOIN table2 ON table1.id = table2.id
|> SELECT column3
|> ORDER BY column3 DESC;

Each pipe operator is a unary relational operation, taking one table as input and producing one table as output. Intermediate results in SQL are tables with one or more columns and zero or more rows. This structure ensures composability and allows operators to be applied in any order, any number of times. Each pipe operator is self-contained, seeing only its input table and arguments. This isolation makes pipe operators naturally composable.

Extensibility

The pipe syntax dramatically improves SQL’s extensibility with Table-Valued Functions (TVFs). The CALL operator allows invoking TVFs directly without nested subqueries. Here’s a quick example

SELECT '<text>' AS input, 7 AS rating
|> CALL ML.PREDICT(MODEL `my_project.nnlm_embedding_model`)
|> CALL ML.PREDICT(MODEL `my_project.imdb_classifier`)

Built-in Operator Extensions

Pipe syntax simplifies the addition of new built-in operators. For example, the PIVOT operator, which is awkwardly implemented in standard SQL, becomes a naturally composable pipe operator:

FROM customer JOIN nation ON c_nationkey = n_nationkey
|> SELECT n_name, c_acctbal AS bal, c_mktsegment
|> PIVOT(SUM(bal) AS bal FOR n_name IN ('PERU', 'KENYA', 'JAPAN'))

Experimental Debugging Operators

GoogleSQL also introduces debugging operators that leverage pipe syntax

  1. ASSERT: adds assertions to SQL queries
  2. LOG: logs intermediate result tables for debugging
  3. DESCRIBE: returns schema information for intermediate tables

Deep Observations on Syntax Flexibility

A good thing about this new syntax is its flexibility in accommodating both existing SQL operations and potential future extensions. Hence the existing features of SQL like complex joins, subqueries, and aggregations will not be abandoned and could be expressed in a piped syntax.

Pipe syntax also supports user-defined functions (UDFs) in a more natural and readable manner. This feature is crucial where data transformations often require custom operations that are not natively supported by SQL. The modular nature of the pipe syntax ensures that these UDFs can be incorporated without breaking the flow of the query.

Implementation and Adoption

To get this adopted, the GoogleSQL team designed the pipe syntax as an extension of the existing SQL syntax, rather than a replacement. This allows users to gradually adopt the new syntax in their queries, without needing to fully commit to it from the outset.

The implementation produces the same algebra as standard SQL, requiring minimal work for query engines to enable the feature. This approach makes pipe syntax immediately a first-class feature in supporting query engines.

GoogleSQL implemented pipe syntax as a reusable component shared across multiple query engines, including F1, BigQuery, Spanner, and Procella. This shared language analysis component allowed for a single implementation to be enabled across multiple engines.

The content presented here is a collection of my notes and explanations based on the paper. You can access the full paper Paper Notes - SQL Has Problems. We Can Fix Them Pipe Syntax In SQL . This is by no means an exhaustive explanation, and I strongly encourage you to read the actual paper for a comprehensive understanding. Any images you see are either taken directly from the paper or illustrated by me .