🔍 Code Extractor

class IterationResult

Maturity: 45

A dataclass that encapsulates the complete results of a single iteration in a two-pass process, including table selection, SQL generation, and execution outcomes.

File:
/tf/active/vicechatdev/full_smartstat/two_pass_sql_workflow.py
Lines:
37 - 45
Complexity:
simple

Purpose

This class serves as a structured container for storing and passing around the comprehensive results of a complete iteration that involves both table selection and SQL generation passes. It tracks the iteration number, the results from each pass, execution status, and performance metrics. This is typically used in iterative query generation or optimization workflows where multiple attempts may be made to generate and execute SQL queries.

Source Code

class IterationResult:
    """Result of a complete iteration (both passes)"""
    iteration_number: int
    table_selection: TableSelectionResult
    sql_generation: SqlGenerationResult
    execution_success: bool
    error_message: Optional[str] = None
    execution_time: Optional[float] = None
    row_count: Optional[int] = None

Parameters

Name Type Default Kind
bases - -

Parameter Details

iteration_number: An integer representing the sequential number of this iteration in a multi-iteration process. Used to track which attempt this result corresponds to.

table_selection: A TableSelectionResult object containing the results from the table selection pass, including which tables were chosen and any related metadata.

sql_generation: A SqlGenerationResult object containing the results from the SQL generation pass, including the generated SQL query and any generation metadata.

execution_success: A boolean flag indicating whether the SQL query execution completed successfully (True) or failed (False).

error_message: An optional string containing the error message if execution failed. None if execution was successful or no error occurred.

execution_time: An optional float representing the time taken to execute the query in seconds. None if execution did not occur or timing was not recorded.

row_count: An optional integer representing the number of rows returned by the executed query. None if execution failed or row count was not captured.

Return Value

Instantiation returns an IterationResult object that holds all the data about a complete iteration. As a dataclass, it automatically generates __init__, __repr__, and __eq__ methods. The object itself serves as a data container and does not return values from methods (it has no custom methods).

Class Interface

Attributes

Name Type Description Scope
iteration_number int The sequential number of this iteration in a multi-iteration process instance
table_selection TableSelectionResult The result object from the table selection pass containing selected tables and metadata instance
sql_generation SqlGenerationResult The result object from the SQL generation pass containing the generated query and metadata instance
execution_success bool Flag indicating whether the SQL query executed successfully without errors instance
error_message Optional[str] Error message if execution failed, None otherwise. Default is None. instance
execution_time Optional[float] Time taken to execute the query in seconds, None if not measured. Default is None. instance
row_count Optional[int] Number of rows returned by the executed query, None if execution failed or not captured. Default is None. instance

Dependencies

  • dataclasses
  • typing

Required Imports

from dataclasses import dataclass
from typing import Optional

Usage Example

from dataclasses import dataclass
from typing import Optional

# Assuming TableSelectionResult and SqlGenerationResult are defined
table_result = TableSelectionResult(selected_tables=['users', 'orders'])
sql_result = SqlGenerationResult(query='SELECT * FROM users', valid=True)

# Create a successful iteration result
result = IterationResult(
    iteration_number=1,
    table_selection=table_result,
    sql_generation=sql_result,
    execution_success=True,
    error_message=None,
    execution_time=0.523,
    row_count=150
)

# Create a failed iteration result
failed_result = IterationResult(
    iteration_number=2,
    table_selection=table_result,
    sql_generation=sql_result,
    execution_success=False,
    error_message='Table not found: users',
    execution_time=0.012,
    row_count=None
)

# Access attributes
print(f'Iteration {result.iteration_number} returned {result.row_count} rows')
if not failed_result.execution_success:
    print(f'Error: {failed_result.error_message}')

Best Practices

  • This is an immutable data container (dataclass) - treat it as a value object representing a snapshot of iteration results
  • Always provide valid TableSelectionResult and SqlGenerationResult objects when instantiating
  • Set execution_success to False and provide error_message when query execution fails
  • Only populate execution_time and row_count when execution actually occurs
  • Use None for optional fields (error_message, execution_time, row_count) when they don't apply
  • The iteration_number should be sequential and start from 1 or 0 depending on your convention
  • This class is designed for read-only access after creation - avoid modifying attributes after instantiation
  • Consider using this in a list or collection to track multiple iterations over time
  • When execution_success is True, error_message should typically be None
  • When execution_success is False, row_count should typically be None

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class QueryIteration 78.3% similar

    A dataclass representing a single iteration in an iterative SQL query generation and evaluation workflow, capturing the query, its results, assessment, and improvement suggestions.

    From: /tf/active/vicechatdev/full_smartstat/enhanced_sql_workflow.py
  • class SqlGenerationResult 70.1% similar

    A dataclass that encapsulates the results of an SQL query generation operation, including the generated query, explanation, confidence score, and metadata about database objects used.

    From: /tf/active/vicechatdev/full_smartstat/two_pass_sql_workflow.py
  • class TableSelectionResult 69.6% similar

    A dataclass that encapsulates the results of a table selection operation, including selected tables, reasoning, confidence score, and suggested joins.

    From: /tf/active/vicechatdev/full_smartstat/two_pass_sql_workflow.py
  • class AnalysisResult_v1 65.9% similar

    A dataclass that encapsulates the results from statistical analysis operations, including metadata, file paths, and timestamps.

    From: /tf/active/vicechatdev/vice_ai/models.py
  • class AnalysisResult 65.3% similar

    A dataclass that encapsulates the results from statistical analysis operations, including metadata, file paths, and timestamps.

    From: /tf/active/vicechatdev/vice_ai/smartstat_models.py
← Back to Browse