feature: phil-wadler authors: - "ice1000"

start_date: "2022/12/01"

Crates.io

Wadler-style algebraic pretty printing API for SQL

This RFC proposes a new API for pretty-printing pseudo "structures". The purpose of the API is to supersede the current implementation of SQL explain, and maybe more.

Goals

Non-goals

Motivation

I tried to use the pretty crate to implement SQL explain, but it turned out to be limited in many ways:

However, the standard Wadler-style "algebraic" pretty printing API is well-designed and can be extended to support the features we desire. I saw a screenshot by @xxchan on a private Slack channel that shows the SQL explain output of databend's system, which inspired me to write this RFC.

Intended behavior

Implementation

These contents are subject to future changes.

Types

Types XmlNode and Pretty for pretty printing data

Variants of Pretty:

Record PrettyConfig for pretty printing configuration

It contains indentation, preferred width, etc.

Record LinedBuffer for actually writing the string

It contains a mutable reference to a String, and a PrettyConfig. It understands the intended width (precomputed by PrettyConfig::interesting_*), and will try to fill an incomplete line with spaces when asked so.

Important methods

Edge cases

Changelog