SQL engine and data schema

The Pyrus visualization engine uses ClickHouse — a high-performance column-oriented database management system, ideally suited for complex analytical queries (OLAP). This allows for fast processing of large volumes of data and building reports in real time.

How report creation works

The process of transforming your SQL query into a ready-made widget goes through several steps.

  1. You write an SQL query in the editor, which may include aliases and parameters.
  2. When you click the Execute button, the parameters are replaced with actual values from the user interface (for example, selected filters, task field values).
  3. The final query is sent to ClickHouse, which forms a selection from the #tasks or #events tables into a single table.
  4. After receiving a response from ClickHouse, aliases are recognized and applied (for example, the task ID is converted into an active link to the task).
  5. The final, formatted result is displayed to the user as a widget.

Note: if the query is incorrect, the system immediately reports an error (for example, syntax errors).

Terminology

Two types of special markers are used in SQL queries to help link a static query with the dynamic context of Pyrus.

TermDescriptionUsage in SQL
AliasesTransform system numeric IDs (statuses, users, stages) into human-readable names or links after receiving data from ClickHouseExclusively in SELECT AS.
ParametersDynamically embed actual values from tasks, as well as selected interface filter values before sending to ClickHouseFROM, WHERE, HAVING, ORDER BY.

Data sources

Two main tables are used for building reports, differing in nature: the current state table #tasks and the event history table #events.

Common fields for #tasks and #events

This section presents all fields that are available for use in both tables.

Note: When using these parameters with the #tasks table, the result will be the current state of the field; when called in #events, the result will be the value in the considered time interval.

FieldDescriptionClickHouse typeDefault value
form_idForm IDUInt32
task_idTask IDUInt32
${Выбор}Choice type field, value IDNullable(Int64)Null
${Checkmark}Checkmark type field, true / falseNullable(Bool)Null
${Catalog:N}Catalog type field, selected text value from column N in the catalogArray(Nullable(String))Null
${Form}Form type field, task IDNullable(Int64)Null
${Number}Number type field, entered numberNullable(Float64)Null
${Money}Money type field, entered numberNullable(Float64)Null
${Date}Date type field, entered numberNullable(DateTime64(9,'UTC'))Null
${Time}Time type field, entered numberNullable(DateTime64(9,'UTC'))Null
${Contact}Contact type field, user IDNullable(Int64)Null
is_closedOpen / Completed type field, true / falseBoolFalse
responsible_idResponsible type field, user IDInt320
create_dateCreation date type fieldDateTime64(3,'UTC')
stepStep type field, step IDInt160
statusStatus type field, status IDInt160

The #tasks table

This table contains the current status of tasks (for example, form fields, task status). In addition to system fields, all fields created in the form are available for selection from this table through their parameters. Each task corresponds to exactly one row. The fields listed in this section are unique and not available for use in the #events table.

Pyrus Tip: use to analyze current metrics, for example: how many tasks are in progress, what their current status is, etc.

FieldDescriptionClickHouse typeDefault value
dueDue date type fieldsDateTime64(3,'UTC')2200-01-01
is_overdueTask overdueBoolFalse
creator_idTask creator IDUInt32System: 1730 Subprocess: 656701
last_note_idID of last commentUInt64
last_modified_dateDate of last modificationDateTime64(3,'UTC')
close_dateDate task was closedDateTime64(3,'UTC')2200-01-01

The #events table

This table stores the chronology of all changes to the task. Each row is a separate recorded system event (for example, change of responsible person, addition of a comment, change of status). At the same time, one row can correspond to multiple changes within the system.

Pyrus tip: Use #events for metrics related to time, transitions, and auditing: how long a stage took, who and when made changes to the task, etc.

FieldDescriptionClickHouse typeDefault value
note_idComment IDUInt64
author_idEvent author IDUInt320
task_createdTask generated by this eventBoolFalse
operator_replyOperator reply (outgoing message to an external channel)BoolFalse
task_dueDue date type fieldDateTime64(3,'UTC')2200-01-01
is_task_overdueThe task is overdue at the time of eventBoolFalse
task_create_dateDate task was createdDateTime64(3,'UTC')
task_creator_idTask creator IDUInt32System: 1730 Subprocess: 656701

approval_type

Current values:

0 – not indicated

1 – approved

2 – denied

3 – deferred

4 – reviewed

Resolution: Approved, Reviewed, etc.

Int8

0

spent_timeTime spent on task, in minutesInt320
comment_as_role_idID of role in whose name the comment is writtenInt320
is_step_changedThe step has changed in this eventBoolFalse
previous_stepPrevious stepInt16-1
seconds_in_stepHow many seconds were spent on the previous stepInt640
is_step_frozenIs the SLA frozen on the previous stepBoolFalse
is_step_overdueHas the previous stage ended after its established deadlineBool
is_status_changedThe status has changed in this eventBoolFalse
previous_statusPrevious statusInt16-1
is_status_frozenIs the SLA frozen at the previous statusBoolFalse
is_status_overdueHas the previous status changed after its established deadlineBoolFalse
is_responsible_changedThe assignee has changed in this eventBoolFalse
previous_responsible_idPrevious responsible personInt32-1

The following form fields are not supported in the visualization engine:

  • User fields: Text, Telephone, Email;
  • Formatting fields: Table, Comment.

Alias and parameter system

Aliases and parameters are special markers that allow linking a static SQL query with the dynamic context of Pyrus.

Aliases (SELECT AS)

Aliases are used only as aliases (AS) in the SELECT section. They convert numeric data into text or links.

Pyrus Tip: if you do not use an alias, the original numeric value (ID, status code, etc.) will be displayed in the column.

Alias descriptionAliasUsage
User ID → FullName#person_full_name('Heading')responsible_id AS "#person_full_name('Responsible')"
User ID → Name of department#person_department('Heading')responsible_id AS "#person_department('Department')"
Status ID → Status name#status_name('Heading')status AS "#status_name('Status')"
Step ID → Name of step#step_name('Heading')step AS "#step_name('Step')"
Selection type field ID → Value of Selection type field#choice_name(${Field code}) #choice_name(${Field code}, 'Heading')${Channel} AS "#choice_name(${Channel},'Channel of contact')
Task ID → Task name#task('Heading')task_id AS "#task('Task')"

Parameters (embedded in SQL)

Parameters dynamically influence what is queried from the database, and how.

Parameter descriptionParameterUsage
Selection of data source#tasks / #eventsFROM #tasks (for current state); FROM #events (for history)
Beginning/end of selected date range.@period_start / @period_endWHERE create_date >= @period_start
The expression corresponding to the filters that the user selected in the summary interface for the request on the current status of the task.#task_filtersWHERE #task_filters — uses filters selected by the user in the report interface.
Similar to the parameter #task_filters, but used in HAVING for queries to historical data in #events.#event_filtersHAVING #event_filters — uses filters specific to working with the #events table.
Used in ORDER BY for correct sorting of statuses according to their order in the form settings#ordered_statusesORDER BY #ordered_statuses — ensures correct sorting of statuses in the output according to their order in the form settings.

Restrictions

  • All SQL queries to the data are executed in read mode. Only SELECT operations are available.
  • The maximum number of rows in the result table is 1000.
  • The maximum processing time for an SQL query is 10 seconds.

Was this article helpful?