Skip to contents

Several polyglotSQL functions (sql_validate(), sql_lineage(), sql_analyze(), sql_optimize(), sql_annotate_types(), sql_openlineage()) accept an optional schema argument describing the tables referenced by the query. A schema enables column qualification, type inference, and existence checks.

Usage

as_polyglot_schema(schema)

Arguments

schema

A schema specification (named list as described above), or NULL for no schema.

Value

A JSON string in the upstream ValidationSchema format, or "" when schema is NULL. Mostly used internally; exported for advanced users who want to inspect the generated payload.

Details

A schema is a named list with one entry per table. Each entry is either:

  • a named character vector mapping column names to SQL types, e.g. c(id = "INT", name = "TEXT");

  • an unnamed character vector of column names (types unknown), e.g. c("id", "name").

Examples

as_polyglot_schema(list(
  orders = c(o_id = "INT", o_total = "DECIMAL(10,2)"),
  users = c("id", "name")
))
#> [1] "{\"tables\":[{\"name\":\"orders\",\"columns\":[{\"name\":\"o_id\",\"type\":\"INT\"},{\"name\":\"o_total\",\"type\":\"DECIMAL(10,2)\"}]},{\"name\":\"users\",\"columns\":[{\"name\":\"id\",\"type\":\"\"},{\"name\":\"name\",\"type\":\"\"}]}]}"