source

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package source finds the files that make up a dataset and works out how to read each one.

Veritix treats a directory as a single dataset rather than a pile of unrelated files. Business data arrives as a folder of exports that reference each other, and most real integrity problems live in the relationships between those files rather than inside any one of them.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTables = errors.New("source: no readable data files found")

ErrNoTables reports that nothing readable was found.

Functions

func AssignNames

func AssignNames(tables []TableRef)

AssignNames gives every table a unique, SQL-friendly name. Collisions are resolved by adding progressively more of the path, so that `2024/orders.csv` and `2025/orders.csv` become `orders_csv` and `t_2025_orders_csv` rather than `orders_csv` and `orders_csv_2`.

Types

type CSVDialect

type CSVDialect struct {
	Delimiter string
	Quote     string
	Escape    string
	NewLine   string
	Comment   string
	SkipRows  int
	HasHeader bool
	Encoding  Encoding

	// HeaderNames are the column names exactly as they appear in the file,
	// before any de-duplication. DuckDB silently renames a repeated header to
	// keep its schema valid, which would hide a real defect, so Veritix reads
	// the header line itself as well.
	HeaderNames []string

	// SniffedTypes is DuckDB's guess at each column's type. Veritix loads all
	// columns as text regardless; this is retained so the profiler can report
	// where a naive import would have guessed wrong, silently coerced a value,
	// or turned a bad value into a null.
	SniffedTypes []SniffedColumn

	// Notes are observations about the file itself, promoted to findings later.
	Notes []Note
}

CSVDialect is everything needed to read one delimited file, plus what was noticed about it along the way.

func SniffCSV

func SniffCSV(ctx context.Context, e *engine.Engine, f File) (CSVDialect, error)

SniffCSV determines how to read a delimited file.

type Dataset

type Dataset struct {
	// Root is the common directory the dataset was discovered under.
	Root string
	// Files are the inputs Veritix understands.
	Files []File
	// Tables are the logical tables those files contain.
	Tables []TableRef
	// Skipped records files that were passed over, and why. These are worth
	// surfacing: a spreadsheet in an unreadable format is itself a finding a
	// user needs to know about, not something to silently ignore.
	Skipped []SkippedFile
}

Dataset is the set of files and tables discovered under one or more paths.

func Discover

func Discover(paths []string) (*Dataset, error)

Discover walks the given paths and builds a dataset description. Directories are walked recursively; individual files are taken as given.

type Encoding

type Encoding string

Encoding is a character encoding Veritix can read.

const (
	// EncodingUTF8 covers plain ASCII too, with or without a byte-order mark.
	EncodingUTF8 Encoding = "utf-8"
	// EncodingUTF16 is what a Windows export saved as "Unicode" produces.
	EncodingUTF16 Encoding = "utf-16"
	// EncodingLatin1 stands in for the single-byte encodings a spreadsheet
	// exports on a European desktop.
	EncodingLatin1 Encoding = "latin-1"
	// EncodingUnknown means detection did not commit to an answer; the reader
	// falls back to UTF-8 and reports what it did.
	EncodingUnknown Encoding = ""
)

type File

type File struct {
	// Path is the absolute path on disk.
	Path string
	// Rel is the path relative to the dataset root, used for display.
	Rel string
	// Kind is how the file will be read.
	Kind Kind
	// Size is the file size in bytes.
	Size int64
}

File is one physical input file.

type Kind

type Kind string

Kind identifies how a file is read.

const (
	// KindCSV is any delimited text file, whatever its delimiter: the
	// extension is a hint and the sniffer has the final say.
	KindCSV Kind = "csv"
	// KindExcel is a workbook, which may hold several tables.
	KindExcel Kind = "excel"
)

type Note

type Note struct {
	Code    string
	Message string
}

Note is an observation made while reading a file.

type Sheet

type Sheet struct {
	Name    string
	Index   int
	Visible bool

	// HeaderRow is the 1-based row the column names were found on. Anything
	// above it was a title block or a blank spacer.
	HeaderRow int
	// Columns are the header names as written.
	Columns []string
	// DataRows is the number of rows below the header.
	DataRows int
	// HiddenRows is how many data rows are hidden from a reader of the file.
	HiddenRows int
	// MergedRanges are merged cell ranges, which break the one-value-per-cell
	// assumption every downstream tool makes.
	MergedRanges []string
	// FormulaErrors maps an error code such as "#REF!" to how many cells hold it.
	FormulaErrors map[string]int
	// RaggedRows is how many rows have a different populated width than the header.
	RaggedRows int
	// BlankSeparators counts fully-blank rows inside the data, which usually
	// mean more than one table has been stacked onto a single sheet.
	BlankSeparators int

	Notes []Note
}

Sheet describes one worksheet.

type SkippedFile

type SkippedFile struct {
	Path   string
	Rel    string
	Reason string
}

SkippedFile is an input Veritix declined to read.

type SniffedColumn

type SniffedColumn struct {
	Name string
	Type string
}

SniffedColumn is one column of DuckDB's guessed schema.

type TableRef

type TableRef struct {
	// Name is a unique, SQL-friendly identifier within the dataset.
	Name string
	// Display is the human-readable origin, e.g. "sales.xlsx#Q1".
	Display string
	// File is the file this table is read from.
	File File
	// Sheet is the worksheet name, empty for CSV.
	Sheet string
}

TableRef names one logical table within the dataset. A CSV file yields exactly one; an Excel workbook yields one per worksheet.

type Workbook

type Workbook struct {
	Sheets []Sheet
	Notes  []Note
}

Workbook describes one Excel file.

func InspectWorkbook

func InspectWorkbook(f File, tmpDir string) (*Workbook, map[string]string, error)

InspectWorkbook opens an Excel file, describes every sheet, and writes each one out as a UTF-8 CSV in tmpDir for the ingest path to read.

The returned paths are keyed by sheet name. The caller owns tmpDir and is responsible for removing it.

Jump to

Keyboard shortcuts

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