Files
zeekay 999d38466d rename: this fork is ours — datastore_connect
Imports read `datastore_connect`, distribution `datastore-connect`, so nothing has to
import another product's name to talk to Hanzo Datastore.

Cut from upstream 0.8.17 — the version this stack already ran — rather than from
upstream HEAD, so it is a PURE RENAME with no behaviour change. Forking from
HEAD would have dragged versions along with the name (connect alone jumped
0.8.17 -> 1.6.0, a major), which is a different and much riskier change wearing
a rename's clothes.

X-ClickHouse-* headers are untouched: they are wire protocol the server sends
and expects, and a different token shape from the module name.
2026-07-26 11:01:30 -07:00

63 lines
2.6 KiB
Python

import logging
import re
from typing import Optional, Dict, Union, Any
logger = logging.getLogger(__name__)
_empty_map = {}
# pylint: disable=too-many-instance-attributes
class BaseQueryContext:
def __init__(self,
settings: Optional[Dict[str, Any]] = None,
query_formats: Optional[Dict[str, str]] = None,
column_formats: Optional[Dict[str, Union[str, Dict[str, str]]]] = None,
encoding: Optional[str] = None,
use_extended_dtypes: bool = False,
use_numpy: bool = False,
transport_settings: Optional[Dict[str, str]] = None):
self.settings = settings or {}
if query_formats is None:
self.type_formats = _empty_map
else:
self.type_formats = {re.compile(type_name.replace('*', '.*'), re.IGNORECASE): fmt
for type_name, fmt in query_formats.items()}
if column_formats is None:
self.col_simple_formats = _empty_map
self.col_type_formats = _empty_map
else:
self.col_simple_formats = {col_name: fmt for col_name, fmt in column_formats.items() if
isinstance(fmt, str)}
self.col_type_formats = {}
for col_name, fmt in column_formats.items():
if not isinstance(fmt, str):
self.col_type_formats[col_name] = {re.compile(type_name.replace('*', '.*'), re.IGNORECASE): fmt
for type_name, fmt in fmt.items()}
self.query_formats = query_formats or {}
self.column_formats = column_formats or {}
self.transport_settings = transport_settings
self.column_name = None
self.encoding = encoding
self.use_numpy = use_numpy
self.use_extended_dtypes = use_extended_dtypes
self._active_col_fmt = None
self._active_col_type_fmts = _empty_map
def start_column(self, name: str):
self.column_name = name
self._active_col_fmt = self.col_simple_formats.get(name)
self._active_col_type_fmts = self.col_type_formats.get(name, _empty_map)
def active_fmt(self, ch_type):
if self._active_col_fmt:
return self._active_col_fmt
for type_pattern, fmt in self._active_col_type_fmts.items():
if type_pattern.match(ch_type):
return fmt
for type_pattern, fmt in self.type_formats.items():
if type_pattern.match(ch_type):
return fmt
return None