tablejsonl

package
v1.135.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package tablejsonl inspects a JSON-lines file before a table is registered over it, and reads the columns that table declares (#1820). It knows nothing about registrations; tableregister asks it and acts on the answer, as it asks tablecsv about a CSV.

A JSON-lines table is read by Trino's Hive JSON reader, one object per line, and it is the format a table reads back exactly: every string a JSON string can hold, line breaks included, and a null that stays a null. What the reader cannot read is the shape of a line, not the text inside it, and it fails in one of two ways. Most defects fail every query on the table, which is loud but leaves a registration nobody can use. One is silent: a second object on the same line is dropped. Each was observed on Trino 453, and each is refused here, by line, before the DDL runs.

The columns are typed from the values (#1833): the JSON reader returns a number in a BIGINT or DOUBLE column, a boolean in a BOOLEAN one, and a nested object or list in a ROW or an ARRAY, so declaring every column VARCHAR -- the rule of the CSV reader, which admits nothing else -- threw away what the file already said and made every aggregate cast.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRecords = errors.New("the file holds no records, so there are no columns to declare; " +
	"a JSON-lines file names its columns only in its records")

ErrNoRecords means the file holds no record to take a column from. A table declares at least one column, and a JSON-lines file carries its columns only in its records.

Functions

func Columns

func Columns(body []byte) ([]tablecsv.Column, error)

Columns reads a JSON-lines file and returns the columns a table over it declares: every key any record carries, lowercased, in the order they are first seen, each with the type its values infer to (tabletype.Inferrer). It refuses a file the reader would fail on or read wrongly, naming the line.

The names are the keys, lowercased and otherwise untouched, because the reader finds a value by matching its key to a column name without regard to case. A CSV column can be renamed (tablecsv.ColumnsFrom fills a blank one and drops a comma) because a CSV is read by position; a key renamed here would be a column the reader never fills.

Every record is read, not a sample. A nested object or list is declared as a ROW or an ARRAY (#1833); a key that holds an object on one line and a list or a scalar on another is refused, because no declaration reads both.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL