---
title: "Enabling static analysis of SQL queries at Meta"
description: "UPM (Unified Programming Model) is Meta's standalone library that parses SQL into a semantic tree, a typed intermediate representation decoupled from any single query engine, so infrastructure teams can build linters, query rewriters and lineage tools without reimplementing analysis per dialect."
url: "https://swe.quest/articles/enabling-static-analysis-of-sql-queries-at-meta-a9210cb14aebcf3f"
canonical: "https://engineering.fb.com/2022/11/30/data-infrastructure/static-analysis-sql-queries/"
source: "Meta Engineering"
published: "2022-11-30"
difficulty: "medium"
kind: "Case study"
reading_minutes: 6
tags: ["static-analysis","sql","type-systems","data-pipelines","query-engines"]
---

# Enabling static analysis of SQL queries at Meta

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2022-11-30, 6 min read, Case study. Original: [https://engineering.fb.com/2022/11/30/data-infrastructure/static-analysis-sql-queries/](https://engineering.fb.com/2022/11/30/data-infrastructure/static-analysis-sql-queries/)

## Summary

UPM (Unified Programming Model) is Meta's standalone library that parses SQL into a semantic tree, a typed intermediate representation decoupled from any single query engine, so infrastructure teams can build linters, query rewriters and lineage tools without reimplementing analysis per dialect. It acts as a pluggable SQL front end exposing one Presto-superset dialect across Presto, Spark and the in-house XStream, either feeding the tree directly to engines or rendering it back to a target dialect. User-defined semantic column types (e.g. TimestampMilliseconds, UserID) let the typechecker catch unit and ID-mismatch errors in UNIONs and JOINs before execution. A lineage tool consumes semantic trees from all recurring queries to build a warehouse-wide column-level lineage graph.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Static analysis](https://swe.quest/tags/static-analysis.md) (Engineering practices)
- [SQL](https://swe.quest/tags/sql.md) (Languages)
- [Type systems](https://swe.quest/tags/type-systems.md) (Compilers & runtimes)
- [Data pipelines](https://swe.quest/tags/data-pipelines.md) (Data & databases)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)

## Prerequisites

- SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- abstract syntax trees
- data warehouses

## Keywords

UPM, Presto, Spark, XStream, Hive, Velox, data lineage

## Related posts

- [Composable data management at Meta](https://swe.quest/articles/composable-data-management-at-meta-c95cc910c8dc9e8f.md): Meta Engineering · 2024-05-22 · Easy · 9 min read · Query engines, Analytics & OLAP, System design, Open source
  Meta has been decomposing its many monolithic data engines (ETL, interactive, streaming, ML preprocessing) into reusable components: language frontend, IR, optimizer, execution library and runtime.
- [Policy Zones: How Meta enforces purpose limitation at scale in batch processing systems](https://swe.quest/articles/policy-zones-how-meta-enforces-purpose-limitation-at-scale-in-batch-processing-615adcc0c88f4c90.md): Meta Engineering · 2025-07-23 · Medium · 20 min read · Privacy, Data pipelines, Identity & auth, SQL
  Meta's Policy Zones, part of its Privacy Aware Infrastructure, applies information flow control to enforce purpose limitation across an exabyte-scale data warehouse.
- [Introducing Velox: An open source unified execution engine](https://swe.quest/articles/introducing-velox-an-open-source-unified-execution-engine-d191dd46ed8f465e.md): Meta Engineering · 2023-03-09 · Hard · 8 min read · Query engines, Analytics & OLAP, C & C++, Performance engineering, Open source
  Velox is Meta's open source C++ execution engine that unifies the data-plane components (expression evaluation, aggregation, joins, sorting, I/O, resource management) shared by engines like Presto, Spark and PyTorch's TorchArrow.
- [PostgREST v10: EXPLAIN and Improved Relationship Detection](https://swe.quest/articles/postgrest-v10-explain-and-improved-relationship-detection-44878c605b0df57d.md): Supabase · 2022-08-19 · Medium · 7 min read · PostgreSQL, API design, Performance engineering
  PostgREST v10 adds HTTP-level EXPLAIN support: requests with the \`application/vnd.pgrst.plan\` media type, or supabase-js's \`explain()\` transform, return the PostgreSQL execution plan for reads, writes and RPC, which helps verify that RLS policies are applied and gives you the pg\_stat\_statements query identifier.
- [What’s New in ClickHouse 22.1](https://swe.quest/articles/what-s-new-in-clickhouse-22-1-dbe5057974c6a557.md): ClickHouse · 2022-01-26 · Medium · 8 min read · Analytics & OLAP, Databases, Distributed databases
  ClickHouse 22.1 adds schema inference for table functions like url, s3, file and hdfs, detecting format and compression from the file extension and reading column types from self-describing formats such as Native, Parquet, Avro and ORC.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
