Skip to main content

Module helper

Module helper 

Source
Expand description

Helper utilities for SQL processing

This module provides various utility functions used throughout the codebase:

  • Safe sequence access
  • Collection normalization
  • String manipulation
  • Fixed-point transformation
  • Topological sorting

Based on the Python implementation in sqlglot/helper.py.

Structs§

SingleValuedMapping
A mapping where all keys return the same value.

Enums§

TsortError
Error type for topological sort

Constants§

DATE_UNITS
Interval units that operate on date components

Traits§

EnsureList
Ensures that a value is wrapped in a Vec if it isn’t already a collection.

Functions§

apply_index_offset
Applies an offset to a given integer literal expression for array indexing.
camel_to_snake_case
Converts a camelCase string to UPPER_SNAKE_CASE
csv
Formats any number of string arguments as CSV.
csv_default
Formats strings as CSV with default separator “, “
dict_depth
Get the nesting depth of a nested HashMap
ensure_list
Wrap a single value in a Vec
ensure_list_option
Wrap an Option in a Vec (empty if None)
find_new_name
Searches for a new name that doesn’t conflict with taken names.
first
Returns the first element from an iterator
flatten
Flattens a nested collection into a flat iterator
is_date_unit
Check if a unit is a date unit (operates on date components)
is_float
Check if a string can be parsed as a float
is_int
Check if a string can be parsed as an integer
is_iso_date
Check if a string is a valid ISO date (YYYY-MM-DD)
is_iso_datetime
Check if a string is a valid ISO datetime
merge_ranges
Merge overlapping ranges
name_sequence
Creates a name generator that produces sequential names.
seq_get
Returns the value in seq at position index, or None if index is out of bounds.
snake_to_camel_case
Converts a snake_case string to CamelCase
split_num_words
Perform a split on a value and return N words with None for missing parts.
to_bool
Convert a boolean-like string to an actual boolean.
tsort
Sorts a directed acyclic graph in topological order.
while_changing
Applies a transformation to a given expression until a fix point is reached.
while_changing_hash
Applies a transformation until a fix point, using a hash function for comparison.