@lightdash/common 2.151.1 → 2.153.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/exploreCompiler.d.ts.map +1 -1
- package/dist/cjs/compiler/exploreCompiler.js +14 -7
- package/dist/cjs/compiler/exploreCompiler.js.map +1 -1
- package/dist/cjs/compiler/exploreCompiler.test.js +10 -0
- package/dist/cjs/compiler/exploreCompiler.test.js.map +1 -1
- package/dist/cjs/compiler/translator.d.ts +50 -2
- package/dist/cjs/compiler/translator.d.ts.map +1 -1
- package/dist/cjs/compiler/translator.js +259 -6
- package/dist/cjs/compiler/translator.js.map +1 -1
- package/dist/cjs/compiler/translator.mock.d.ts +2 -1
- package/dist/cjs/compiler/translator.mock.d.ts.map +1 -1
- package/dist/cjs/compiler/translator.mock.js +12 -12
- package/dist/cjs/compiler/translator.mock.js.map +1 -1
- package/dist/cjs/compiler/translator.test.js +332 -0
- package/dist/cjs/compiler/translator.test.js.map +1 -1
- 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/types/featureFlags.d.ts +5 -0
- package/dist/cjs/types/featureFlags.d.ts.map +1 -1
- package/dist/cjs/types/featureFlags.js +5 -0
- package/dist/cjs/types/featureFlags.js.map +1 -1
- package/dist/cjs/types/table.d.ts +5 -0
- package/dist/cjs/types/table.d.ts.map +1 -1
- package/dist/cjs/types/warehouse.d.ts +20 -0
- package/dist/cjs/types/warehouse.d.ts.map +1 -1
- package/dist/cjs/types/warehouse.js +40 -1
- package/dist/cjs/types/warehouse.js.map +1 -1
- package/dist/cjs/utils/item.d.ts +4 -0
- package/dist/cjs/utils/item.d.ts.map +1 -1
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/compiler/exploreCompiler.d.ts.map +1 -1
- package/dist/esm/compiler/exploreCompiler.js +14 -7
- package/dist/esm/compiler/exploreCompiler.js.map +1 -1
- package/dist/esm/compiler/exploreCompiler.test.js +10 -0
- package/dist/esm/compiler/exploreCompiler.test.js.map +1 -1
- package/dist/esm/compiler/translator.d.ts +50 -2
- package/dist/esm/compiler/translator.d.ts.map +1 -1
- package/dist/esm/compiler/translator.js +258 -8
- package/dist/esm/compiler/translator.js.map +1 -1
- package/dist/esm/compiler/translator.mock.d.ts +2 -1
- package/dist/esm/compiler/translator.mock.d.ts.map +1 -1
- package/dist/esm/compiler/translator.mock.js +1 -1
- package/dist/esm/compiler/translator.mock.js.map +1 -1
- package/dist/esm/compiler/translator.test.js +334 -2
- package/dist/esm/compiler/translator.test.js.map +1 -1
- 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/types/featureFlags.d.ts +5 -0
- package/dist/esm/types/featureFlags.d.ts.map +1 -1
- package/dist/esm/types/featureFlags.js +5 -0
- package/dist/esm/types/featureFlags.js.map +1 -1
- package/dist/esm/types/table.d.ts +5 -0
- package/dist/esm/types/table.d.ts.map +1 -1
- package/dist/esm/types/warehouse.d.ts +20 -0
- package/dist/esm/types/warehouse.d.ts.map +1 -1
- package/dist/esm/types/warehouse.js +36 -0
- package/dist/esm/types/warehouse.js.map +1 -1
- package/dist/esm/utils/item.d.ts +4 -0
- package/dist/esm/utils/item.d.ts.map +1 -1
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/compiler/exploreCompiler.d.ts.map +1 -1
- package/dist/types/compiler/exploreCompiler.js +14 -7
- package/dist/types/compiler/exploreCompiler.js.map +1 -1
- package/dist/types/compiler/exploreCompiler.test.js +10 -0
- package/dist/types/compiler/exploreCompiler.test.js.map +1 -1
- package/dist/types/compiler/translator.d.ts +50 -2
- package/dist/types/compiler/translator.d.ts.map +1 -1
- package/dist/types/compiler/translator.js +258 -8
- package/dist/types/compiler/translator.js.map +1 -1
- package/dist/types/compiler/translator.mock.d.ts +2 -1
- package/dist/types/compiler/translator.mock.d.ts.map +1 -1
- package/dist/types/compiler/translator.mock.js +1 -1
- package/dist/types/compiler/translator.mock.js.map +1 -1
- package/dist/types/compiler/translator.test.js +334 -2
- package/dist/types/compiler/translator.test.js.map +1 -1
- 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/types/featureFlags.d.ts +5 -0
- package/dist/types/types/featureFlags.d.ts.map +1 -1
- package/dist/types/types/featureFlags.js +5 -0
- package/dist/types/types/featureFlags.js.map +1 -1
- package/dist/types/types/table.d.ts +5 -0
- package/dist/types/types/table.d.ts.map +1 -1
- package/dist/types/types/warehouse.d.ts +20 -0
- package/dist/types/types/warehouse.d.ts.map +1 -1
- package/dist/types/types/warehouse.js +36 -0
- package/dist/types/types/warehouse.js.map +1 -1
- package/dist/types/utils/item.d.ts +4 -0
- package/dist/types/utils/item.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1953,4 +1953,336 @@ describe('convertExplores at scale', () => {
|
|
|
1953
1953
|
expect(Object.keys(first.tables)).toEqual(['m_0']);
|
|
1954
1954
|
});
|
|
1955
1955
|
});
|
|
1956
|
+
describe('nested and repeated columns', () => {
|
|
1957
|
+
const bigqueryClientMock = {
|
|
1958
|
+
...exploreCompiler_mock_1.warehouseClientMock,
|
|
1959
|
+
getAdapterType: () => dbt_1.SupportedDbtAdapter.BIGQUERY,
|
|
1960
|
+
getFieldQuoteChar: () => '`',
|
|
1961
|
+
};
|
|
1962
|
+
const nestedColumn = (name, extra = {}) => ({ name, meta: {}, ...extra });
|
|
1963
|
+
const gaSessions = {
|
|
1964
|
+
...translator_mock_1.model,
|
|
1965
|
+
name: 'ga_sessions',
|
|
1966
|
+
alias: 'ga_sessions',
|
|
1967
|
+
unique_id: 'model.ga_sessions',
|
|
1968
|
+
database: 'db',
|
|
1969
|
+
schema: 'ds',
|
|
1970
|
+
relation_name: '`db`.`ds`.`ga_sessions`',
|
|
1971
|
+
meta: {},
|
|
1972
|
+
columns: {
|
|
1973
|
+
visitId: nestedColumn('visitId'),
|
|
1974
|
+
'totals.pageviews': nestedColumn('totals.pageviews'),
|
|
1975
|
+
hits: nestedColumn('hits', { description: 'One row per hit' }),
|
|
1976
|
+
'customDimensions.index': nestedColumn('customDimensions.index'),
|
|
1977
|
+
'customDimensions.value': nestedColumn('customDimensions.value'),
|
|
1978
|
+
'hits.page.pagePath': nestedColumn('hits.page.pagePath'),
|
|
1979
|
+
'hits.product.productSKU': nestedColumn('hits.product.productSKU'),
|
|
1980
|
+
'hits.product.productRevenue': nestedColumn('hits.product.productRevenue', {
|
|
1981
|
+
meta: {
|
|
1982
|
+
metrics: { total_revenue: { type: field_1.MetricType.SUM } },
|
|
1983
|
+
},
|
|
1984
|
+
}),
|
|
1985
|
+
},
|
|
1986
|
+
};
|
|
1987
|
+
const catalog = {
|
|
1988
|
+
db: {
|
|
1989
|
+
ds: {
|
|
1990
|
+
ga_sessions: {
|
|
1991
|
+
visitId: field_1.DimensionType.NUMBER,
|
|
1992
|
+
totals: field_1.DimensionType.STRING,
|
|
1993
|
+
'totals.pageviews': field_1.DimensionType.NUMBER,
|
|
1994
|
+
customDimensions: field_1.DimensionType.STRING,
|
|
1995
|
+
'customDimensions.index': field_1.DimensionType.NUMBER,
|
|
1996
|
+
'customDimensions.value': field_1.DimensionType.STRING,
|
|
1997
|
+
hits: field_1.DimensionType.STRING,
|
|
1998
|
+
'hits.page': field_1.DimensionType.STRING,
|
|
1999
|
+
'hits.page.pagePath': field_1.DimensionType.STRING,
|
|
2000
|
+
'hits.product': field_1.DimensionType.STRING,
|
|
2001
|
+
'hits.product.productSKU': field_1.DimensionType.STRING,
|
|
2002
|
+
'hits.product.productRevenue': field_1.DimensionType.NUMBER,
|
|
2003
|
+
tags: field_1.DimensionType.STRING,
|
|
2004
|
+
'hits.page.keywords': field_1.DimensionType.STRING,
|
|
2005
|
+
},
|
|
2006
|
+
},
|
|
2007
|
+
},
|
|
2008
|
+
};
|
|
2009
|
+
Object.entries({
|
|
2010
|
+
totals: { repeated: false, record: true },
|
|
2011
|
+
customDimensions: { repeated: true, record: true },
|
|
2012
|
+
hits: { repeated: true, record: true },
|
|
2013
|
+
'hits.page': { repeated: false, record: true },
|
|
2014
|
+
'hits.product': { repeated: true, record: true },
|
|
2015
|
+
tags: { repeated: true, record: false },
|
|
2016
|
+
'hits.page.keywords': { repeated: true, record: false },
|
|
2017
|
+
}).forEach(([path, shape]) => (0, warehouse_1.setCatalogNestedColumnShape)(catalog, 'db', 'ds', 'ga_sessions', path, shape));
|
|
2018
|
+
const typedModels = (0, translator_1.attachTypesToModels)([gaSessions], catalog, true);
|
|
2019
|
+
const compile = async (models, unnestRepeatedColumns) => {
|
|
2020
|
+
const explores = await (0, translator_1.convertExplores)(models, false, dbt_1.SupportedDbtAdapter.BIGQUERY, bigqueryClientMock, { spotlight: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG }, { unnestRepeatedColumns });
|
|
2021
|
+
const explore = explores.find((e) => e.name === 'ga_sessions');
|
|
2022
|
+
if (!explore || (0, explore_1.isExploreError)(explore)) {
|
|
2023
|
+
throw new Error(JSON.stringify(explore));
|
|
2024
|
+
}
|
|
2025
|
+
return explore;
|
|
2026
|
+
};
|
|
2027
|
+
it('attaches the shape and repeated ancestors from the catalog', () => {
|
|
2028
|
+
const { columns } = typedModels[0];
|
|
2029
|
+
expect(columns.hits.nested_shape).toEqual({
|
|
2030
|
+
repeated: true,
|
|
2031
|
+
record: true,
|
|
2032
|
+
});
|
|
2033
|
+
expect(columns.hits.repeated_ancestors).toBeUndefined();
|
|
2034
|
+
expect(columns['totals.pageviews'].repeated_ancestors).toBeUndefined();
|
|
2035
|
+
expect(columns['hits.page.pagePath'].repeated_ancestors).toEqual([
|
|
2036
|
+
'hits',
|
|
2037
|
+
]);
|
|
2038
|
+
expect(columns['hits.product.productSKU'].repeated_ancestors).toEqual([
|
|
2039
|
+
'hits',
|
|
2040
|
+
'hits.product',
|
|
2041
|
+
]);
|
|
2042
|
+
});
|
|
2043
|
+
it("keeps today's dotted dimensions when unnesting is off", async () => {
|
|
2044
|
+
const explore = await compile(typedModels, false);
|
|
2045
|
+
expect(Object.keys(explore.tables)).toEqual(['ga_sessions']);
|
|
2046
|
+
expect(explore.tables.ga_sessions.dimensions['hits.product.productSKU']
|
|
2047
|
+
.compiledSql).toEqual('`ga_sessions`.hits.product.productSKU');
|
|
2048
|
+
});
|
|
2049
|
+
it('unnests each repeated node into a virtual table joined on TRUE', async () => {
|
|
2050
|
+
const explore = await compile(typedModels, true);
|
|
2051
|
+
expect(Object.keys(explore.tables).sort()).toEqual([
|
|
2052
|
+
'ga_sessions',
|
|
2053
|
+
'ga_sessions__customDimensions',
|
|
2054
|
+
'ga_sessions__hits',
|
|
2055
|
+
'ga_sessions__hits__product',
|
|
2056
|
+
]);
|
|
2057
|
+
const base = explore.tables.ga_sessions;
|
|
2058
|
+
expect(Object.keys(base.dimensions).sort()).toEqual([
|
|
2059
|
+
'totals.pageviews',
|
|
2060
|
+
'visitId',
|
|
2061
|
+
]);
|
|
2062
|
+
expect(base.dimensions['totals.pageviews'].compiledSql).toEqual('`ga_sessions`.totals.pageviews');
|
|
2063
|
+
const hits = explore.tables.ga_sessions__hits;
|
|
2064
|
+
expect(hits.nestedFrom).toEqual({
|
|
2065
|
+
parentTable: 'ga_sessions',
|
|
2066
|
+
columnPath: 'hits',
|
|
2067
|
+
});
|
|
2068
|
+
expect(hits.sqlTable).toEqual('UNNEST(`ga_sessions`.hits) AS `ga_sessions__hits` WITH OFFSET AS `ga_sessions__hits__offset`');
|
|
2069
|
+
expect(hits.label).toEqual('Ga sessions: Hits');
|
|
2070
|
+
expect(hits.description).toEqual('One row per hit');
|
|
2071
|
+
expect(hits.primaryKey).toBeUndefined();
|
|
2072
|
+
expect(Object.keys(hits.dimensions).sort()).toEqual([
|
|
2073
|
+
'offset',
|
|
2074
|
+
'page.pagePath',
|
|
2075
|
+
]);
|
|
2076
|
+
expect(hits.dimensions['page.pagePath']).toMatchObject({
|
|
2077
|
+
table: 'ga_sessions__hits',
|
|
2078
|
+
type: field_1.DimensionType.STRING,
|
|
2079
|
+
compiledSql: '`ga_sessions__hits`.page.pagePath',
|
|
2080
|
+
});
|
|
2081
|
+
expect(hits.dimensions.offset).toMatchObject({
|
|
2082
|
+
type: field_1.DimensionType.NUMBER,
|
|
2083
|
+
compiledSql: '`ga_sessions__hits__offset`',
|
|
2084
|
+
});
|
|
2085
|
+
const product = explore.tables.ga_sessions__hits__product;
|
|
2086
|
+
expect(product.nestedFrom).toEqual({
|
|
2087
|
+
parentTable: 'ga_sessions__hits',
|
|
2088
|
+
columnPath: 'hits.product',
|
|
2089
|
+
});
|
|
2090
|
+
expect(product.sqlTable).toEqual('UNNEST(`ga_sessions__hits`.product) AS `ga_sessions__hits__product` WITH OFFSET AS `ga_sessions__hits__product__offset`');
|
|
2091
|
+
expect(product.label).toEqual('Ga sessions: Hits: Product');
|
|
2092
|
+
expect(product.metrics.total_revenue).toMatchObject({
|
|
2093
|
+
table: 'ga_sessions__hits__product',
|
|
2094
|
+
compiledSql: 'SUM(`ga_sessions__hits__product`.productRevenue)',
|
|
2095
|
+
});
|
|
2096
|
+
expect(explore.joinedTables.map(({ table, type, relationship, compiledSqlOn, tablesReferences, }) => ({
|
|
2097
|
+
table,
|
|
2098
|
+
type,
|
|
2099
|
+
relationship,
|
|
2100
|
+
compiledSqlOn,
|
|
2101
|
+
tablesReferences,
|
|
2102
|
+
}))).toEqual([
|
|
2103
|
+
{
|
|
2104
|
+
table: 'ga_sessions__customDimensions',
|
|
2105
|
+
type: 'left',
|
|
2106
|
+
relationship: explore_1.JoinRelationship.ONE_TO_MANY,
|
|
2107
|
+
compiledSqlOn: 'TRUE',
|
|
2108
|
+
tablesReferences: ['ga_sessions'],
|
|
2109
|
+
},
|
|
2110
|
+
{
|
|
2111
|
+
table: 'ga_sessions__hits',
|
|
2112
|
+
type: 'left',
|
|
2113
|
+
relationship: explore_1.JoinRelationship.ONE_TO_MANY,
|
|
2114
|
+
compiledSqlOn: 'TRUE',
|
|
2115
|
+
tablesReferences: ['ga_sessions'],
|
|
2116
|
+
},
|
|
2117
|
+
{
|
|
2118
|
+
table: 'ga_sessions__hits__product',
|
|
2119
|
+
type: 'left',
|
|
2120
|
+
relationship: explore_1.JoinRelationship.ONE_TO_MANY,
|
|
2121
|
+
compiledSqlOn: 'TRUE',
|
|
2122
|
+
tablesReferences: ['ga_sessions__hits'],
|
|
2123
|
+
},
|
|
2124
|
+
]);
|
|
2125
|
+
});
|
|
2126
|
+
it("adds a joined model's virtual tables after its own join", async () => {
|
|
2127
|
+
const orders = {
|
|
2128
|
+
...translator_mock_1.model,
|
|
2129
|
+
name: 'orders',
|
|
2130
|
+
alias: 'orders',
|
|
2131
|
+
unique_id: 'model.orders',
|
|
2132
|
+
database: 'db',
|
|
2133
|
+
schema: 'ds',
|
|
2134
|
+
relation_name: '`db`.`ds`.`orders`',
|
|
2135
|
+
columns: { id: nestedColumn('id') },
|
|
2136
|
+
meta: {
|
|
2137
|
+
joins: [
|
|
2138
|
+
{
|
|
2139
|
+
join: 'ga_sessions',
|
|
2140
|
+
sql_on: '${orders.id} = ${ga_sessions.visitId}',
|
|
2141
|
+
},
|
|
2142
|
+
],
|
|
2143
|
+
},
|
|
2144
|
+
};
|
|
2145
|
+
const explores = await (0, translator_1.convertExplores)([orders, ...typedModels], false, dbt_1.SupportedDbtAdapter.BIGQUERY, bigqueryClientMock, { spotlight: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG }, { unnestRepeatedColumns: true });
|
|
2146
|
+
const explore = explores.find((e) => e.name === 'orders');
|
|
2147
|
+
if (!explore || (0, explore_1.isExploreError)(explore)) {
|
|
2148
|
+
throw new Error(JSON.stringify(explore));
|
|
2149
|
+
}
|
|
2150
|
+
expect(explore.joinedTables.map(({ table }) => table)).toEqual([
|
|
2151
|
+
'ga_sessions',
|
|
2152
|
+
'ga_sessions__customDimensions',
|
|
2153
|
+
'ga_sessions__hits',
|
|
2154
|
+
'ga_sessions__hits__product',
|
|
2155
|
+
]);
|
|
2156
|
+
});
|
|
2157
|
+
it('instantiates virtual tables per join alias, referencing the alias in the UNNEST', async () => {
|
|
2158
|
+
const orders = {
|
|
2159
|
+
...translator_mock_1.model,
|
|
2160
|
+
name: 'orders',
|
|
2161
|
+
alias: 'orders',
|
|
2162
|
+
unique_id: 'model.orders',
|
|
2163
|
+
database: 'db',
|
|
2164
|
+
schema: 'ds',
|
|
2165
|
+
relation_name: '`db`.`ds`.`orders`',
|
|
2166
|
+
columns: { id: nestedColumn('id') },
|
|
2167
|
+
meta: {
|
|
2168
|
+
joins: [
|
|
2169
|
+
{
|
|
2170
|
+
join: 'ga_sessions',
|
|
2171
|
+
alias: 'first_session',
|
|
2172
|
+
sql_on: '${orders.id} = ${first_session.visitId}',
|
|
2173
|
+
},
|
|
2174
|
+
{
|
|
2175
|
+
join: 'ga_sessions',
|
|
2176
|
+
alias: 'second_session',
|
|
2177
|
+
label: 'Return visit',
|
|
2178
|
+
sql_on: '${orders.id} = ${second_session.visitId}',
|
|
2179
|
+
},
|
|
2180
|
+
],
|
|
2181
|
+
},
|
|
2182
|
+
};
|
|
2183
|
+
const explores = await (0, translator_1.convertExplores)([orders, ...typedModels], false, dbt_1.SupportedDbtAdapter.BIGQUERY, bigqueryClientMock, { spotlight: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG }, { unnestRepeatedColumns: true });
|
|
2184
|
+
const explore = explores.find((e) => e.name === 'orders');
|
|
2185
|
+
if (!explore || (0, explore_1.isExploreError)(explore)) {
|
|
2186
|
+
throw new Error(JSON.stringify(explore));
|
|
2187
|
+
}
|
|
2188
|
+
expect(explore.joinedTables.map(({ table }) => table)).toEqual([
|
|
2189
|
+
'first_session',
|
|
2190
|
+
'first_session__customDimensions',
|
|
2191
|
+
'first_session__hits',
|
|
2192
|
+
'first_session__hits__product',
|
|
2193
|
+
'second_session',
|
|
2194
|
+
'second_session__customDimensions',
|
|
2195
|
+
'second_session__hits',
|
|
2196
|
+
'second_session__hits__product',
|
|
2197
|
+
]);
|
|
2198
|
+
const firstHits = explore.tables.first_session__hits;
|
|
2199
|
+
expect(firstHits.sqlTable).toEqual('UNNEST(`first_session`.hits) AS `first_session__hits` WITH OFFSET AS `first_session__hits__offset`');
|
|
2200
|
+
expect(firstHits.nestedFrom).toEqual({
|
|
2201
|
+
parentTable: 'first_session',
|
|
2202
|
+
columnPath: 'hits',
|
|
2203
|
+
});
|
|
2204
|
+
expect(firstHits.dimensions['page.pagePath'].compiledSql).toEqual('`first_session__hits`.page.pagePath');
|
|
2205
|
+
expect(explore.joinedTables.find(({ table }) => table === 'first_session__hits__product')?.tablesReferences).toEqual(['first_session__hits']);
|
|
2206
|
+
const secondProduct = explore.tables.second_session__hits__product;
|
|
2207
|
+
expect(secondProduct.sqlTable).toEqual('UNNEST(`second_session__hits`.product) AS `second_session__hits__product` WITH OFFSET AS `second_session__hits__product__offset`');
|
|
2208
|
+
expect(secondProduct.label).toEqual('Return visit: Hits: Product');
|
|
2209
|
+
expect(secondProduct.metrics.total_revenue.compiledSql).toEqual('SUM(`second_session__hits__product`.productRevenue)');
|
|
2210
|
+
expect(explore.tables.ga_sessions__hits).toBeUndefined();
|
|
2211
|
+
});
|
|
2212
|
+
it('unnests an array of scalars into a virtual table with a value dimension', async () => {
|
|
2213
|
+
const taggedSessions = {
|
|
2214
|
+
...gaSessions,
|
|
2215
|
+
columns: {
|
|
2216
|
+
visitId: nestedColumn('visitId'),
|
|
2217
|
+
tags: nestedColumn('tags', {
|
|
2218
|
+
description: 'Session tags',
|
|
2219
|
+
meta: {
|
|
2220
|
+
dimension: { label: 'Tag list' },
|
|
2221
|
+
metrics: {
|
|
2222
|
+
last_tag: { type: field_1.MetricType.MAX },
|
|
2223
|
+
},
|
|
2224
|
+
},
|
|
2225
|
+
}),
|
|
2226
|
+
'hits.page.keywords': nestedColumn('hits.page.keywords'),
|
|
2227
|
+
},
|
|
2228
|
+
};
|
|
2229
|
+
const explore = await compile((0, translator_1.attachTypesToModels)([taggedSessions], catalog, true), true);
|
|
2230
|
+
expect(Object.keys(explore.tables).sort()).toEqual([
|
|
2231
|
+
'ga_sessions',
|
|
2232
|
+
'ga_sessions__hits',
|
|
2233
|
+
'ga_sessions__hits__page__keywords',
|
|
2234
|
+
'ga_sessions__tags',
|
|
2235
|
+
]);
|
|
2236
|
+
expect(Object.keys(explore.tables.ga_sessions.dimensions)).toEqual([
|
|
2237
|
+
'visitId',
|
|
2238
|
+
]);
|
|
2239
|
+
const tags = explore.tables.ga_sessions__tags;
|
|
2240
|
+
expect(tags.label).toEqual('Tag list');
|
|
2241
|
+
expect(tags.description).toEqual('Session tags');
|
|
2242
|
+
expect(tags.sqlTable).toEqual('UNNEST(`ga_sessions`.tags) AS `ga_sessions__tags` WITH OFFSET AS `ga_sessions__tags__offset`');
|
|
2243
|
+
expect(Object.keys(tags.dimensions).sort()).toEqual([
|
|
2244
|
+
'offset',
|
|
2245
|
+
'value',
|
|
2246
|
+
]);
|
|
2247
|
+
expect(tags.dimensions.value).toMatchObject({
|
|
2248
|
+
type: field_1.DimensionType.STRING,
|
|
2249
|
+
label: 'Value',
|
|
2250
|
+
compiledSql: '`ga_sessions__tags`',
|
|
2251
|
+
});
|
|
2252
|
+
expect(tags.metrics.last_tag.compiledSql).toEqual('MAX(`ga_sessions__tags`)');
|
|
2253
|
+
// An array below a struct inside a repeated record unnests from the
|
|
2254
|
+
// repeated parent, with the struct path in the segment.
|
|
2255
|
+
const keywords = explore.tables.ga_sessions__hits__page__keywords;
|
|
2256
|
+
expect(keywords.nestedFrom).toEqual({
|
|
2257
|
+
parentTable: 'ga_sessions__hits',
|
|
2258
|
+
columnPath: 'hits.page.keywords',
|
|
2259
|
+
});
|
|
2260
|
+
expect(keywords.sqlTable).toEqual('UNNEST(`ga_sessions__hits`.page.keywords) AS `ga_sessions__hits__page__keywords` WITH OFFSET AS `ga_sessions__hits__page__keywords__offset`');
|
|
2261
|
+
expect(keywords.label).toEqual('Ga sessions: Hits: Page: Keywords');
|
|
2262
|
+
expect(keywords.dimensions.value.compiledSql).toEqual('`ga_sessions__hits__page__keywords`');
|
|
2263
|
+
expect(Object.keys(explore.tables.ga_sessions__hits.dimensions)).toEqual(['offset']);
|
|
2264
|
+
expect(explore.joinedTables.map(({ table, tablesReferences }) => [
|
|
2265
|
+
table,
|
|
2266
|
+
tablesReferences,
|
|
2267
|
+
])).toEqual([
|
|
2268
|
+
['ga_sessions__hits', ['ga_sessions']],
|
|
2269
|
+
['ga_sessions__tags', ['ga_sessions']],
|
|
2270
|
+
['ga_sessions__hits__page__keywords', ['ga_sessions__hits']],
|
|
2271
|
+
]);
|
|
2272
|
+
});
|
|
2273
|
+
it('fails the model when a virtual table name collides with a model', async () => {
|
|
2274
|
+
const collidingModel = {
|
|
2275
|
+
...translator_mock_1.model,
|
|
2276
|
+
name: 'ga_sessions__hits',
|
|
2277
|
+
alias: 'ga_sessions__hits',
|
|
2278
|
+
unique_id: 'model.ga_sessions__hits',
|
|
2279
|
+
columns: { id: nestedColumn('id') },
|
|
2280
|
+
meta: {},
|
|
2281
|
+
};
|
|
2282
|
+
const explores = await (0, translator_1.convertExplores)([collidingModel, ...typedModels], false, dbt_1.SupportedDbtAdapter.BIGQUERY, bigqueryClientMock, { spotlight: lightdashProjectConfig_1.DEFAULT_SPOTLIGHT_CONFIG }, { unnestRepeatedColumns: true });
|
|
2283
|
+
const explore = explores.find((e) => e.name === 'ga_sessions');
|
|
2284
|
+
expect(explore && (0, explore_1.isExploreError)(explore)).toBe(true);
|
|
2285
|
+
expect(JSON.stringify(explore)).toContain('already used by another table');
|
|
2286
|
+
});
|
|
2287
|
+
});
|
|
1956
2288
|
//# sourceMappingURL=translator.test.js.map
|