@lightdash/common 3.207.0 → 3.209.0
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/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/compiler/translator.d.ts +2 -1
- package/dist/cjs/compiler/translator.d.ts.map +1 -1
- package/dist/cjs/compiler/translator.js +175 -121
- package/dist/cjs/compiler/translator.js.map +1 -1
- package/dist/cjs/dbt/schemas/lightdashMetadata.json +7 -0
- package/dist/cjs/schemas/json/lightdash-dbt-2.0.json +296 -267
- package/dist/cjs/types/dbt.d.ts +5 -0
- package/dist/cjs/types/dbt.d.ts.map +1 -1
- package/dist/cjs/types/dbt.js.map +1 -1
- package/dist/cjs/utils/filters.d.ts +9 -0
- package/dist/cjs/utils/filters.d.ts.map +1 -1
- package/dist/cjs/utils/filters.js +5 -4
- package/dist/cjs/utils/filters.js.map +1 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/compiler/translator.d.ts +2 -1
- package/dist/esm/compiler/translator.d.ts.map +1 -1
- package/dist/esm/compiler/translator.js +173 -120
- package/dist/esm/compiler/translator.js.map +1 -1
- package/dist/esm/dbt/schemas/lightdashMetadata.json +7 -0
- package/dist/esm/schemas/json/lightdash-dbt-2.0.json +296 -267
- package/dist/esm/types/dbt.d.ts +5 -0
- package/dist/esm/types/dbt.d.ts.map +1 -1
- package/dist/esm/types/dbt.js.map +1 -1
- package/dist/esm/utils/filters.d.ts +9 -0
- package/dist/esm/utils/filters.d.ts.map +1 -1
- package/dist/esm/utils/filters.js +1 -1
- package/dist/esm/utils/filters.js.map +1 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/compiler/translator.d.ts +2 -1
- package/dist/types/compiler/translator.d.ts.map +1 -1
- package/dist/types/compiler/translator.js +173 -120
- package/dist/types/compiler/translator.js.map +1 -1
- package/dist/types/dbt/schemas/lightdashMetadata.json +7 -0
- package/dist/types/schemas/json/lightdash-dbt-2.0.json +296 -267
- package/dist/types/types/dbt.d.ts +5 -0
- package/dist/types/types/dbt.d.ts.map +1 -1
- package/dist/types/types/dbt.js.map +1 -1
- package/dist/types/utils/filters.d.ts +9 -0
- package/dist/types/utils/filters.d.ts.map +1 -1
- package/dist/types/utils/filters.js +1 -1
- package/dist/types/utils/filters.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { SupportedDbtAdapter, type DbtModelColumn, type DbtModelNode, type ModelInventoryEntry } from '../types/dbt';
|
|
1
|
+
import { SupportedDbtAdapter, type DbtModelColumn, type DbtModelNode, type DbtRawModelNode, type ModelInventoryEntry } from '../types/dbt';
|
|
2
2
|
import { type Explore, type ExploreError, type Table } from '../types/explore';
|
|
3
3
|
import { type CustomGranularity, type LightdashProjectConfig } from '../types/lightdashProjectConfig';
|
|
4
4
|
import { type TimeFrames } from '../types/timeFrames';
|
|
5
5
|
import { type WarehouseCatalog, type WarehouseCatalogMissingEntry, type WarehouseSqlBuilder } from '../types/warehouse';
|
|
6
6
|
import { type ResolvedAdditionalTimeIntervals, type WeekDay } from '../utils/timeFrames';
|
|
7
|
+
export declare const hasModelAdditionalDimension: (model: Pick<DbtRawModelNode, 'meta' | 'config'>) => boolean;
|
|
7
8
|
export declare const convertTable: (adapterType: SupportedDbtAdapter, model: DbtModelNode, spotlightConfig: LightdashProjectConfig['spotlight'], startOfWeek?: WeekDay | null, disableTimestampConversion?: boolean, customGranularities?: Record<string, CustomGranularity>, allowPartialCompilation?: boolean, additionalTimeIntervals?: ResolvedAdditionalTimeIntervals, granularityLabels?: Partial<Record<TimeFrames, string>>) => Omit<Table, 'lineageGraph'>;
|
|
8
9
|
export type ExplorePostProcessor = (compiledExplores: Explore[], context: {
|
|
9
10
|
model: DbtModelNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"translator.d.ts","sourceRoot":"","sources":["../../../src/compiler/translator.ts"],"names":[],"mappings":"AAUA,OAAO,EAQH,mBAAmB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ACjC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1D,YAAY,EAAE,MAAM,CAAC;IACrB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;CAC1B,CAAC;AAiJF;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,qBACf,gBAAgB,UAC1B,YAAY,EAAE,yBACC,OAAO,KAC/B;IACC,YAAY,EAAE,4BAA4B,EAAE,CAAC;IAC7C,cAAc,EAAE,4BAA4B,EAAE,CAAC;CAmDlD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gCAAgC,kBAC1B,gBAAgB,UACvB,YAAY,EAAE,gBACR,4BAA4B,EAAE,yBACrB,OAAO,KAC/B,OA6BF,CAAC;AAEF,eAAO,MAAM,mBAAmB,WACpB,YAAY,EAAE,oBACJ,gBAAgB,+BACN,OAAO,0BACZ,OAAO,kBACd,CAAC,WAAW,EAAE,sBAAsB,KAAK,IAAI,wBACxC,4BAA4B,EAAE,KACpD,YAAY,EA4Ld,CAAC;AAEF,eAAO,MAAM,+BAA+B,cAC7B,YAAY,EAAE,KAC1B;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,EAK/C,CAAC"}
|
|
@@ -453,12 +453,133 @@ function dropMapValuedModelFilters(owner, filters, allowPartialCompilation) {
|
|
|
453
453
|
});
|
|
454
454
|
return { filters: validFilters, warnings };
|
|
455
455
|
}
|
|
456
|
+
// Model-level additional dimensions have no column to fall back on.
|
|
457
|
+
const isCompleteAdditionalDimension = (config) => Boolean(config.type && config.sql);
|
|
458
|
+
const getModelAdditionalDimensions = (model) => merge({}, model.meta, model.config?.meta).additional_dimensions ?? {};
|
|
459
|
+
export const hasModelAdditionalDimension = (model) => Object.values(getModelAdditionalDimensions(model)).some(isCompleteAdditionalDimension);
|
|
456
460
|
export const convertTable = (adapterType, model, spotlightConfig, startOfWeek, disableTimestampConversion, customGranularities, allowPartialCompilation, additionalTimeIntervals, granularityLabels) => {
|
|
457
461
|
// Config block takes priority, then meta block
|
|
458
462
|
const meta = merge({}, model.meta, model.config?.meta);
|
|
459
463
|
const tableLabel = meta.label || friendlyName(model.name);
|
|
460
464
|
const tableWarnings = [];
|
|
461
|
-
const
|
|
465
|
+
const processIntervalDimension = (dim, overrideTimeIntervals, column, columnMeta, index) => {
|
|
466
|
+
if (dim.isIntervalBase) {
|
|
467
|
+
let allIntervals = [];
|
|
468
|
+
if (!dim.isAdditionalDimension &&
|
|
469
|
+
columnMeta.dimension?.time_intervals &&
|
|
470
|
+
Array.isArray(columnMeta?.dimension.time_intervals)) {
|
|
471
|
+
allIntervals = columnMeta.dimension.time_intervals;
|
|
472
|
+
}
|
|
473
|
+
else if (dim.isAdditionalDimension &&
|
|
474
|
+
Array.isArray(overrideTimeIntervals)) {
|
|
475
|
+
allIntervals = overrideTimeIntervals;
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
allIntervals = getTimeFramesWithProjectDefaults(dim.type, additionalTimeIntervals);
|
|
479
|
+
}
|
|
480
|
+
// Split into standard TimeFrames and custom granularity names
|
|
481
|
+
const intervals = validateTimeFrames(allIntervals);
|
|
482
|
+
const customIntervalNames = allIntervals.filter((v) => !isTimeInterval(v.toUpperCase()));
|
|
483
|
+
const dimensionMeta = {
|
|
484
|
+
...columnMeta.dimension,
|
|
485
|
+
type: dim.type,
|
|
486
|
+
label: dim.label,
|
|
487
|
+
groups: dim.groups,
|
|
488
|
+
sql: dim.sql,
|
|
489
|
+
description: dim.description,
|
|
490
|
+
hidden: dim.hidden,
|
|
491
|
+
// Additional-dim children must inherit the additional
|
|
492
|
+
// dimension's own resolved domain, not the parent
|
|
493
|
+
// column's annotation riding in the meta spread.
|
|
494
|
+
timestamp_domain: dim.timestampDomain,
|
|
495
|
+
};
|
|
496
|
+
// Generate standard interval dimensions
|
|
497
|
+
const standardDims = intervals.reduce((acc, interval) => ({
|
|
498
|
+
...acc,
|
|
499
|
+
[`${dim.name}_${interval.toLowerCase()}`]: convertDimension(index, adapterType, model, tableLabel, {
|
|
500
|
+
...column,
|
|
501
|
+
...('isAdditionalDimension' in dim &&
|
|
502
|
+
dim.isAdditionalDimension
|
|
503
|
+
? {
|
|
504
|
+
name: dim.name,
|
|
505
|
+
meta: {
|
|
506
|
+
dimension: dimensionMeta,
|
|
507
|
+
},
|
|
508
|
+
// In dbt 1.10+, config.meta takes precedence over meta
|
|
509
|
+
// so we must set config.meta.dimension to prevent
|
|
510
|
+
// the base dimension's properties from overwriting
|
|
511
|
+
config: {
|
|
512
|
+
meta: {
|
|
513
|
+
dimension: dimensionMeta,
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
}
|
|
517
|
+
: {}),
|
|
518
|
+
}, undefined, interval, startOfWeek, 'isAdditionalDimension' in dim &&
|
|
519
|
+
dim.isAdditionalDimension,
|
|
520
|
+
// Additional-dim children derive from the
|
|
521
|
+
// parent's compiled sql, which already
|
|
522
|
+
// carries the timestamp conversion.
|
|
523
|
+
dim.isAdditionalDimension
|
|
524
|
+
? true
|
|
525
|
+
: disableTimestampConversion, undefined, granularityLabels),
|
|
526
|
+
}), {});
|
|
527
|
+
// Generate custom granularity dimensions
|
|
528
|
+
const customDims = customIntervalNames.reduce((acc, customName) => {
|
|
529
|
+
const granularity = customGranularities?.[customName];
|
|
530
|
+
if (!granularity) {
|
|
531
|
+
tableWarnings.push({
|
|
532
|
+
type: InlineErrorType.FIELD_ERROR,
|
|
533
|
+
message: `Unknown time interval "${customName}" on column "${dim.name}" in model "${model.name}". It is not a standard time frame or a custom granularity defined in lightdash.config.yml.`,
|
|
534
|
+
});
|
|
535
|
+
return acc;
|
|
536
|
+
}
|
|
537
|
+
const customSql = granularity.sql.replace(/\$\{COLUMN\}/g, () => dim.sql);
|
|
538
|
+
const customType = granularity.type || DimensionType.DATE;
|
|
539
|
+
const customDimName = `${dim.name}_${customName}`;
|
|
540
|
+
const groups = [...(dim.groups || [])];
|
|
541
|
+
if (!groups.includes(dim.label)) {
|
|
542
|
+
groups.push(dim.label);
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
...acc,
|
|
546
|
+
[customDimName]: {
|
|
547
|
+
index,
|
|
548
|
+
fieldType: FieldType.DIMENSION,
|
|
549
|
+
name: customDimName,
|
|
550
|
+
label: granularity.label,
|
|
551
|
+
sql: customSql,
|
|
552
|
+
table: model.name,
|
|
553
|
+
tableLabel,
|
|
554
|
+
type: customType,
|
|
555
|
+
description: dim.description,
|
|
556
|
+
source: undefined,
|
|
557
|
+
timeInterval: undefined,
|
|
558
|
+
timeIntervalBaseDimensionName: dim.name,
|
|
559
|
+
timeIntervalBaseDimensionType: dim.type,
|
|
560
|
+
customTimeInterval: customName,
|
|
561
|
+
hidden: dim.hidden,
|
|
562
|
+
format: undefined,
|
|
563
|
+
round: undefined,
|
|
564
|
+
compact: undefined,
|
|
565
|
+
requiredAttributes: dim.requiredAttributes,
|
|
566
|
+
anyAttributes: dim.anyAttributes,
|
|
567
|
+
groups,
|
|
568
|
+
isIntervalBase: false,
|
|
569
|
+
isAdditionalDimension: dim.isAdditionalDimension,
|
|
570
|
+
...(dim.skipTimezoneConversion
|
|
571
|
+
? { skipTimezoneConversion: true }
|
|
572
|
+
: {}),
|
|
573
|
+
// Custom granularity SQL may change the base
|
|
574
|
+
// column's domain, so keep its output unknown.
|
|
575
|
+
},
|
|
576
|
+
};
|
|
577
|
+
}, {});
|
|
578
|
+
return { ...standardDims, ...customDims };
|
|
579
|
+
}
|
|
580
|
+
return {};
|
|
581
|
+
};
|
|
582
|
+
const [columnDimensions, metrics] = Object.values(model.columns).reduce(([prevDimensions, prevMetrics], column, index) => {
|
|
462
583
|
// Config block takes priority, then meta block
|
|
463
584
|
const columnMeta = merge({}, column.meta, column.config?.meta);
|
|
464
585
|
const routedByUnnest = !columnMeta.dimension?.sql;
|
|
@@ -477,125 +598,10 @@ export const convertTable = (adapterType, model, spotlightConfig, startOfWeek, d
|
|
|
477
598
|
const dimension = isContainer
|
|
478
599
|
? undefined
|
|
479
600
|
: convertDimension(index, adapterType, model, tableLabel, column, undefined, undefined, startOfWeek, undefined, disableTimestampConversion, tableWarnings, granularityLabels);
|
|
480
|
-
const processIntervalDimension = (dim, overrideTimeIntervals) => {
|
|
481
|
-
if (dim.isIntervalBase) {
|
|
482
|
-
let allIntervals = [];
|
|
483
|
-
if (!dim.isAdditionalDimension &&
|
|
484
|
-
columnMeta.dimension?.time_intervals &&
|
|
485
|
-
Array.isArray(columnMeta?.dimension.time_intervals)) {
|
|
486
|
-
allIntervals = columnMeta.dimension.time_intervals;
|
|
487
|
-
}
|
|
488
|
-
else if (dim.isAdditionalDimension &&
|
|
489
|
-
Array.isArray(overrideTimeIntervals)) {
|
|
490
|
-
allIntervals = overrideTimeIntervals;
|
|
491
|
-
}
|
|
492
|
-
else {
|
|
493
|
-
allIntervals = getTimeFramesWithProjectDefaults(dim.type, additionalTimeIntervals);
|
|
494
|
-
}
|
|
495
|
-
// Split into standard TimeFrames and custom granularity names
|
|
496
|
-
const intervals = validateTimeFrames(allIntervals);
|
|
497
|
-
const customIntervalNames = allIntervals.filter((v) => !isTimeInterval(v.toUpperCase()));
|
|
498
|
-
const dimensionMeta = {
|
|
499
|
-
...columnMeta.dimension,
|
|
500
|
-
type: dim.type,
|
|
501
|
-
label: dim.label,
|
|
502
|
-
groups: dim.groups,
|
|
503
|
-
sql: dim.sql,
|
|
504
|
-
description: dim.description,
|
|
505
|
-
hidden: dim.hidden,
|
|
506
|
-
// Additional-dim children must inherit the additional
|
|
507
|
-
// dimension's own resolved domain, not the parent
|
|
508
|
-
// column's annotation riding in the meta spread.
|
|
509
|
-
timestamp_domain: dim.timestampDomain,
|
|
510
|
-
};
|
|
511
|
-
// Generate standard interval dimensions
|
|
512
|
-
const standardDims = intervals.reduce((acc, interval) => ({
|
|
513
|
-
...acc,
|
|
514
|
-
[`${dim.name}_${interval.toLowerCase()}`]: convertDimension(index, adapterType, model, tableLabel, {
|
|
515
|
-
...column,
|
|
516
|
-
...('isAdditionalDimension' in dim &&
|
|
517
|
-
dim.isAdditionalDimension
|
|
518
|
-
? {
|
|
519
|
-
name: dim.name,
|
|
520
|
-
meta: {
|
|
521
|
-
dimension: dimensionMeta,
|
|
522
|
-
},
|
|
523
|
-
// In dbt 1.10+, config.meta takes precedence over meta
|
|
524
|
-
// so we must set config.meta.dimension to prevent
|
|
525
|
-
// the base dimension's properties from overwriting
|
|
526
|
-
config: {
|
|
527
|
-
meta: {
|
|
528
|
-
dimension: dimensionMeta,
|
|
529
|
-
},
|
|
530
|
-
},
|
|
531
|
-
}
|
|
532
|
-
: {}),
|
|
533
|
-
}, undefined, interval, startOfWeek, 'isAdditionalDimension' in dim &&
|
|
534
|
-
dim.isAdditionalDimension,
|
|
535
|
-
// Additional-dim children derive from the
|
|
536
|
-
// parent's compiled sql, which already
|
|
537
|
-
// carries the timestamp conversion.
|
|
538
|
-
dim.isAdditionalDimension
|
|
539
|
-
? true
|
|
540
|
-
: disableTimestampConversion, undefined, granularityLabels),
|
|
541
|
-
}), {});
|
|
542
|
-
// Generate custom granularity dimensions
|
|
543
|
-
const customDims = customIntervalNames.reduce((acc, customName) => {
|
|
544
|
-
const granularity = customGranularities?.[customName];
|
|
545
|
-
if (!granularity) {
|
|
546
|
-
tableWarnings.push({
|
|
547
|
-
type: InlineErrorType.FIELD_ERROR,
|
|
548
|
-
message: `Unknown time interval "${customName}" on column "${dim.name}" in model "${model.name}". It is not a standard time frame or a custom granularity defined in lightdash.config.yml.`,
|
|
549
|
-
});
|
|
550
|
-
return acc;
|
|
551
|
-
}
|
|
552
|
-
const customSql = granularity.sql.replace(/\$\{COLUMN\}/g, () => dim.sql);
|
|
553
|
-
const customType = granularity.type || DimensionType.DATE;
|
|
554
|
-
const customDimName = `${dim.name}_${customName}`;
|
|
555
|
-
const groups = [...(dim.groups || [])];
|
|
556
|
-
if (!groups.includes(dim.label)) {
|
|
557
|
-
groups.push(dim.label);
|
|
558
|
-
}
|
|
559
|
-
return {
|
|
560
|
-
...acc,
|
|
561
|
-
[customDimName]: {
|
|
562
|
-
index,
|
|
563
|
-
fieldType: FieldType.DIMENSION,
|
|
564
|
-
name: customDimName,
|
|
565
|
-
label: granularity.label,
|
|
566
|
-
sql: customSql,
|
|
567
|
-
table: model.name,
|
|
568
|
-
tableLabel,
|
|
569
|
-
type: customType,
|
|
570
|
-
description: dim.description,
|
|
571
|
-
source: undefined,
|
|
572
|
-
timeInterval: undefined,
|
|
573
|
-
timeIntervalBaseDimensionName: dim.name,
|
|
574
|
-
timeIntervalBaseDimensionType: dim.type,
|
|
575
|
-
customTimeInterval: customName,
|
|
576
|
-
hidden: dim.hidden,
|
|
577
|
-
format: undefined,
|
|
578
|
-
round: undefined,
|
|
579
|
-
compact: undefined,
|
|
580
|
-
requiredAttributes: dim.requiredAttributes,
|
|
581
|
-
anyAttributes: dim.anyAttributes,
|
|
582
|
-
groups,
|
|
583
|
-
isIntervalBase: false,
|
|
584
|
-
isAdditionalDimension: dim.isAdditionalDimension,
|
|
585
|
-
...(dim.skipTimezoneConversion
|
|
586
|
-
? { skipTimezoneConversion: true }
|
|
587
|
-
: {}),
|
|
588
|
-
// Custom granularity SQL may change the base
|
|
589
|
-
// column's domain, so keep its output unknown.
|
|
590
|
-
},
|
|
591
|
-
};
|
|
592
|
-
}, {});
|
|
593
|
-
return { ...standardDims, ...customDims };
|
|
594
|
-
}
|
|
595
|
-
return {};
|
|
596
|
-
};
|
|
597
601
|
let extraDimensions = dimension
|
|
598
|
-
? {
|
|
602
|
+
? {
|
|
603
|
+
...processIntervalDimension(dimension, undefined, column, columnMeta, index),
|
|
604
|
+
}
|
|
599
605
|
: {};
|
|
600
606
|
extraDimensions = Object.entries(columnMeta.additional_dimensions || {}).reduce((acc, [subDimensionName, subDimension]) => {
|
|
601
607
|
const additionalDim = convertDimension(index, adapterType, model, tableLabel, {
|
|
@@ -614,7 +620,7 @@ export const convertTable = (adapterType, model, spotlightConfig, startOfWeek, d
|
|
|
614
620
|
...acc,
|
|
615
621
|
// When the additional dim is interval AND the base dimension is a interval base then we want to compute all additional dims with the parent intervals otherwise just set the additional dim
|
|
616
622
|
[subDimensionName]: additionalDim,
|
|
617
|
-
...processIntervalDimension(additionalDim, subDimension.time_intervals),
|
|
623
|
+
...processIntervalDimension(additionalDim, subDimension.time_intervals, column, columnMeta, index),
|
|
618
624
|
};
|
|
619
625
|
}, extraDimensions);
|
|
620
626
|
// Metrics under an array of scalars aggregate its elements and
|
|
@@ -657,6 +663,53 @@ export const convertTable = (adapterType, model, spotlightConfig, startOfWeek, d
|
|
|
657
663
|
{ ...prevMetrics, ...columnMetrics },
|
|
658
664
|
];
|
|
659
665
|
}, [{}, {}]);
|
|
666
|
+
const dimensions = { ...columnDimensions };
|
|
667
|
+
const metricNames = new Set([
|
|
668
|
+
...Object.keys(metrics),
|
|
669
|
+
...Object.keys(meta.metrics ?? {}),
|
|
670
|
+
]);
|
|
671
|
+
const isDuplicateDimension = (name) => {
|
|
672
|
+
const existing = (dimensions[name] && 'dimension') ||
|
|
673
|
+
(metricNames.has(name) && 'metric');
|
|
674
|
+
if (!existing)
|
|
675
|
+
return false;
|
|
676
|
+
tableWarnings.push({
|
|
677
|
+
type: InlineErrorType.DUPLICATE_FIELD_NAME,
|
|
678
|
+
message: `Skipped additional dimension "${name}" in model "${model.name}" because a ${existing} with the same name exists.`,
|
|
679
|
+
});
|
|
680
|
+
return true;
|
|
681
|
+
};
|
|
682
|
+
const columnCount = Object.keys(model.columns).length;
|
|
683
|
+
Object.entries(getModelAdditionalDimensions(model)).forEach(([name, config], position) => {
|
|
684
|
+
if (!isCompleteAdditionalDimension(config)) {
|
|
685
|
+
const missing = [
|
|
686
|
+
...(config.type ? [] : ['type']),
|
|
687
|
+
...(config.sql ? [] : ['sql']),
|
|
688
|
+
]
|
|
689
|
+
.map((key) => `"${key}"`)
|
|
690
|
+
.join(' and ');
|
|
691
|
+
tableWarnings.push({
|
|
692
|
+
type: InlineErrorType.FIELD_ERROR,
|
|
693
|
+
message: `Skipped additional dimension "${name}" in model "${model.name}" because it is missing ${missing}. Model-level additional dimensions need both "type" and "sql".`,
|
|
694
|
+
});
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
if (isDuplicateDimension(name))
|
|
698
|
+
return;
|
|
699
|
+
const index = columnCount + position;
|
|
700
|
+
const column = {
|
|
701
|
+
name,
|
|
702
|
+
data_type: config.type,
|
|
703
|
+
meta: { dimension: config },
|
|
704
|
+
};
|
|
705
|
+
const baseDimension = convertDimension(index, adapterType, model, tableLabel, column, undefined, undefined, startOfWeek, true, disableTimestampConversion, tableWarnings, granularityLabels);
|
|
706
|
+
dimensions[name] = baseDimension;
|
|
707
|
+
Object.entries(processIntervalDimension(baseDimension, config.time_intervals, column, { dimension: config }, index)).forEach(([intervalName, intervalDimension]) => {
|
|
708
|
+
if (!isDuplicateDimension(intervalName)) {
|
|
709
|
+
dimensions[intervalName] = intervalDimension;
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
});
|
|
660
713
|
const modelMetrics = Object.fromEntries(Object.entries(meta.metrics || {}).map(([name, metric]) => [
|
|
661
714
|
name,
|
|
662
715
|
convertModelMetric({
|