@tmlmobilidade/databases 20260511.1606.49 → 20260513.1432.15
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.
- package/dist/interfaces/vehicle-events/raw-vehicle-events.d.ts +5 -0
- package/dist/interfaces/vehicle-events/raw-vehicle-events.js +5 -1
- package/dist/interfaces/vehicle-events/simplified-vehicle-events.d.ts +9 -3
- package/dist/interfaces/vehicle-events/simplified-vehicle-events.js +8 -3
- package/dist/templates/clickhouse.d.ts +1 -0
- package/dist/templates/clickhouse.js +2 -0
- package/package.json +1 -1
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw Vehicle Events represent the raw vehicle events as they are received from the data sources.
|
|
3
|
+
* These are stored in MongoDB for persistence and later processing.
|
|
4
|
+
* These documents are also different depending on the data source and version of the vehicle event.
|
|
5
|
+
**/
|
|
1
6
|
import { MongoInterfaceTemplate } from '../../templates/mongodb.js';
|
|
2
7
|
import { type SimplifiedMongoIndex } from '../../types/mongo/index-description.js';
|
|
3
8
|
import { type RawVehicleEvent } from '@tmlmobilidade/types';
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Raw Vehicle Events represent the raw vehicle events as they are received from the data sources.
|
|
3
|
+
* These are stored in MongoDB for persistence and later processing.
|
|
4
|
+
* These documents are also different depending on the data source and version of the vehicle event.
|
|
5
|
+
**/
|
|
2
6
|
import { PCGIRawClient } from '../../clients/pcgi-raw.js';
|
|
3
7
|
import { MongoInterfaceTemplate } from '../../templates/mongodb.js';
|
|
4
8
|
import { RawVehicleEventSchema } from '@tmlmobilidade/types';
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simplified Vehicle Events represent a simplified version of the raw vehicle events.
|
|
3
|
+
* These are stored in ClickHouse for performance and scalability reasons.
|
|
4
|
+
**/
|
|
1
5
|
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
2
|
-
import { type ClickHouseSchema } from '../../types/index.js';
|
|
6
|
+
import { type ClickHouseSchema, ClickHouseTableEngine } from '../../types/index.js';
|
|
3
7
|
import { type SimplifiedVehicleEvent } from '@tmlmobilidade/types';
|
|
4
8
|
declare class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplate<SimplifiedVehicleEvent> {
|
|
5
9
|
private static _instance;
|
|
6
10
|
readonly databaseName = "operation";
|
|
7
|
-
readonly
|
|
8
|
-
readonly
|
|
11
|
+
readonly engine: ClickHouseTableEngine;
|
|
12
|
+
readonly orderBy = "(trip_id, vehicle_id, agency_id, created_at)";
|
|
13
|
+
readonly partitionBy = "toYYYYMM(fromUnixTimestamp64Milli(created_at))";
|
|
14
|
+
readonly primaryKey = "(trip_id, vehicle_id)";
|
|
9
15
|
readonly schema: ClickHouseSchema<{
|
|
10
16
|
_id: string;
|
|
11
17
|
created_at: number & {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Simplified Vehicle Events represent a simplified version of the raw vehicle events.
|
|
3
|
+
* These are stored in ClickHouse for performance and scalability reasons.
|
|
4
|
+
**/
|
|
2
5
|
import { GOClickHouseClient } from '../../clients/go-clickhouse.js';
|
|
3
6
|
import { ClickHouseInterfaceTemplate } from '../../templates/clickhouse.js';
|
|
4
7
|
import { asyncSingletonProxy } from '@tmlmobilidade/utils';
|
|
@@ -28,8 +31,10 @@ class SimplifiedVehicleEventsNewClass extends ClickHouseInterfaceTemplate {
|
|
|
28
31
|
//
|
|
29
32
|
static _instance = null;
|
|
30
33
|
databaseName = 'operation';
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
engine = 'ReplacingMergeTree';
|
|
35
|
+
orderBy = '(trip_id, vehicle_id, agency_id, created_at)';
|
|
36
|
+
partitionBy = 'toYYYYMM(fromUnixTimestamp64Milli(created_at))';
|
|
37
|
+
primaryKey = '(trip_id, vehicle_id)';
|
|
33
38
|
schema = tableSchema;
|
|
34
39
|
tableName = 'simplified_vehicle_events';
|
|
35
40
|
/**
|
|
@@ -16,6 +16,7 @@ export declare abstract class ClickHouseInterfaceTemplate<T extends object> {
|
|
|
16
16
|
protected readonly manageSchema: boolean;
|
|
17
17
|
protected readonly orderBy: string;
|
|
18
18
|
protected readonly partitionBy: null | string;
|
|
19
|
+
protected readonly primaryKey: null | string;
|
|
19
20
|
private client;
|
|
20
21
|
/**
|
|
21
22
|
* Disallow direct instantiation of the service.
|
|
@@ -17,6 +17,7 @@ export class ClickHouseInterfaceTemplate {
|
|
|
17
17
|
manageSchema = true;
|
|
18
18
|
orderBy = '_id';
|
|
19
19
|
partitionBy = null;
|
|
20
|
+
primaryKey = null;
|
|
20
21
|
client;
|
|
21
22
|
/**
|
|
22
23
|
* Disallow direct instantiation of the service.
|
|
@@ -209,6 +210,7 @@ export class ClickHouseInterfaceTemplate {
|
|
|
209
210
|
CREATE TABLE IF NOT EXISTS "${this.databaseName}"."${this.tableName}" (
|
|
210
211
|
${Object.entries(this.schema).map(([key, column]) => `${key} ${column.type}`).join(', ')}
|
|
211
212
|
) ENGINE = ${this.getEngineString()}
|
|
213
|
+
${this.primaryKey ? `PRIMARY KEY (${this.primaryKey})` : ''}
|
|
212
214
|
${this.orderBy ? `ORDER BY (${this.orderBy})` : ''}
|
|
213
215
|
${this.partitionBy ? `PARTITION BY (${this.partitionBy})` : ''}
|
|
214
216
|
`;
|