Ledger

Warehouse

Reference for the data warehouse of Twisp ledgers.

The Basics

The Twisp ledger exports all data to AWS Redshift and exposes APIs to interact with the data using arbitrary SQL queries. When enabled on your tenant, this warehouse provides a convenient way to execute analytical queries or unload data to your own data lake or warehouse.

Components of Warehouse

GraphQL Interface

Twisp exposes the Redshift Data API in GraphQL format for execution of SQL queries. The most commonly used API interactions are described here.

Execute Statement

The execute statement API allows you to execute a statement on Redshift.

mutation ExecuteStatement($SQL:String! = "SELECT TRUE") {
  warehouse{
    executeStatement(input:{
      SQL: $SQL
    }) {
      id
    }
  }
}

Describe Statement

Describe Statement allows you to check on the status of a running query and retrieve metadata about it's results.

query DescribeStatement($id:String!) {
  warehouse{
    describeStatement(input:{
      id:$id
    }) {
      resultRows
      resultSize
      status
      error
    }
  }
}

Cancel Statement

Cancel statement cancels a running statement.

mutation CancelStatement($id:String!) {
  warehouse{
    cancelStatement(
      input:{
        id
      }
    )
  }
}

Get Statement Result

Get Statement Result allows you to fetch the results of a query via the API with paging. If the result is particularly large, you may opt to instead use the UNLOAD capabilty to export data in a suitable format to an S3 bucket of your choosing.

query GetStatementResult($id:String!) {
  warehouse{
    getStatementResult(input:{
      id:$id
      #nextToken:""
    }) {
      records {
        fields {
          type
          value {
            str
            bytes
            isNull
          }
        }
      }
      nextToken
    }
  }
}

Views and Schemas

Twisp maintains two views for each entity in the ledger:

  • entity: the latest version of any entity stored in the Twisp ledger.
  • entity_history: all versions of a particular record stored in the Twisp ledger.

Each record contains a number of header rows prepended with record_:

  • record_begin - A unique timestamp of when the Twisp database transaction began.
  • record_rowid - A uuid identifier of the particular item in Twisp.
  • record_status - An enumeration indicating whether this record is deleted.
  • record_tenantid - A uuid indicating the tenant that this record belongs to.
  • record_version - An monotonically increasing unsigned integer indicating the version of the record.

These columns allow for incremental exports via record_begin, which are guaranteed to be unique per transaction. In other words, records with the same timestamp originated within the same transaction. The record_rowid and record_version together uniquely identify a particular version of a record and is a convenient way to de-duplicate rows in the event you use overlapping timestamps to import data.

The following entities are available in the warehouse:

  • public.account
  • public.account_history
  • public.account_set
  • public.account_set_history
  • public.account_set_member
  • public.account_set_member_history
  • public.balance
  • public.balance_history
  • public.calculation
  • public.calculation_history
  • public.entry
  • public.entry_history
  • public.journal
  • public.journal_history
  • public.tran_code
  • public.tran_code_history
  • public.transaction
  • public.transaction_history
  • public.transaction_exception
  • public.transaction_exception_history
  • public.workflow_execution
  • public.workflow_execution_history

The schemas between each entity and entity_history view are identical and are provided below.

account

Every Account and Account Set in Twisp has an account record stored.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
account_idVARCHAR(36)
statusVARCHAR
nameSUPER
codeVARCHAR
normal_balance_typeVARCHAR
descriptionSUPER
metadataSUPER
createdTIMESTAMP
modifiedTIMESTAMP
external_idVARCHAR
config_enable_concurrent_postingBOOLEAN
config_is_account_setBOOLEAN

account_set

The account_set table has all Account Sets in the Twisp ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
account_set_idVARCHAR(36)
journal_idVARCHAR(36)
account_idVARCHAR(36)
nameVARCHAR
descriptionVARCHAR
metadataSUPER
createdTIMESTAMP
modifiedTIMESTAMP
config_enable_concurrent_postingBOOLEAN

account_set_member

The account_set_member table maintains the Account Set tree membership details. The member_id can refer to either an Account Set or Account, based on member_type.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
account_set_idVARCHAR(36)
journal_idVARCHAR(36)
member_typeVARCHAR
member_idVARCHAR(36)
createdTIMESTAMP

balance

Contains all Balance records and versions. Note that the dimension column is of VARBYTE type. If unloading, you must convert into a base64 encoded string:

SELECT FROM_VARBYTE(dimension,'base64') AS dimension FROM balance;
Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
journal_idVARCHAR(36)
account_idVARCHAR(36)
transaction_idVARCHAR(36)
entry_idVARCHAR(36)
currencyVARCHAR
settled_dr_balanceVARCHAR
settled_cr_balanceVARCHAR
settled_entry_idVARCHAR(36)
settled_modifiedTIMESTAMP
pending_dr_balanceVARCHAR
pending_cr_balanceVARCHAR
pending_entry_idVARCHAR(36)
pending_modifiedTIMESTAMP
encumbrance_dr_balanceVARCHAR
encumbrance_cr_balanceVARCHAR
encumbrance_entry_idVARCHAR(36)
encumbrance_modifiedTIMESTAMP
createdTIMESTAMP
modifiedTIMESTAMP
available_settled_dr_balanceVARCHAR
available_settled_cr_balanceVARCHAR
available_settled_entry_idVARCHAR(36)
available_settled_modifiedTIMESTAMP
available_pending_dr_balanceVARCHAR
available_pending_cr_balanceVARCHAR
available_pending_entry_idVARCHAR(36)
available_pending_modifiedTIMESTAMP
available_encumbrance_dr_balanceVARCHAR
available_encumbrance_cr_balanceVARCHAR
available_encumbrance_entry_idVARCHAR(36)
available_encumbrance_modifiedTIMESTAMP
calculation_idVARCHAR(36)
dimensionVARBYTE
dimensionsSUPER
entry_committedTIMESTAMP
entry_timestampsSUPER

calculation

Contains the calculation definitions in the Ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
calculation_idVARCHAR(36)
descriptionVARCHAR
codeVARCHAR
dimensionsSUPER
statusVARCHAR
createdTIMESTAMP
modifiedTIMESTAMP
conditionSUPER
skip_calculationBOOLEAN
backfill_statusVARCHAR

entry

All of the journal entries in the Ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
entry_idVARCHAR(36)
transaction_idVARCHAR(36)
transaction_seqBIGINT
journal_idVARCHAR(36)
account_idVARCHAR(36)
entry_typeVARCHAR
layerVARCHAR
directionVARCHAR
descriptionVARCHAR
amountVARCHAR
balance_record_idVARCHAR(36)
balance_record_versionBIGINT
createdTIMESTAMP
modifiedTIMESTAMP
metadataSUPER
committedTIMESTAMP
parent_account_idsSUPER
is_voided_entryBOOLEAN
is_void_entryBOOLEAN

journal

All of the journals in the Ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
journal_idVARCHAR(36)
nameVARCHAR
descriptionVARCHAR
statusVARCHAR
createdTIMESTAMP
modifiedTIMESTAMP
codeVARCHAR
config_enable_effective_balancesBOOLEAN

tran_code

All of the Transaction Code definitions in the Ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
tran_code_idVARCHAR(36)
codeVARCHAR
descriptionVARCHAR
statusVARCHAR
paramsSUPER
transaction_journal_idSUPER
transaction_correlation_idSUPER
transaction_external_idSUPER
transaction_effectiveSUPER
transaction_descriptionSUPER
transaction_metadataSUPER
entriesSUPER
createdTIMESTAMP
modifiedTIMESTAMP
metadataSUPER

transaction

All of the Transactions posted in the Ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
transaction_idVARCHAR(36)
tran_code_idVARCHAR(36)
journal_idVARCHAR(36)
correlation_idVARCHAR
external_idVARCHAR
effectiveDATE
descriptionVARCHAR
metadataSUPER
createdTIMESTAMP
modifiedTIMESTAMP
tran_code_versionBIGINT
void_ofVARCHAR(36)
voided_byVARCHAR(36)

transaction_exception

All Transaction Exceptions for WARN and VOID velocity control enforcements.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
transaction_idVARCHAR(36)
typeVARCHAR
error_messageVARCHAR
detailSUPER
createdTIMESTAMP

velocity_control

All Velocity Controls defined in the ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
velocity_control_idVARCHAR(36)
nameVARCHAR
descriptionVARCHAR
enforcementSUPER
conditionVARCHAR
createdTIMESTAMP
modifiedTIMESTAMP

velocity_limit

All Velocity Limits defined in the Ledger.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
velocity_limit_idVARCHAR(36)
nameVARCHAR
descriptionVARCHAR
windowSUPER
conditionSUPER
currencyVARCHAR
timestamp_sourceVARCHAR
limitSUPER
paramsSUPER
createdTIMESTAMP
modifiedTIMESTAMP

workflow_execution

A log of all workflow executions for workflow.execute.

Column NameType
record_beginTIMESTAMP
record_rowidVARCHAR(36)
record_statusVARCHAR
record_tenantidVARCHAR(36)
record_versionBIGINT
workflow_idVARCHAR(36)
execution_idVARCHAR(36)
taskVARCHAR
paramsSUPER
contextSUPER
createdTIMESTAMP
modifiedTIMESTAMP
outputSUPER

Warehouse Operations

Use GraphQL queries and mutations to execute queries and describe results in the data warehouse:

Previous
Versions and History