/** * @file The corpus parquet schema defines its columns and logical types. It also defines the projection from a `LabeledRow`. * * Every file in this family agrees on this one definition. A column added here and nowhere else fails to compile * against {@linkcode ParquetRow}, which keeps the writer, the reader and the manifest's `schema` key from drifting * apart. * * Compression is `snappy` throughout. PyArrow uses it by default. It is also the standard ML-corpus codec. A reader * outside this repository therefore opens the files without configuration. */ import type { LabeledRow } from "#types"; /** * Row groups are written at this cadence within a parquet file. */ export declare const ROW_GROUP_SIZE = 50000; /** * Rows per parquet file when a writer's caller identifies no limit. * * A file is closed here rather than grown, because `writeParquetFile` materializes * one Arrow table and Arrow's list builder raises before a whole source fits: * 4,228,212 rows raised where 1,603,143 wrote. * The manifest records the value in force as `rows_per_file`. */ export declare const ROWS_PER_FILE = 1000000; /** * The optional per-row draw weight: a positive float that scales a row's chance of * being drawn within its source, with mean 1 over the source's train rows. * A file without the column reads 1.0 for every row. */ export declare const DRAW_WEIGHT_COLUMN = "draw_weight"; /** * Snappy is the codec selected for corpus parquet files. */ export declare const PARQUET_COMPRESSION = "SNAPPY"; export interface ParquetFieldDefinition { type: "UTF8" | "INT32"; compression: typeof PARQUET_COMPRESSION; repeated?: boolean; optional?: boolean; } export type ParquetSchemaDefinition = Record, ParquetFieldDefinition>; /** * A single Parquet row shape. * * The index signature allows callers to retain source fields before projection. * * Optional fields are represented as null in the Arrow table and read back as null. */ export interface ParquetRow { raw: string; tokens: readonly string[]; labels: readonly string[]; span_starts: readonly number[]; span_ends: readonly number[]; span_tags: readonly string[]; country: string; locale?: string | null; source: string; source_id: string; /** * The SPDX identifier or `LicenseRef-*` id of the source's register inputs. * * Every writer stamps this value from `#source-register/row-license`. * * A file written before the column had this meaning holds the producer's prose here, * and {@linkcode corpusRowFromParquet} passes it through unchanged. */ license: string; register?: string | null; surface: string; /** * The augmentation that derived the row from the row `base_source_id` names, or `null`. */ augmentation?: string | null; base_source_id?: string | null; [key: string]: unknown; } /** * Column names emitted into every parquet file. * * Matches `ParquetRow`. */ export declare const PARQUET_COLUMNS: readonly ["raw", "tokens", "labels", "span_starts", "span_ends", "span_tags", "country", "locale", "source", "source_id", "license", "register", "surface", "augmentation", "base_source_id"]; /** * The DuckDB type each column is read and written as. * * Paired with {@linkcode PARQUET_COLUMNS} so a `read_json` column map and a `copy` * select list are built from one list rather than two that can disagree. */ export declare const PARQUET_COLUMN_TYPES: Record<(typeof PARQUET_COLUMNS)[number], string>; /** * Parquet schema for `LabeledRow`. * * Optional fields set `optional: true`. * Repeated UTF8 columns capture the tokens and labels arrays. */ export declare const LABELED_ROW_SCHEMA: ParquetSchemaDefinition; /** * Project a labeled row to the Parquet schema. * * The span triple is required because `alignRow` emits it on every labeled row. * A row without it came from a producer that's not migrated. * * The writer would drop the labels from the file if it wrote that row. * A thrown error identifies the row instead. */ export declare function rowToParquet(row: LabeledRow): ParquetRow; /** * The columns a corpus parquet file written before #2741 has in place of `augmentation`. */ export declare const RETIRED_PARQUET_COLUMNS: readonly ["corpus_version", "recipe"]; /** * Read one row of a corpus parquet file of either schema as a {@linkcode ParquetRow}. * * This is the one place an older file's columns map to the current ones. * A v0.7.x file has `corpus_version`, the run of whichever recipe or build wrote the row, and `recipe`. * * On a row derived from a base row, `recipe` held an augmentation name. * On every other row, it held the producer's name or template. * * Measured over the 1,069 files of `v0.7.10-gb-county`, a `recipe` value is an * augmentation exactly where `base_source_id` is set, so that value becomes `augmentation` * and every other becomes `null`; the producer is the row's `source`. * `corpus_version` is dropped, because the file's record and the manifest name the corpus. * * `license` passes through unchanged. * An older file holds the producer's prose there. * * That text records the producer's statement, and a writer re-stamps the register's id * when the row is written again. * * Every other column passes through, so a projection of current columns reads the same from both schemas. */ export declare function corpusRowFromParquet(raw: Record): ParquetRow; //# sourceMappingURL=schema.d.ts.map