monorise 1.7.0-dev.10 → 1.7.0-dev.11
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/core/index.js +7 -2
- package/dist/core/index.js.map +1 -1
- package/package.json +1 -1
package/dist/core/index.js
CHANGED
|
@@ -2846,6 +2846,9 @@ function required3(name) {
|
|
|
2846
2846
|
function quoteIdentifier(identifier) {
|
|
2847
2847
|
return `"${identifier.replaceAll('"', '""')}"`;
|
|
2848
2848
|
}
|
|
2849
|
+
function quoteDdlIdentifier(identifier) {
|
|
2850
|
+
return `\`${identifier.replaceAll("`", "``")}\``;
|
|
2851
|
+
}
|
|
2849
2852
|
function quoteLiteral(value) {
|
|
2850
2853
|
return `'${value.replaceAll("'", "''")}'`;
|
|
2851
2854
|
}
|
|
@@ -2884,6 +2887,8 @@ function datasetSql(dataset, database, bucket) {
|
|
|
2884
2887
|
var _a;
|
|
2885
2888
|
const history = `${quoteIdentifier(database)}.${quoteIdentifier(dataset.historyTable)}`;
|
|
2886
2889
|
const current = `${quoteIdentifier(database)}.${quoteIdentifier(dataset.currentTable)}`;
|
|
2890
|
+
const historyDdl = `${quoteDdlIdentifier(database)}.${quoteDdlIdentifier(dataset.historyTable)}`;
|
|
2891
|
+
const currentDdl = `${quoteDdlIdentifier(database)}.${quoteDdlIdentifier(dataset.currentTable)}`;
|
|
2887
2892
|
const raw = `${quoteIdentifier(database)}.${quoteIdentifier((_a = dataset.rawTable) != null ? _a : `${dataset.historyTable}_raw`)}`;
|
|
2888
2893
|
const typedColumns = dataset.columns.map(
|
|
2889
2894
|
(column) => `${quoteIdentifier(column.name)} ${column.type === "json" ? "varchar" : column.type}`
|
|
@@ -2952,9 +2957,9 @@ function datasetSql(dataset, database, bucket) {
|
|
|
2952
2957
|
...names.map((name) => `s.${name}`)
|
|
2953
2958
|
].join(", ");
|
|
2954
2959
|
return [
|
|
2955
|
-
`CREATE TABLE ${
|
|
2960
|
+
`CREATE TABLE ${historyDdl} (${allColumns.join(", ")}) WITH (table_type = 'ICEBERG', location = ${quoteLiteral(`s3://${bucket}/curated/history/${dataset.kind === "entity" ? "entities" : "mutuals"}/${dataset.name}/`)})`,
|
|
2956
2961
|
`MERGE INTO ${history} h USING (SELECT * FROM (SELECT ${selected.join(", ")}, row_number() OVER (PARTITION BY event_id ORDER BY ordering_key DESC) AS row_number FROM ${raw}) WHERE row_number = 1) s ON h.event_id = s.event_id WHEN NOT MATCHED THEN INSERT (${historyNames}) VALUES (${insertValues})`,
|
|
2957
|
-
`CREATE TABLE ${
|
|
2962
|
+
`CREATE TABLE ${currentDdl} (${allColumns.filter((column) => !column.startsWith("event_id ") && !column.startsWith("idempotency_key ") && !column.startsWith("sequence_number ") && !column.startsWith("before_json ") && !column.startsWith("after_json ")).join(", ")}) WITH (table_type = 'ICEBERG', location = ${quoteLiteral(`s3://${bucket}/current/${dataset.name}/`)})`,
|
|
2958
2963
|
`MERGE INTO ${current} c USING (SELECT * FROM (SELECT h.*, row_number() OVER (PARTITION BY ${quoteIdentifier(dataset.idColumn)} ORDER BY occurred_at DESC, ordering_key DESC) AS row_number FROM ${history} h) WHERE row_number = 1) s ON c.${quoteIdentifier(dataset.idColumn)} = s.${quoteIdentifier(dataset.idColumn)} WHEN MATCHED AND s.operation = 'REMOVE' THEN DELETE WHEN MATCHED THEN UPDATE SET operation = s.operation, occurred_at = s.occurred_at, ordering_key = s.ordering_key${endpointNames.map((name) => `, ${name} = s.${name}`).join("")}${names.map((name) => `, ${name} = s.${name}`).join("")} WHEN NOT MATCHED AND s.operation <> 'REMOVE' THEN INSERT (operation, occurred_at, ordering_key, ${quoteIdentifier(dataset.idColumn)}${endpointNames.length ? `, ${endpointNames.join(", ")}` : ""}${names.length ? `, ${names.join(", ")}` : ""}) VALUES (s.operation, s.occurred_at, s.ordering_key, s.${quoteIdentifier(dataset.idColumn)}${endpointNames.length ? `, ${endpointNames.map((name) => `s.${name}`).join(", ")}` : ""}${names.length ? `, ${names.map((name) => `s.${name}`).join(", ")}` : ""})`
|
|
2959
2964
|
];
|
|
2960
2965
|
}
|