1use mz_repr::{RelationDesc, SqlScalarType};
11use std::sync::LazyLock;
12
13pub static MZ_PREPARED_STATEMENT_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
14    RelationDesc::builder()
15        .with_column("id", SqlScalarType::Uuid.nullable(false))
16        .with_column("session_id", SqlScalarType::Uuid.nullable(false))
17        .with_column("name", SqlScalarType::String.nullable(false))
18        .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
19        .with_column(
20            "prepared_at",
21            SqlScalarType::TimestampTz { precision: None }.nullable(false),
22        )
23        .with_column("statement_type", SqlScalarType::String.nullable(true))
24        .with_column("throttled_count", SqlScalarType::UInt64.nullable(false))
25        .finish()
26});
27
28pub static MZ_SQL_TEXT_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
29    RelationDesc::builder()
30        .with_column(
31            "prepared_day",
32            SqlScalarType::TimestampTz { precision: None }.nullable(false),
33        )
34        .with_column("sql_hash", SqlScalarType::Bytes.nullable(false))
35        .with_column("sql", SqlScalarType::String.nullable(false))
36        .with_column("redacted_sql", SqlScalarType::String.nullable(false))
37        .finish()
38});
39
40pub static MZ_SESSION_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
41    RelationDesc::builder()
42        .with_column("session_id", SqlScalarType::Uuid.nullable(false))
43        .with_column(
44            "connected_at",
45            SqlScalarType::TimestampTz { precision: None }.nullable(false),
46        )
47        .with_column(
48            "initial_application_name",
49            SqlScalarType::String.nullable(false),
50        )
51        .with_column("authenticated_user", SqlScalarType::String.nullable(false))
52        .finish()
53});
54
55pub static MZ_STATEMENT_EXECUTION_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
62    RelationDesc::builder()
63        .with_column("id", SqlScalarType::Uuid.nullable(false))
64        .with_column("prepared_statement_id", SqlScalarType::Uuid.nullable(false))
65        .with_column("sample_rate", SqlScalarType::Float64.nullable(false))
66        .with_column("cluster_id", SqlScalarType::String.nullable(true))
67        .with_column("application_name", SqlScalarType::String.nullable(false))
68        .with_column("cluster_name", SqlScalarType::String.nullable(true))
69        .with_column("database_name", SqlScalarType::String.nullable(false))
70        .with_column(
71            "search_path",
72            SqlScalarType::List {
73                element_type: Box::new(SqlScalarType::String),
74                custom_id: None,
75            }
76            .nullable(false),
77        )
78        .with_column(
79            "transaction_isolation",
80            SqlScalarType::String.nullable(false),
81        )
82        .with_column("execution_timestamp", SqlScalarType::UInt64.nullable(true))
85        .with_column("transaction_id", SqlScalarType::UInt64.nullable(false))
86        .with_column("transient_index_id", SqlScalarType::String.nullable(true))
87        .with_column(
88            "params",
89            SqlScalarType::Array(Box::new(SqlScalarType::String)).nullable(false),
90        )
91        .with_column("mz_version", SqlScalarType::String.nullable(false))
92        .with_column(
93            "began_at",
94            SqlScalarType::TimestampTz { precision: None }.nullable(false),
95        )
96        .with_column(
97            "finished_at",
98            SqlScalarType::TimestampTz { precision: None }.nullable(true),
99        )
100        .with_column("finished_status", SqlScalarType::String.nullable(true))
101        .with_column("error_message", SqlScalarType::String.nullable(true))
102        .with_column("result_size", SqlScalarType::Int64.nullable(true))
103        .with_column("rows_returned", SqlScalarType::Int64.nullable(true))
104        .with_column("execution_strategy", SqlScalarType::String.nullable(true))
105        .finish()
106});
107
108pub static MZ_SOURCE_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
109    RelationDesc::builder()
110        .with_column(
111            "occurred_at",
112            SqlScalarType::TimestampTz { precision: None }.nullable(false),
113        )
114        .with_column("source_id", SqlScalarType::String.nullable(false))
115        .with_column("status", SqlScalarType::String.nullable(false))
116        .with_column("error", SqlScalarType::String.nullable(true))
117        .with_column("details", SqlScalarType::Jsonb.nullable(true))
118        .with_column("replica_id", SqlScalarType::String.nullable(true))
119        .finish()
120});
121
122pub static MZ_SINK_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
123    RelationDesc::builder()
124        .with_column(
125            "occurred_at",
126            SqlScalarType::TimestampTz { precision: None }.nullable(false),
127        )
128        .with_column("sink_id", SqlScalarType::String.nullable(false))
129        .with_column("status", SqlScalarType::String.nullable(false))
130        .with_column("error", SqlScalarType::String.nullable(true))
131        .with_column("details", SqlScalarType::Jsonb.nullable(true))
132        .with_column("replica_id", SqlScalarType::String.nullable(true))
133        .finish()
134});
135
136pub static MZ_AWS_PRIVATELINK_CONNECTION_STATUS_HISTORY_DESC: LazyLock<RelationDesc> =
137    LazyLock::new(|| {
138        RelationDesc::builder()
139            .with_column(
140                "occurred_at",
141                SqlScalarType::TimestampTz { precision: None }.nullable(false),
142            )
143            .with_column("connection_id", SqlScalarType::String.nullable(false))
144            .with_column("status", SqlScalarType::String.nullable(false))
145            .finish()
146    });
147
148pub static REPLICA_STATUS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
149    RelationDesc::builder()
150        .with_column("replica_id", SqlScalarType::String.nullable(false))
151        .with_column("process_id", SqlScalarType::UInt64.nullable(false))
152        .with_column("status", SqlScalarType::String.nullable(false))
153        .with_column("reason", SqlScalarType::String.nullable(true))
154        .with_column(
155            "occurred_at",
156            SqlScalarType::TimestampTz { precision: None }.nullable(false),
157        )
158        .finish()
159});
160
161pub static REPLICA_METRICS_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
165    RelationDesc::builder()
166        .with_column("replica_id", SqlScalarType::String.nullable(false))
167        .with_column("process_id", SqlScalarType::UInt64.nullable(false))
168        .with_column("cpu_nano_cores", SqlScalarType::UInt64.nullable(true))
169        .with_column("memory_bytes", SqlScalarType::UInt64.nullable(true))
170        .with_column("disk_bytes", SqlScalarType::UInt64.nullable(true))
171        .with_column(
172            "occurred_at",
173            SqlScalarType::TimestampTz { precision: None }.nullable(false),
174        )
175        .with_column("heap_bytes", SqlScalarType::UInt64.nullable(true))
176        .with_column("heap_limit", SqlScalarType::UInt64.nullable(true))
177        .finish()
178});
179
180pub static WALLCLOCK_LAG_HISTORY_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
181    RelationDesc::builder()
182        .with_column("object_id", SqlScalarType::String.nullable(false))
183        .with_column("replica_id", SqlScalarType::String.nullable(true))
184        .with_column("lag", SqlScalarType::Interval.nullable(true))
185        .with_column(
186            "occurred_at",
187            SqlScalarType::TimestampTz { precision: None }.nullable(false),
188        )
189        .finish()
190});
191
192pub static WALLCLOCK_GLOBAL_LAG_HISTOGRAM_RAW_DESC: LazyLock<RelationDesc> = LazyLock::new(|| {
193    RelationDesc::builder()
194        .with_column(
195            "period_start",
196            SqlScalarType::TimestampTz { precision: None }.nullable(false),
197        )
198        .with_column(
199            "period_end",
200            SqlScalarType::TimestampTz { precision: None }.nullable(false),
201        )
202        .with_column("object_id", SqlScalarType::String.nullable(false))
203        .with_column("lag_seconds", SqlScalarType::UInt64.nullable(true))
204        .with_column("labels", SqlScalarType::Jsonb.nullable(false))
205        .finish()
206});