@housekit/orm 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +224 -0
  3. package/dist/builders/delete.d.ts +21 -0
  4. package/dist/builders/insert.d.ts +128 -0
  5. package/dist/builders/prepared.d.ts +11 -0
  6. package/dist/builders/select.d.ts +352 -0
  7. package/dist/builders/select.types.d.ts +76 -0
  8. package/dist/builders/update.d.ts +23 -0
  9. package/dist/client.d.ts +52 -0
  10. package/dist/codegen/zod.d.ts +4 -0
  11. package/dist/column.d.ts +76 -0
  12. package/dist/compiler.d.ts +27 -0
  13. package/dist/core.d.ts +6 -0
  14. package/dist/data-types.d.ts +150 -0
  15. package/dist/dictionary.d.ts +263 -0
  16. package/dist/engines.d.ts +558 -0
  17. package/dist/expressions.d.ts +72 -0
  18. package/dist/external.d.ts +177 -0
  19. package/dist/index.d.ts +187 -0
  20. package/dist/index.js +222 -0
  21. package/dist/logger.d.ts +8 -0
  22. package/dist/materialized-views.d.ts +271 -0
  23. package/dist/metadata.d.ts +33 -0
  24. package/dist/modules/aggregates.d.ts +205 -0
  25. package/dist/modules/array.d.ts +122 -0
  26. package/dist/modules/conditional.d.ts +110 -0
  27. package/dist/modules/conversion.d.ts +189 -0
  28. package/dist/modules/geo.d.ts +202 -0
  29. package/dist/modules/hash.d.ts +7 -0
  30. package/dist/modules/index.d.ts +12 -0
  31. package/dist/modules/json.d.ts +130 -0
  32. package/dist/modules/math.d.ts +28 -0
  33. package/dist/modules/string.d.ts +167 -0
  34. package/dist/modules/time.d.ts +154 -0
  35. package/dist/modules/types.d.ts +177 -0
  36. package/dist/modules/window.d.ts +27 -0
  37. package/dist/relational.d.ts +33 -0
  38. package/dist/relations.d.ts +15 -0
  39. package/dist/schema-builder.d.ts +172 -0
  40. package/dist/table.d.ts +172 -0
  41. package/dist/utils/background-batcher.d.ts +20 -0
  42. package/dist/utils/batch-transform.d.ts +20 -0
  43. package/dist/utils/binary-reader.d.ts +48 -0
  44. package/dist/utils/binary-serializer.d.ts +160 -0
  45. package/dist/utils/binary-worker-code.d.ts +1 -0
  46. package/dist/utils/binary-worker-pool.d.ts +76 -0
  47. package/dist/utils/binary-worker.d.ts +12 -0
  48. package/dist/utils/insert-processing.d.ts +23 -0
  49. package/dist/utils/lru-cache.d.ts +10 -0
  50. package/package.json +68 -0
@@ -0,0 +1,271 @@
1
+ /**
2
+ * HouseKit Materialized Views DSL - Type-Safe Materialized Views
3
+ *
4
+ * Unlike generic ORMs which often treat materialized views as static SQL strings,
5
+ * HouseKit allows defining MV queries using the Query Builder for
6
+ * compile-time type safety. If you rename a column in the source table,
7
+ * TypeScript will catch the error before deployment.
8
+ */
9
+ import { ClickHouseColumn } from './column';
10
+ import { type TableDefinition, type TableColumns } from './table';
11
+ import { EngineConfiguration } from './engines';
12
+ import { type SQLExpression } from './expressions';
13
+ /**
14
+ * Helper type to extract columns from a TableDefinition
15
+ */
16
+ export type InferTableColumns<T> = T extends TableDefinition<infer TCols> ? TCols : TableColumns;
17
+ /**
18
+ * Helper type to ensure we have access to $columns
19
+ */
20
+ type TableWithColumns<TCols extends TableColumns> = {
21
+ $table: string;
22
+ $columns: TCols;
23
+ };
24
+ /**
25
+ * Configuration for type-safe materialized views
26
+ */
27
+ export interface MaterializedViewConfig<TSource extends TableDefinition<any>, TTargetCols extends TableColumns = TableColumns> {
28
+ /**
29
+ * Source table(s) for the materialized view.
30
+ * This is used to provide type information for the query builder.
31
+ */
32
+ source: TSource;
33
+ /**
34
+ * The query definition for the materialized view.
35
+ * Use the query builder to ensure type safety.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * query: (qb) => qb
40
+ * .from(events)
41
+ * .select({
42
+ * eventType: events.event_type,
43
+ * count: sql`count()`
44
+ * })
45
+ * .groupBy(events.event_type)
46
+ * ```
47
+ */
48
+ query: (qb: MaterializedViewQueryBuilder<TSource>) => MaterializedViewQueryBuilder<any>;
49
+ /**
50
+ * Target table to write materialized data to.
51
+ * If not specified, ClickHouse creates an internal table.
52
+ *
53
+ * Can be:
54
+ * - A string table name
55
+ * - A TableDefinition reference (type-safe)
56
+ */
57
+ toTable?: string | TableDefinition<TTargetCols>;
58
+ /**
59
+ * Cluster name for distributed materialized view
60
+ */
61
+ onCluster?: string;
62
+ /**
63
+ * Whether to populate the MV with existing data on creation.
64
+ * Warning: Can be slow and resource-intensive for large tables.
65
+ */
66
+ populate?: boolean;
67
+ /**
68
+ * Engine configuration for the internal table (when toTable is not specified).
69
+ * Uses the type-safe Engine DSL.
70
+ */
71
+ engine?: EngineConfiguration;
72
+ /**
73
+ * Whether to use OR REPLACE semantics
74
+ */
75
+ orReplace?: boolean;
76
+ /**
77
+ * Optional ORDER BY for the internal storage table
78
+ */
79
+ orderBy?: string | string[];
80
+ /**
81
+ * Optional partition by for the internal storage table
82
+ */
83
+ partitionBy?: string | string[];
84
+ }
85
+ /**
86
+ * Simplified query builder for materialized view definitions.
87
+ * This is a subset of the full ClickHouseQueryBuilder that generates
88
+ * SQL without executing queries.
89
+ */
90
+ export interface MaterializedViewQueryBuilder<TTable extends TableDefinition<any>> {
91
+ select<TSelection extends Record<string, ClickHouseColumn | SQLExpression>>(fields: TSelection): MaterializedViewQueryBuilder<TTable>;
92
+ from<TNewTable extends TableDefinition<any>>(table: TNewTable): MaterializedViewQueryBuilder<TNewTable>;
93
+ where(expression: SQLExpression): MaterializedViewQueryBuilder<TTable>;
94
+ groupBy(...cols: (ClickHouseColumn | SQLExpression)[]): MaterializedViewQueryBuilder<TTable>;
95
+ having(expression: SQLExpression): MaterializedViewQueryBuilder<TTable>;
96
+ orderBy(col: ClickHouseColumn | SQLExpression, dir?: 'ASC' | 'DESC'): MaterializedViewQueryBuilder<TTable>;
97
+ limit(val: number): MaterializedViewQueryBuilder<TTable>;
98
+ innerJoin(table: TableDefinition<any>, on: SQLExpression): MaterializedViewQueryBuilder<TTable>;
99
+ leftJoin(table: TableDefinition<any>, on: SQLExpression): MaterializedViewQueryBuilder<TTable>;
100
+ toSQL(): {
101
+ query: string;
102
+ params: Record<string, unknown>;
103
+ };
104
+ }
105
+ /**
106
+ * Extended type for materialized views - contains table-like properties
107
+ * plus MV-specific metadata for drift detection and query tracking.
108
+ */
109
+ export type MaterializedViewDefinition<TCols extends TableColumns, TSource extends TableDefinition<any>, TOptions = MaterializedViewConfig<TSource>> = {
110
+ $table: string;
111
+ $columns: TCols;
112
+ $options: TOptions;
113
+ $kind: 'materializedView';
114
+ $source: TSource;
115
+ $querySQL: string;
116
+ $config: TOptions;
117
+ /**
118
+ * Get the SQL to create the materialized view
119
+ */
120
+ toSQL(): string;
121
+ /**
122
+ * Get all SQL statements (for views that need multiple statements)
123
+ */
124
+ toSQLs(): string[];
125
+ /**
126
+ * Create an aliased version for use in queries
127
+ */
128
+ as(alias: string): MaterializedViewDefinition<TCols, TSource, TOptions>;
129
+ } & TCols;
130
+ /**
131
+ * Result type for projection definitions using query builder
132
+ */
133
+ export interface TypedProjectionDefinition<TSource extends TableDefinition<any>> {
134
+ name: string;
135
+ query: string;
136
+ sourceTable: TSource;
137
+ orderBy?: string[];
138
+ }
139
+ /**
140
+ * Create a type-safe materialized view definition.
141
+ * The query is defined using a query builder that validates column references
142
+ * at compile time.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { defineMaterializedView, text, uint64, sql, Engine } from '@housekit/orm';
147
+ *
148
+ * // Source table
149
+ * const events = defineTable('events', {
150
+ * event_type: t.text('event_type'),
151
+ * user_id: t.text('user_id'),
152
+ * revenue: t.uint64('revenue'),
153
+ * }, { engine: Engine.MergeTree(), orderBy: 'event_type' });
154
+ *
155
+ * // Type-safe materialized view
156
+ * export const revenueByEvent = defineMaterializedView('revenue_by_event_mv', {
157
+ * event_type: t.text('event_type'),
158
+ * total_revenue: t.uint64('total_revenue'),
159
+ * event_count: t.uint64('event_count'),
160
+ * }, {
161
+ * source: events,
162
+ * query: (qb) => qb
163
+ * .from(events) // Type-safe: only accepts events columns
164
+ * .select({
165
+ * event_type: events.event_type,
166
+ * total_revenue: sql`sum(${events.revenue})`,
167
+ * event_count: sql`count()`,
168
+ * })
169
+ * .groupBy(events.event_type),
170
+ * engine: Engine.SummingMergeTree(['total_revenue', 'event_count']),
171
+ * orderBy: 'event_type',
172
+ * });
173
+ * ```
174
+ */
175
+ export declare function chMaterializedView<TCols extends TableColumns, TSource extends TableDefinition<any>, TTarget extends TableColumns = TCols>(name: string, columns: TCols, config: MaterializedViewConfig<TSource, TTarget>): MaterializedViewDefinition<TCols, TSource, MaterializedViewConfig<TSource, TTarget>>;
176
+ /**
177
+ * Create a type-safe projection definition.
178
+ *
179
+ * Projections are precomputed aggregations stored alongside the main table.
180
+ * They're automatically used by ClickHouse when the query matches.
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * const events = defineTable('events', {
185
+ * event_type: t.text('event_type'),
186
+ * user_id: t.text('user_id'),
187
+ * created_at: t.timestamp('created_at'),
188
+ * }, {
189
+ * engine: Engine.MergeTree(),
190
+ * orderBy: ['event_type', 'created_at'],
191
+ * projections: [
192
+ * // Type-safe projection
193
+ * chProjection('events_by_user', events, (cols) => ({
194
+ * select: {
195
+ * user_id: cols.user_id,
196
+ * event_type: cols.event_type,
197
+ * event_count: sql`count()`,
198
+ * },
199
+ * groupBy: [cols.user_id, cols.event_type],
200
+ * orderBy: ['user_id', 'event_type'],
201
+ * })),
202
+ * ],
203
+ * });
204
+ * ```
205
+ */
206
+ export declare function chProjection<TCols extends TableColumns, TSource extends TableDefinition<TCols>>(name: string, sourceTable: TSource & TableWithColumns<TCols>, definition: (cols: TCols) => {
207
+ select: Record<string, ClickHouseColumn | SQLExpression>;
208
+ groupBy?: (ClickHouseColumn | SQLExpression)[];
209
+ orderBy?: string[];
210
+ }): TypedProjectionDefinition<TSource>;
211
+ /**
212
+ * Convert a TypedProjectionDefinition to the format expected by defineTable
213
+ */
214
+ export declare function toProjectionDefinition(projection: TypedProjectionDefinition<any>): {
215
+ name: string;
216
+ query: string;
217
+ };
218
+ /**
219
+ * Normalize SQL for comparison (removes extra whitespace, normalizes case)
220
+ */
221
+ export declare function normalizeSQL(sql: string): string;
222
+ /**
223
+ * Compare two materialized view definitions for drift
224
+ */
225
+ export declare function detectMaterializedViewDrift(local: MaterializedViewDefinition<any, any>, remoteSQL: string): {
226
+ hasDrift: boolean;
227
+ localSQL: string;
228
+ remoteSQL: string;
229
+ normalizedLocal: string;
230
+ normalizedRemote: string;
231
+ };
232
+ /**
233
+ * Extract the AS query from a CREATE MATERIALIZED VIEW statement
234
+ */
235
+ export declare function extractMVQuery(createStatement: string): string | null;
236
+ /**
237
+ * Generate a Blue-Green migration plan for a Materialized View update.
238
+ *
239
+ * Instead of just dropping and recreating, we:
240
+ * 1. Create a "next" version of the target table (if using TO table)
241
+ * 2. Create a "next" version of the MV
242
+ * 3. Backfill data from source table using the NEW query
243
+ * 4. Swap them using RENAME
244
+ */
245
+ export declare function generateBlueGreenMigration(oldMV: MaterializedViewDefinition<any, any>, newMV: MaterializedViewDefinition<any, any>, options?: {
246
+ backfill?: boolean;
247
+ }): string[];
248
+ /**
249
+ * Creates a "migration bridge" Materialized View that synchronizes data from an old table to a new one.
250
+ * This is extremely useful for zero-downtime migrations where you need to pipe real-time
251
+ * inserts from the v1 table into the v2 table while you perform a separate historical backfill.
252
+ *
253
+ * @example
254
+ * ```typescript
255
+ * const bridge = createMigrationBridge({
256
+ * from: tableV1,
257
+ * to: tableV2,
258
+ * mapping: {
259
+ * new_col: sql`upper(${tableV1.old_col})`
260
+ * }
261
+ * });
262
+ * ```
263
+ */
264
+ export declare function createMigrationBridge<TSourceCols extends TableColumns, TTargetCols extends TableColumns>(options: {
265
+ from: TableDefinition<TSourceCols>;
266
+ to: TableDefinition<TTargetCols>;
267
+ mapping?: Record<string, ClickHouseColumn | SQLExpression>;
268
+ name?: string;
269
+ onCluster?: string;
270
+ }): MaterializedViewDefinition<TTargetCols, TableDefinition<TSourceCols>>;
271
+ export {};
@@ -0,0 +1,33 @@
1
+ export declare const supportedMetadataVersions: readonly ["1.1.0", "1.2.0"];
2
+ export type MetadataVersion = typeof supportedMetadataVersions[number];
3
+ export declare const defaultMetadataVersion: MetadataVersion;
4
+ export type HousekitMetadata = {
5
+ version: '1.1.0';
6
+ appendOnly: boolean;
7
+ } | {
8
+ version: '1.2.0';
9
+ appendOnly: boolean;
10
+ readOnly: boolean;
11
+ };
12
+ export declare const housekitMetadataSchemas: Record<MetadataVersion, Record<string, string>>;
13
+ export declare const housekitMetadataDefaults: Record<MetadataVersion, {
14
+ appendOnly: boolean;
15
+ readOnly?: boolean;
16
+ }>;
17
+ export declare function assertMetadataVersion(version: string): asserts version is MetadataVersion;
18
+ export declare function getMetadataDefaults(version: MetadataVersion): {
19
+ appendOnly: boolean;
20
+ readOnly?: boolean;
21
+ };
22
+ export declare function buildHousekitMetadata(version: MetadataVersion, opts: {
23
+ appendOnly?: boolean;
24
+ readOnly?: boolean;
25
+ }): HousekitMetadata;
26
+ export declare function normalizeHousekitMetadata(raw: any): {
27
+ version: MetadataVersion;
28
+ meta: HousekitMetadata;
29
+ } | null;
30
+ export declare function upgradeMetadataVersion(base: HousekitMetadata | null, targetVersion: MetadataVersion, overrides?: {
31
+ appendOnly?: boolean;
32
+ readOnly?: boolean;
33
+ }): HousekitMetadata;
@@ -0,0 +1,205 @@
1
+ import { ClickHouseColumn } from '../core';
2
+ import { SQLExpression } from '../expressions';
3
+ /**
4
+ * Count rows or non-null values in column
5
+ * @param col - Column to count (optional, defaults to all rows)
6
+ */
7
+ export declare function count(col?: ClickHouseColumn | SQLExpression): SQLExpression;
8
+ /**
9
+ * Get minimum value
10
+ * @param col - Column to find minimum
11
+ */
12
+ export declare function min<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
13
+ /**
14
+ * Get maximum value
15
+ * @param col - Column to find maximum
16
+ */
17
+ export declare function max<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
18
+ /**
19
+ * Calculate sum of values
20
+ * @param col - Column to sum
21
+ */
22
+ export declare function sum(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
23
+ /**
24
+ * Calculate average of values
25
+ * @param col - Column to average
26
+ */
27
+ export declare function avg(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
28
+ /**
29
+ * Count approximate unique values (HyperLogLog)
30
+ * @param col - Column to count unique values
31
+ */
32
+ export declare function uniq(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
33
+ /**
34
+ * Count exact unique values (ClickHouse-native naming)
35
+ * @param col - Column to count unique values
36
+ */
37
+ export declare function uniqExact(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
38
+ /**
39
+ * Count exact unique values (SQL-standard naming)
40
+ * @param col - Column to count unique values
41
+ */
42
+ export declare function countDistinct(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
43
+ /**
44
+ * Create an array from all values in the group
45
+ * @param expr - Expression to aggregate into array
46
+ */
47
+ export declare function groupArray<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T[]>;
48
+ /**
49
+ * Create an array of unique values from all values in the group
50
+ * @param expr - Expression to aggregate into unique array
51
+ */
52
+ export declare function groupUniqArray<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T[]>;
53
+ /**
54
+ * Get any value from the group (non-deterministic)
55
+ * @param expr - Expression to get any value from
56
+ */
57
+ export declare function any<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
58
+ /**
59
+ * Get any value from the group, preferring the last one
60
+ * @param expr - Expression to get any value from
61
+ */
62
+ export declare function anyLast<T>(expr: ClickHouseColumn<T, any, any> | SQLExpression<T>): SQLExpression<T>;
63
+ /**
64
+ * Get the value with the minimum weight
65
+ * Extremely useful in logs/metrics/"latest state" queries
66
+ * @param value - The value to return when weight is minimum
67
+ * @param weight - The weight to compare
68
+ */
69
+ export declare function argMin<T>(value: ClickHouseColumn<T, any, any> | SQLExpression<T>, weight: ClickHouseColumn | SQLExpression): SQLExpression<T>;
70
+ /**
71
+ * Get the value with the maximum weight
72
+ * Extremely useful in logs/metrics/"latest state" queries
73
+ * @param value - The value to return when weight is maximum
74
+ * @param weight - The weight to compare
75
+ */
76
+ export declare function argMax<T>(value: ClickHouseColumn<T, any, any> | SQLExpression<T>, weight: ClickHouseColumn | SQLExpression): SQLExpression<T>;
77
+ /**
78
+ * Calculate standard deviation
79
+ * @param col - Column to calculate standard deviation
80
+ */
81
+ export declare function stddevSamp(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
82
+ /**
83
+ * Calculate population standard deviation
84
+ * @param col - Column to calculate standard deviation
85
+ */
86
+ export declare function stddevPop(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
87
+ /**
88
+ * Calculate sample variance
89
+ * @param col - Column to calculate variance
90
+ */
91
+ export declare function varSamp(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
92
+ /**
93
+ * Calculate population variance
94
+ * @param col - Column to calculate variance
95
+ */
96
+ export declare function varPop(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
97
+ /**
98
+ * Calculate median
99
+ * @param col - Column to calculate median
100
+ */
101
+ export declare function median(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
102
+ /**
103
+ * Calculate quantile
104
+ * @param col - Column to calculate quantile
105
+ * @param level - Quantile level (0.0 to 1.0)
106
+ */
107
+ export declare function quantile(col: ClickHouseColumn | SQLExpression, level: number): SQLExpression<number>;
108
+ /**
109
+ * Calculate quantiles (multiple levels)
110
+ * @param col - Column to calculate quantiles
111
+ * @param levels - Array of quantile levels
112
+ */
113
+ export declare function quantiles(col: ClickHouseColumn | SQLExpression, levels: number[]): SQLExpression<number[]>;
114
+ /**
115
+ * Calculate Pearson correlation coefficient
116
+ * @param col1 - First column
117
+ * @param col2 - Second column
118
+ */
119
+ export declare function corr(col1: ClickHouseColumn | SQLExpression, col2: ClickHouseColumn | SQLExpression): SQLExpression<number>;
120
+ /**
121
+ * Calculate covariance
122
+ * @param col1 - First column
123
+ * @param col2 - Second column
124
+ */
125
+ export declare function covarSamp(col1: ClickHouseColumn | SQLExpression, col2: ClickHouseColumn | SQLExpression): SQLExpression<number>;
126
+ /**
127
+ * Calculate population covariance
128
+ * @param col1 - First column
129
+ * @param col2 - Second column
130
+ */
131
+ export declare function covarPop(col1: ClickHouseColumn | SQLExpression, col2: ClickHouseColumn | SQLExpression): SQLExpression<number>;
132
+ /**
133
+ * Calculate rate per second (for counters and metrics)
134
+ * @param col - Counter column
135
+ * @param bucket - Time bucket column
136
+ */
137
+ export declare function rate(col: ClickHouseColumn | SQLExpression, bucket: ClickHouseColumn | SQLExpression): SQLExpression<number>;
138
+ /**
139
+ * Calculate increase in counter value
140
+ * @param col - Counter column
141
+ * @param bucket - Time bucket column
142
+ */
143
+ export declare function increase(col: ClickHouseColumn | SQLExpression, bucket?: ClickHouseColumn | SQLExpression): SQLExpression<number>;
144
+ /**
145
+ * Calculate delta between consecutive values
146
+ * @param col - Column to calculate delta
147
+ */
148
+ export declare function delta(col: ClickHouseColumn | SQLExpression): SQLExpression<number>;
149
+ /**
150
+ * Get top N values by frequency
151
+ * @param col - Column to analyze
152
+ * @param n - Number of top values to return
153
+ */
154
+ export declare function topK<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
155
+ /**
156
+ * Get bottom N values by frequency
157
+ * @param col - Column to analyze
158
+ * @param n - Number of bottom values to return
159
+ */
160
+ export declare function bottomK<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
161
+ /**
162
+ * Get top N values by sum
163
+ * @param col - Column to analyze
164
+ * @param n - Number of top values to return
165
+ */
166
+ export declare function topSum<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
167
+ /**
168
+ * Get bottom N values by sum
169
+ * @param col - Column to analyze
170
+ * @param n - Number of bottom values to return
171
+ */
172
+ export declare function bottomSum<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, n: number): SQLExpression<T[]>;
173
+ /**
174
+ * Sum values if condition is met
175
+ */
176
+ export declare function sumIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
177
+ /**
178
+ * Count rows if condition is met
179
+ */
180
+ export declare function countIf(condition: SQLExpression): SQLExpression<number>;
181
+ /**
182
+ * Average values if condition is met
183
+ */
184
+ export declare function avgIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
185
+ /**
186
+ * Minimum value if condition is met
187
+ */
188
+ export declare function minIf<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, condition: SQLExpression): SQLExpression<T>;
189
+ /**
190
+ * Maximum value if condition is met
191
+ */
192
+ export declare function maxIf<T>(col: ClickHouseColumn<T, any, any> | SQLExpression<T>, condition: SQLExpression): SQLExpression<T>;
193
+ /**
194
+ * Approximate unique values if condition is met
195
+ */
196
+ export declare function uniqIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
197
+ /**
198
+ * Exact unique values if condition is met
199
+ */
200
+ export declare function uniqExactIf(col: ClickHouseColumn | SQLExpression, condition: SQLExpression): SQLExpression<number>;
201
+ /**
202
+ * Aggregates all array elements into a single array
203
+ * @example t.array(1, 2), t.array(3, 4) -> [1, 2, 3, 4]
204
+ */
205
+ export declare function groupArrayArray<T>(expr: ClickHouseColumn<T[], any, any> | SQLExpression<T[]>): SQLExpression<T[]>;
@@ -0,0 +1,122 @@
1
+ import { ClickHouseColumn } from '../core';
2
+ import { SQLExpression } from '../expressions';
3
+ /**
4
+ * Join array elements with a separator
5
+ * @param separator - Separator string
6
+ * @param col - Array column or expression
7
+ */
8
+ export declare function arrayJoin(separator: string | ClickHouseColumn | SQLExpression, col?: ClickHouseColumn | SQLExpression): SQLExpression<any>;
9
+ /**
10
+ * Apply a lambda function to each element of an array
11
+ * @param lambda - Lambda function (e.g., 'x -> x * 2')
12
+ * @param col - Array column or expression
13
+ */
14
+ export declare function arrayMap(lambda: string, col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
15
+ /**
16
+ * Filter array elements using a lambda function
17
+ * @param lambda - Lambda function (e.g., 'x -> x > 0')
18
+ * @param col - Array column or expression
19
+ */
20
+ export declare function arrayFilter(lambda: string, col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
21
+ /**
22
+ * Get the length of an array
23
+ * @param col - Array column or expression
24
+ */
25
+ export declare function arrayLength(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
26
+ /**
27
+ * Reduce an array using a function
28
+ * @param func - Aggregate function name (e.g., 'sum', 'avg', 'max')
29
+ * @param col - Array column or expression
30
+ */
31
+ export declare function arrayReduce(func: string, col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
32
+ /**
33
+ * Concatenate multiple arrays
34
+ * @param arrays - Array columns or expressions to concatenate
35
+ */
36
+ export declare function arrayConcat(...arrays: (ClickHouseColumn | SQLExpression)[]): SQLExpression<any>;
37
+ /**
38
+ * Get element at specific index (1-based)
39
+ * @param col - Array column or expression
40
+ * @param index - Index (1-based)
41
+ */
42
+ export declare function arrayElement(col: ClickHouseColumn | SQLExpression, index: number): SQLExpression<any>;
43
+ /**
44
+ * Check if array contains an element
45
+ * @param col - Array column or expression
46
+ * @param element - Element to search for
47
+ */
48
+ export declare function arrayHas(col: ClickHouseColumn | SQLExpression, element: any): SQLExpression<any>;
49
+ /**
50
+ * Check if array has all elements from another array
51
+ * @param col - Array column or expression
52
+ * @param elements - Array of elements to check
53
+ */
54
+ export declare function arrayHasAll(col: ClickHouseColumn | SQLExpression, elements: any[] | ClickHouseColumn | SQLExpression): SQLExpression<any>;
55
+ /**
56
+ * Check if array has any element from another array
57
+ * @param col - Array column or expression
58
+ * @param elements - Array of elements to check
59
+ */
60
+ export declare function arrayHasAny(col: ClickHouseColumn | SQLExpression, elements: any[] | ClickHouseColumn | SQLExpression): SQLExpression<any>;
61
+ /**
62
+ * Get the first element of an array
63
+ * @param col - Array column or expression
64
+ */
65
+ export declare function arrayFirst(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
66
+ /**
67
+ * Get the last element of an array
68
+ * @param col - Array column or expression
69
+ */
70
+ export declare function arrayLast(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
71
+ /**
72
+ * Sort an array
73
+ * @param col - Array column or expression
74
+ * @param ascending - Sort order (default: true for ascending)
75
+ */
76
+ export declare function arraySort(col: ClickHouseColumn | SQLExpression, ascending?: boolean): SQLExpression<any>;
77
+ /**
78
+ * Reverse an array
79
+ * @param col - Array column or expression
80
+ */
81
+ export declare function arrayReverse(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
82
+ /**
83
+ * Get unique elements from an array
84
+ * @param col - Array column or expression
85
+ */
86
+ export declare function arrayDistinct(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
87
+ /**
88
+ * Count occurrences of an element in an array
89
+ * @param col - Array column or expression
90
+ * @param element - Element to count
91
+ */
92
+ export declare function arrayCountMatches(col: ClickHouseColumn | SQLExpression, element: any): SQLExpression<any>;
93
+ /**
94
+ * Check if array is empty
95
+ * @param col - Array column or expression
96
+ */
97
+ export declare function empty(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
98
+ /**
99
+ * Check if array is not empty
100
+ * @param col - Array column or expression
101
+ */
102
+ export declare function notEmpty(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
103
+ /**
104
+ * Get the minimum value in an array
105
+ * @param col - Array column or expression
106
+ */
107
+ export declare function arrayMin(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
108
+ /**
109
+ * Get the maximum value in an array
110
+ * @param col - Array column or expression
111
+ */
112
+ export declare function arrayMax(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
113
+ /**
114
+ * Calculate the sum of array elements
115
+ * @param col - Array column or expression
116
+ */
117
+ export declare function arraySum(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;
118
+ /**
119
+ * Calculate the average of array elements
120
+ * @param col - Array column or expression
121
+ */
122
+ export declare function arrayAvg(col: ClickHouseColumn | SQLExpression): SQLExpression<any>;