trulens.connectors.snowflake.sqlalchemy_db¶
trulens.connectors.snowflake.sqlalchemy_db
¶
Snowflake-specific SQLAlchemyDB subclass.
Encapsulates dialect-specific behavior that previously lived in
trulens-core:
- AUTOCOMMIT isolation_level workaround for
snowflake-sqlalchemy >= 1.7.2. - NULL-result feedback insert workaround for the Snowflake stored-procedure connector.
- JSON path extraction via
json_extract_path_textwith quoted paths. - Latency expression via
timestampdiff. - Alembic
DefaultImplregistration for thesnowflakedialect.
Classes¶
SnowflakeImpl
¶
Bases: DefaultImpl
Alembic DDL impl marker for the snowflake dialect.
SnowflakeSQLAlchemyDB
¶
Bases: SQLAlchemyDB
SQLAlchemyDB subclass that hosts all Snowflake-dialect-specific overrides.
Attributes¶
redact_keys
class-attribute
instance-attribute
¶
redact_keys: bool = DEFAULT_DATABASE_REDACT_KEYS
Redact secrets before writing out data.
table_prefix
class-attribute
instance-attribute
¶
table_prefix: str = DEFAULT_DATABASE_PREFIX
The prefix to use for all table names.
DB interface requirement.
engine_params
class-attribute
instance-attribute
¶
SQLAlchemy-related engine params.
session_params
class-attribute
instance-attribute
¶
SQLAlchemy-related session.
session
class-attribute
instance-attribute
¶
session: Optional[sessionmaker] = None
SQLAlchemy session(maker).
orm
instance-attribute
¶
Container of all the ORM classes for this database.
This should be set to a subclass of ORM upon initialization.
Functions¶
__repr__
¶
__repr__() -> str
Safe repr that handles circular references.
Pydantic's default __repr__ does not guard against
circular references among model instances, which leads to
RecursionError (see GitHub issue #1862). This override
uses the same formatted_objects context-variable that
__rich_repr__ uses so that already-visited objects are
replaced with a short placeholder instead of recursing
infinitely.
delete_app
¶
delete_app(app_id: AppID) -> None
Deletes an app from the database based on its app_id.
| PARAMETER | DESCRIPTION |
|---|---|
app_id
|
The unique identifier of the app to be deleted.
TYPE:
|
insert_feedback_definition
¶
insert_feedback_definition(
feedback_definition: FeedbackDefinition,
) -> FeedbackDefinitionID
get_feedback_defs
¶
get_feedback_defs(
feedback_definition_id: Optional[
FeedbackDefinitionID
] = None,
) -> DataFrame
See DB.get_feedback_defs.
insert_feedback
¶
insert_feedback(
feedback_result: FeedbackResult,
) -> FeedbackResultID
See DB.insert_feedback.
batch_insert_feedback
¶
batch_insert_feedback(
feedback_results: List[FeedbackResult],
) -> List[FeedbackResultID]
get_feedback
¶
get_feedback(
record_id: Optional[RecordID] = None,
feedback_result_id: Optional[FeedbackResultID] = None,
feedback_definition_id: Optional[
FeedbackDefinitionID
] = None,
status: Optional[
Union[
FeedbackResultStatus,
Sequence[FeedbackResultStatus],
]
] = None,
last_ts_before: Optional[datetime] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
shuffle: Optional[bool] = False,
run_location: Optional[FeedbackRunLocation] = None,
) -> DataFrame
See DB.get_feedback.
get_feedback_count_by_status
¶
get_feedback_count_by_status(
record_id: Optional[RecordID] = None,
feedback_result_id: Optional[FeedbackResultID] = None,
feedback_definition_id: Optional[
FeedbackDefinitionID
] = None,
status: Optional[
Union[
FeedbackResultStatus,
Sequence[FeedbackResultStatus],
]
] = None,
last_ts_before: Optional[datetime] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
shuffle: bool = False,
run_location: Optional[FeedbackRunLocation] = None,
) -> Dict[FeedbackResultStatus, int]
update_app_metadata
¶
get_records_and_feedback
¶
get_records_and_feedback(
app_ids: Optional[List[AppID]] = None,
app_name: Optional[AppName] = None,
app_version: Optional[AppVersion] = None,
app_versions: Optional[List[AppVersion]] = None,
run_name: Optional[RunName] = None,
record_ids: Optional[List[RecordID]] = None,
offset: Optional[int] = None,
limit: Optional[int] = None,
) -> Tuple[DataFrame, Sequence[str]]
get_leaderboard_aggregates
¶
insert_ground_truth
¶
insert_ground_truth(
ground_truth: GroundTruth,
) -> GroundTruthID
batch_insert_ground_truth
¶
batch_insert_ground_truth(
ground_truths: List[GroundTruth],
) -> List[GroundTruthID]
get_ground_truth
¶
See DB.get_ground_truth.
get_ground_truths_by_dataset
¶
get_events
¶
get_events(
app_name: Optional[str],
app_version: Optional[str],
record_ids: Optional[List[str]],
start_time: Optional[datetime],
) -> DataFrame
See DB.get_events.
extract_app_and_run_info
staticmethod
¶
from_tru_args
classmethod
¶
from_tru_args(
database_url: Optional[str] = None,
database_engine: Optional[Engine] = None,
database_redact_keys: Optional[
bool
] = DEFAULT_DATABASE_REDACT_KEYS,
database_prefix: Optional[
str
] = DEFAULT_DATABASE_PREFIX,
**kwargs: Dict[str, Any]
) -> SQLAlchemyDB
Process database-related configuration provided to the Tru class to create a database.
Emits warnings if appropriate.
from_db_url
classmethod
¶
from_db_url(
url: str, **kwargs: Dict[str, Any]
) -> SQLAlchemyDB
Create a database for the given url.
| PARAMETER | DESCRIPTION |
|---|---|
url
|
The database url. This includes database type.
TYPE:
|
kwargs
|
Additional arguments to pass to the database constructor. |
| RETURNS | DESCRIPTION |
|---|---|
SQLAlchemyDB
|
A database instance. |
from_db_engine
classmethod
¶
from_db_engine(
engine: Engine, **kwargs: Dict[str, Any]
) -> SQLAlchemyDB
Create a database for the given engine. Args: engine: The database engine. kwargs: Additional arguments to pass to the database constructor. Returns: A database instance.