Skip to main content

Pipe Syntax Formatting

Pipe syntax (|>) is supported in BigQuery, Spark, and Databricks. Each pipe step starts on a new line with |> leading.

Behavior: The |> operator leads each pipe step on a new line. The pipe operation content (SELECT, WHERE, etc.) follows on the same line when it fits, or is indented below when it exceeds maxLineWidth.

Internal formatting: Pipe operations follow the same formatting rules as their non-pipe equivalents:

  • |> SELECT items follow SELECT item style
  • |> WHERE conditions get AND/OR line-breaking
  • |> ORDER BY items follow ORDER BY item style

Subqueries: Pipe steps inside subqueries are indented along with the subquery.

Simple pipe query

select 1 as x, 2 as y |> select *, x + y as z |> select x, z
select 1 as x, 2 as y |> select *, x + y as z |> select x, z

Pipe with WHERE

from orders |> where status = 'active' |> select customer_id, total
from orders |> where status = 'active' |> select customer_id, total

Pipe with ORDER BY and LIMIT

from orders |> where total > 100 |> order by total desc |> limit 10
from orders |> where total > 100 |> order by total desc |> limit 10

Pipe with aggregate

from orders |> aggregate count(*) as cnt, sum(total) as total_sum group by customer_id
from orders
|> aggregate count(*) as cnt, sum(total) as total_sum group by customer_id

Single pipe step

select a, b from t |> where a > 1
select a, b from t |> where a > 1

Pipe SELECT with many items (BODY style)

from orders |> select customer_id, order_date, total, status, region
from orders |> select customer_id, order_date, total, status, region

Pipe SELECT with STACKED style

from orders |> select customer_id, total, status
from orders |> select customer_id, total, status

Pipe WHERE with AND/OR

from orders |> where status = 'active' and total > 100 and region = 'US'
from orders |> where status = 'active' and total > 100 and region = 'US'

Pipe ORDER BY with multiple items (BODY style)

from orders |> order by region asc, total desc, customer_id asc
from orders |> order by region asc, total desc, customer_id asc

Pipe in CTE subquery

WITH active AS (FROM orders |> WHERE status = 'active' |> SELECT customer_id, total) SELECT * FROM active
with
active as (
from orders
|> where status = 'active'
|> select customer_id, total
)
select *
from active

Pipe in inline subquery

SELECT * FROM (FROM orders |> WHERE total > 100 |> SELECT customer_id, total) AS t
select *
from (from orders |> where total > 100 |> select customer_id, total) as t

Pipe AGGREGATE with multiple items (BODY style)

from orders |> aggregate count(*) as cnt, sum(total) as total_sum, avg(total) as avg_total group by customer_id, region
from orders
|>
aggregate count(*) as cnt, sum(total) as total_sum, avg(total) as avg_total
group by customer_id, region

Pipe AGGREGATE with GROUP BY items

from orders |> aggregate count(*) as cnt group by customer_id, region, status
from orders |> aggregate count(*) as cnt group by customer_id, region, status

Pipe AGGREGATE STACKED style

from orders |> aggregate count(*) as cnt, sum(total) as total_sum, avg(total) as avg_total group by customer_id
from orders
|>
aggregate count(*) as cnt, sum(total) as total_sum, avg(total) as avg_total
group by customer_id

Pipe DROP columns (BODY style)

from orders |> drop customer_id, order_date, status
from orders |> drop customer_id, order_date, status

Pipe multi-step with internal formatting

from orders |> where status = 'active' and total > 100 |> select customer_id, order_date, total |> order by total desc, order_date asc |> limit 10
from orders
|> where status = 'active' and total > 100
|> select customer_id, order_date, total
|> order by total desc, order_date asc
|> limit 10