ga4-export-fixer 0.2.5-dev.0 → 0.2.5-dev.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.
- package/constants.js +1 -0
- package/package.json +1 -1
- package/preOperations.js +23 -1
package/constants.js
CHANGED
|
@@ -2,6 +2,7 @@ const constants = {
|
|
|
2
2
|
DATE_RANGE_START_VARIABLE: 'date_range_start',
|
|
3
3
|
INTRADAY_DATE_RANGE_START_VARIABLE: 'intraday_date_range_start',
|
|
4
4
|
DATE_RANGE_END_VARIABLE: 'date_range_end',
|
|
5
|
+
LAST_PARTITION_DATE_VARIABLE: 'last_partition_date',
|
|
5
6
|
DATE_COLUMN: 'event_date',
|
|
6
7
|
DEFAULT_EVENTS_TABLE_NAME: 'ga4_events_enhanced',
|
|
7
8
|
TABLE_DESCRIPTION_SUFFIX: 'Created by the ga4-export-fixer package.',
|
package/package.json
CHANGED
package/preOperations.js
CHANGED
|
@@ -6,6 +6,22 @@ const declareVariable = (variable, value) => {
|
|
|
6
6
|
);`;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
+
// Get the last partition date from the result table
|
|
10
|
+
const getLastPartitionDate = (config) => {
|
|
11
|
+
const informationSchemaPath = config.self.replace(
|
|
12
|
+
/`?([^`]+)\.([^`]+)\.[^`]+`?$/,
|
|
13
|
+
'`$1.$2.INFORMATION_SCHEMA.PARTITIONS`'
|
|
14
|
+
);
|
|
15
|
+
const tableName = config.self.replace(/`/g, '').split('.').pop();
|
|
16
|
+
|
|
17
|
+
return `select
|
|
18
|
+
max(parse_date('%Y%m%d', partition_id))
|
|
19
|
+
from
|
|
20
|
+
${informationSchemaPath}
|
|
21
|
+
where
|
|
22
|
+
table_name = '${tableName}' and partition_id != '__NULL__'`;
|
|
23
|
+
};
|
|
24
|
+
|
|
9
25
|
// Define the date range start for incremental and full refresh
|
|
10
26
|
const getDateRangeStart = (config) => {
|
|
11
27
|
if (config.incremental) {
|
|
@@ -22,7 +38,7 @@ const getDateRangeStart = (config) => {
|
|
|
22
38
|
from
|
|
23
39
|
${config.self}
|
|
24
40
|
where
|
|
25
|
-
${constants.DATE_COLUMN} >
|
|
41
|
+
${constants.DATE_COLUMN} > ${constants.LAST_PARTITION_DATE_VARIABLE}-${config.preOperations.numberOfPreviousDaysToScan}
|
|
26
42
|
group by
|
|
27
43
|
${constants.DATE_COLUMN}
|
|
28
44
|
)
|
|
@@ -132,6 +148,12 @@ const setPreOperations = (config) => {
|
|
|
132
148
|
|
|
133
149
|
// define the pre operations
|
|
134
150
|
const preOperations = [
|
|
151
|
+
{
|
|
152
|
+
type: 'variable',
|
|
153
|
+
name: constants.LAST_PARTITION_DATE_VARIABLE,
|
|
154
|
+
value: config.incremental ? getLastPartitionDate(config) : undefined,
|
|
155
|
+
comment: 'Get the last partition date from the result table. Used to anchor the incremental date checkpoint scan window to the table\'s actual data.',
|
|
156
|
+
},
|
|
135
157
|
{
|
|
136
158
|
type: 'variable',
|
|
137
159
|
name: constants.DATE_RANGE_START_VARIABLE,
|