Skip to content

tdfs4ds.feature_props.valtypes

tdfs4ds.feature_props.valtypes

Value families and bounds of feature properties (pure, no database).

A declared bound (VALID_MIN / VALID_MAX) or allowed value is stored as TEXT and compared after being typed like the feature: this module says which family a catalog FEATURE_TYPE belongs to, whether a text is a valid literal of it, and how to write it in SQL.

_NUMERIC_PREFIXES module-attribute

_NUMERIC_PREFIXES = ('BYTEINT', 'SMALLINT', 'INTEGER', 'INT', 'BIGINT', 'FLOAT', 'REAL', 'DOUBLE', 'DECIMAL', 'DEC', 'NUMERIC', 'NUMBER')

_TEXT_PREFIXES module-attribute

_TEXT_PREFIXES = ('VARCHAR', 'CHAR', 'CLOB', 'LONG VARCHAR')

_TS_RE module-attribute

_TS_RE = compile('^(\\d{4})-(\\d{2})-(\\d{2})(?:[ T](\\d{2}):(\\d{2}):(\\d{2})(\\.\\d+)?)?\\s*(Z|[+-]\\d{2}:\\d{2})?$')

sql_literal

sql_literal(value)

Escape value for use inside a single-quoted SQL string literal.

For the DBC probes and catalog predicates that compare a name as data (WHERE DatabaseName = '…'). The caller supplies the surrounding quotes.

family_of

family_of(feature_type) -> Optional[str]

'numeric' / 'date' / 'timestamp' / 'text' for a catalog FEATURE_TYPE, None for anything a range or an allowed list cannot express (PERIOD, JSON, BLOB, ...).

_timestamp

_timestamp(text: str)

check_literal

check_literal(text, feature_type) -> Tuple[bool, str, str]

(ok, normalised text, reason): is text a valid literal of the feature's type?

numeric: a finite number (decimals allowed for integer features: the comparison is numeric); date: YYYY-MM-DD; timestamp: ISO date or date-time, optional offset; text: any non-empty text. A type with no family (PERIOD, JSON, LOB...) refuses every bound.

sql_value

sql_value(text, feature_type) -> str

The SQL expression of a declared value, typed like the feature. Pure; text must have passed :func:check_literal.

bounds_order_ok

bounds_order_ok(vmin, vmax, feature_type) -> bool

False when both bounds are given, comparable and VALID_MIN > VALID_MAX.