Query Results

After executing a query the query results can be accessed via the SDK in a query result set object.

Query Results are stored in the QueryResultSet object. This object is returned by:

  • Flipside.run

  • Flipside.get_query_results

class QueryResultSet(BaseModel):
    query_id: Union[str, None] = Field(None, description="The server id of the query")

    status: str = Field(
        False, description="The status of the query (`PENDING`, `FINISHED`, `ERROR`)"
    )
    columns: Union[List[str], None] = Field(
        None, description="The names of the columns in the result set"
    )
    column_types: Union[List[str], None] = Field(
        None, description="The type of the columns in the result set"
    )
    rows: Union[List[Any], None] = Field(None, description="The results of the query")
    run_stats: Union[QueryRunStats, None] = Field(
        None,
        description="Summary stats on the query run (i.e. the number of rows returned, the elapsed time, etc)",
    )
    records: Union[List[Any], None] = Field(
        None, description="The results of the query transformed as an array of objects"
    )
    page: Union[PageStats, None] = Field(
        None, description="Summary of page stats for this query result set"
    )
    error: Any

Results are accessible via rows and records. Rows is an array of arrays (CSV format), while records are an array of objects where the keys are the column names.

Run Stats

Run stats provide a summary of the entire result set from the number of rows returned, the number of bytes returned, and a breakdown of time spent on each part of the query run's lifecycle.

Python QueryRunStats object, which can be accessed on the QueryResultSet via run_stats

class QueryRunStats(BaseModel):
    started_at: datetime = Field(None, description="The start time of the query run.")
    ended_at: datetime = Field(None, description="The end time of the query run.")
    query_exec_started_at: datetime = Field(
        None, description="The start time of query execution."
    )
    query_exec_ended_at: datetime = Field(
        None, description="The end time of query execution."
    )
    streaming_started_at: datetime = Field(
        None, description="The start time of streaming query results."
    )
    streaming_ended_at: datetime = Field(
        None, description="The end time of streaming query results."
    )
    elapsed_seconds: int = Field(
        None,
        description="The number of seconds elapsed between the start and end times.",
    )
    queued_seconds: int = Field(
        None,
        description="The number of seconds elapsed between when the query was created and when execution on the data source began.",
    )
    streaming_seconds: int = Field(
        None,
        description="The number of seconds elapsed between when the query execution completed and results were fully streamed to Flipside's servers.",
    )
    query_exec_seconds: int = Field(
        None,
        description="The number of seconds elapsed between when the query execution started and when it completed on the data source.",
    )
    record_count: int = Field(
        None, description="The number of records returned by the query."
    )
    bytes: int = Field(None, description="The number of bytes returned by the query.")

query_exec_seconds represents the number of QuerySeconds used by the query that you will be billed/debited for. Note you are not billed/debited for queued, streaming, or total seconds, only execution seconds. For more information on QuerySeconds see the QuerySeconds section here.

Page

The page object returns stats about the current page of results as well as the total available pages given the specified page size you provided when requesting the results.

For example, if there are 1 million rows returned by a query and you request results with a page size of 10,000 rows, the total number of pages will be 100.

class PageStats(BaseModel):
    currentPageNumber: int
    currentPageSize: int
    totalRows: int
    totalPages: int

Assuming we have query_result_set variable you can access the total number of pages simply by calling:

print(query_result_set.page.totalPages)

In the next example we'll show you how to use PageStats to iterate over a Query Result Set.

Last updated