exporttrunc

package
v1.142.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package exporttrunc is what every export tool does when a bound cut the result it was writing (#2057): trino_export at a row limit, api_export and graphql_export at a page walk's page bound. The tools share one judgment so they cannot disagree about when a cut file is refused, what the response says, and how the asset it lands in is marked.

A cut the caller asked for (its own limit or max_pages) writes the file and flags it. A cut the caller did not ask for (the deployment's cap, or a walk's built-in default bound) refuses and writes nothing, unless the caller passes on_truncation "warn". Either default is overridden by on_truncation.

Index

Constants

View Source
const (
	// SourceRequest is a bound the caller set: trino_export's limit, a page
	// walk's max_pages.
	SourceRequest = "request"
	// SourceDeployment is a bound the caller did not set: the deployment's
	// row cap, or a page walk's built-in default page bound.
	SourceDeployment = "deployment"
)

Where the bound that cut a result came from.

View Source
const (
	UnitRows  = "rows"
	UnitPages = "pages"
)

What a bound counts.

View Source
const (
	// PolicyFail refuses a cut result and writes nothing.
	PolicyFail = "fail"
	// PolicyWarn writes a cut result and flags it.
	PolicyWarn = "warn"
)

on_truncation values.

View Source
const (
	MetaTruncated    = "truncated"
	MetaLimitApplied = "limit_applied"
	MetaLimitSource  = "limit_source"
	MetaLimitUnit    = "limit_unit"
)

The metadata keys a truncated version and its asset carry. The portal version store strips them from an asset whose new version carries no metadata, so they only ever describe the content the asset holds now.

View Source
const Tag = "_sys-truncated"

Tag is the reserved tag an asset carries while its current version is a truncated export. The portal version store adds and removes it with the version, so a complete version written later, by any path, clears it.

View Source
const WalkSchemaProperties = `` /* 1114-byte string literal not displayed */

WalkSchemaProperties is the on_truncation, expect_rows and expect_min_rows properties of an export whose bound is a page walk's (api_export, graphql_export), as JSON Schema property entries to splice into the tool's properties object, so the two describe one judgment in one set of words.

Variables

View Source
var ErrExpectNeedsWalk = errors.New("expect_rows and expect_min_rows count the items a page walk merges; set paginate, or drop them")

ErrExpectNeedsWalk is the refusal for a count expectation on an export that is not a page walk: a single response has no item count to hold it to.

Functions

func Carry

func Carry(m map[string]any) map[string]any

Carry is the truncation keys of an older version's metadata, for a revert that makes that version's content current again, or nil when it records no cut.

func Sentences

func Sentences(parts ...string) string

Sentences joins a message's sentences, dropping the empty ones, so a part that said nothing leaves no doubled space.

func Thousands

func Thousands(n int) string

Thousands renders n with comma separators ("100,000"), the way a tool description states a cap to a reader.

func WithTag

func WithTag(tags []string, r Report) []string

WithTag returns tags with Tag added when the report records a cut, and unchanged otherwise.

Types

type Judgment

type Judgment struct {
	Limit Limit
	// Truncated is the source's own signal that the bound cut the result.
	Truncated bool
	// Written is the count the export would write: rows, or items merged.
	Written int
	// WrittenUnit names Written in a sentence ("rows", "items").
	WrittenUnit string
	Options     Options
	// Unordered marks a result whose order the statement does not fix (a
	// query with no top-level ORDER BY). Only a row export knows this; a page
	// walk leaves it false.
	Unordered bool
}

Judgment is what Judge needs to know about one export.

type Limit

type Limit struct {
	// Applied is the bound's value.
	Applied int
	// Source is SourceRequest or SourceDeployment.
	Source string
	// Unit is what Applied counts: UnitRows or UnitPages.
	Unit string
	// Key names what set the bound, for the sentence a cut is reported in:
	// the config key of a deployment cap ("portal.export.max_rows") or the
	// parameter the caller set ("limit").
	Key string
	// Remedy is what the caller can do instead, appended to a refusal. Each
	// tool has its own.
	Remedy string
	// Name is what the bound is called in a sentence. Empty takes the
	// source's: "the requested limit" or "the deployment cap".
	Name string
}

Limit is the bound a result was read under.

func WalkLimit

func WalkLimit(pages int, callerSet bool, remedy string) Limit

WalkLimit is the bound a page walk ran under: the caller's max_pages, or the tool's default bound when the caller set none. remedy is the tool's own way out, appended to a refusal.

type Options

type Options struct {
	// OnTruncation is "fail" or "warn"; empty takes the default for the
	// bound's source.
	OnTruncation string `json:"on_truncation,omitempty"`
	// ExpectRows is the exact count the export must write.
	ExpectRows *int `json:"expect_rows,omitempty"`
	// ExpectMinRows is the fewest the export may write.
	ExpectMinRows *int `json:"expect_min_rows,omitempty"`
}

Options is what a caller passes on an export call to decide what a cut or an unexpected count does. Each export tool's input embeds it.

func (Options) Expects

func (o Options) Expects() bool

Expects reports whether the caller set an expectation on the count.

func (Options) Validate

func (o Options) Validate() error

Validate refuses an on_truncation value outside the enum, a negative expectation, and both expectations at once.

func (Options) ValidateWalk

func (o Options) ValidateWalk(walk bool) error

ValidateWalk is Validate for an export whose count is a page walk's (api_export, graphql_export): walk says whether the call walks, and a count expectation on one that does not is refused.

type Outcome

type Outcome struct {
	Report Report
	// Refusal, when set, is the error the call returns instead of writing.
	Refusal string
	// Note is what the success message says beyond the count. Empty for a
	// complete result nothing else is said about.
	Note string
}

Outcome is what an export does with its result.

func Judge

func Judge(j Judgment) Outcome

Judge decides whether an export writes its result, and what it reports.

type Report

type Report struct {
	// Truncated reports that the bound cut the result: the source had more
	// past it.
	Truncated    bool   `json:"truncated"`
	LimitApplied int    `json:"limit_applied,omitempty"`
	LimitSource  string `json:"limit_source,omitempty"`
	LimitUnit    string `json:"limit_unit,omitempty"`
	// ArbitrarySubset reports that a cut result came from a statement with no
	// top-level ORDER BY, so which rows it kept is the engine's choice and can
	// differ on the next run.
	ArbitrarySubset bool `json:"arbitrary_subset,omitempty"`
	// ExpectMismatch, under on_truncation "warn", is the expectation the
	// written count missed. A miss without "warn" refuses instead.
	ExpectMismatch string `json:"expect_mismatch,omitempty"`
}

Report is the fields every export output carries beside its count when a bound applied to it.

func FromMetadata

func FromMetadata(m map[string]any) *Report

FromMetadata reads a Report back from a version's or an asset's metadata, for an answer that names an export written earlier (an idempotency hit). It is nil when the metadata records no cut.

func (Report) Metadata

func (r Report) Metadata() map[string]any

Metadata is what a truncated version and its asset record, or nil for a result the bound did not cut.

Jump to

Keyboard shortcuts

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