Skip to content

Commit 9ad3a79

Browse files
committed
code polish
1 parent 8ba8f7b commit 9ad3a79

File tree

6 files changed

+26
-29
lines changed

6 files changed

+26
-29
lines changed

packages/cubejs-cubestore-driver/src/CubeStoreDriver.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class CubeStoreDriver extends BaseDriver implements DriverInterface {
199199

200200
public toColumnValue(value: any, genericType: any) {
201201
if (genericType === 'timestamp' && typeof value === 'string') {
202-
return value && value.replace('Z', '');
202+
return value?.replace('Z', '');
203203
}
204204
if (genericType === 'boolean' && typeof value === 'string') {
205205
if (value.toLowerCase() === 'true') {
@@ -216,14 +216,14 @@ export class CubeStoreDriver extends BaseDriver implements DriverInterface {
216216
const createTableIndexes = externalOptions?.createTableIndexes;
217217
const aggregationsColumns = externalOptions?.aggregationsColumns;
218218

219-
const indexes = createTableIndexes && createTableIndexes.length ? createTableIndexes.map(this.createIndexString).join(' ') : '';
219+
const indexes = createTableIndexes?.length ? createTableIndexes.map(this.createIndexString).join(' ') : '';
220220

221221
let hasAggregatingIndexes = false;
222-
if (createTableIndexes && createTableIndexes.length) {
222+
if (createTableIndexes?.length) {
223223
hasAggregatingIndexes = createTableIndexes.some((index) => index.type === 'aggregate');
224224
}
225225

226-
const aggregations = hasAggregatingIndexes && aggregationsColumns && aggregationsColumns.length ? ` AGGREGATIONS (${aggregationsColumns.join(', ')})` : '';
226+
const aggregations = hasAggregatingIndexes && aggregationsColumns?.length ? ` AGGREGATIONS (${aggregationsColumns.join(', ')})` : '';
227227

228228
if (tableData.rowStream) {
229229
await this.importStream(columns, tableData, table, indexes, aggregations, queryTracingObj);
@@ -428,7 +428,7 @@ export class CubeStoreDriver extends BaseDriver implements DriverInterface {
428428
locations.push(`stream://${tableData.streamingSource.name}/${tableData.streamingTable}/${i}`);
429429
}
430430
}
431-
431+
432432
const options: CreateTableOptions = {
433433
buildRangeEnd: queryTracingObj?.buildRangeEnd,
434434
uniqueKey: uniqueKeyColumns.join(','),

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationLoadCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ type PreAggregationLoadCacheOptions = {
1919
export class PreAggregationLoadCache {
2020
private readonly driverFactory: DriverFactory;
2121

22-
private queryCache: QueryCache;
22+
private readonly queryCache: QueryCache;
2323

24-
private preAggregations: PreAggregations;
24+
private readonly preAggregations: PreAggregations;
2525

2626
private readonly queryResults: any;
2727

@@ -179,7 +179,7 @@ export class PreAggregationLoadCache {
179179
throw new Error(`Load cache tries to load table ${preAggregation.tableName} outside of tablePrefixes filter: ${this.tablePrefixes.join(', ')}`);
180180
}
181181
const redisKey = this.tablesCachePrefixKey(preAggregation);
182-
if (!this.versionEntries[redisKey]) {
182+
if (!(await this.versionEntries[redisKey])) {
183183
this.versionEntries[redisKey] = this.calculateVersionEntries(preAggregation).catch(e => {
184184
delete this.versionEntries[redisKey];
185185
throw e;

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregationPartitionRangeLoader.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ export class PreAggregationPartitionRangeLoader {
8484
private async loadRangeQuery(rangeQuery: QueryTuple, partitionRange?: QueryDateRange) {
8585
const [query, values, queryOptions]: QueryTuple = rangeQuery;
8686
const invalidate =
87-
this.preAggregation.invalidateKeyQueries &&
88-
this.preAggregation.invalidateKeyQueries[0]
87+
this.preAggregation.invalidateKeyQueries?.[0]
8988
? this.preAggregation.invalidateKeyQueries[0].slice(0, 2)
9089
: false;
9190

@@ -128,7 +127,7 @@ export class PreAggregationPartitionRangeLoader {
128127
}
129128

130129
protected priority(defaultValue) {
131-
return this.preAggregation.priority != null ? this.preAggregation.priority : defaultValue;
130+
return this.preAggregation.priority ?? defaultValue;
132131
}
133132

134133
public async replaceQueryBuildRangeParams(queryValues: string[]): Promise<string[] | null> {
@@ -208,8 +207,7 @@ export class PreAggregationPartitionRangeLoader {
208207
this.replacePartitionSqlAndParams(this.preAggregation.sql, loadRange, partitionTableName),
209208
invalidateKeyQueries: (this.preAggregation.invalidateKeyQueries || [])
210209
.map(q => this.replacePartitionSqlAndParams(q, range, partitionTableName)),
211-
partitionInvalidateKeyQueries: this.preAggregation.partitionInvalidateKeyQueries &&
212-
this.preAggregation.partitionInvalidateKeyQueries.map(q => this.replacePartitionSqlAndParams(q, range, partitionTableName)),
210+
partitionInvalidateKeyQueries: this.preAggregation.partitionInvalidateKeyQueries?.map(q => this.replacePartitionSqlAndParams(q, range, partitionTableName)),
213211
indexesSql: (this.preAggregation.indexesSql || [])
214212
.map(q => ({ ...q, sql: this.replacePartitionSqlAndParams(q.sql, range, partitionTableName) })),
215213
previewSql: this.preAggregation.previewSql &&
@@ -529,7 +527,7 @@ export class PreAggregationPartitionRangeLoader {
529527
return parseLocalDate(data, timezone, timestampFormat);
530528
}
531529

532-
public static FROM_PARTITION_RANGE = FROM_PARTITION_RANGE;
530+
public static readonly FROM_PARTITION_RANGE = FROM_PARTITION_RANGE;
533531

534-
public static TO_PARTITION_RANGE = TO_PARTITION_RANGE;
532+
public static readonly TO_PARTITION_RANGE = TO_PARTITION_RANGE;
535533
}

packages/cubejs-query-orchestrator/src/orchestrator/PreAggregations.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BaseDriver, InlineTable, } from '@cubejs-backend/base-driver';
66
import { CubeStoreDriver } from '@cubejs-backend/cubestore-driver';
77
import LRUCache from 'lru-cache';
88

9-
import { PreAggTableToTempTable, Query, QueryBody, QueryCache, QueryTuple, QueryWithParams } from './QueryCache';
9+
import { PreAggTableToTempTable, Query, QueryBody, QueryCache, QueryWithParams } from './QueryCache';
1010
import { DriverFactory, DriverFactoryByDataSource } from './DriverFactory';
1111
import { QueryQueue } from './QueryQueue';
1212
import { CacheAndQueryDriverType } from './QueryOrchestrator';
@@ -67,7 +67,7 @@ export function getLastUpdatedAtTimestamp(
6767

6868
export function getStructureVersion(preAggregation) {
6969
const versionArray = [preAggregation.structureVersionLoadSql || preAggregation.loadSql];
70-
if (preAggregation.indexesSql && preAggregation.indexesSql.length) {
70+
if (preAggregation.indexesSql?.length) {
7171
versionArray.push(preAggregation.indexesSql);
7272
}
7373
if (preAggregation.streamOffset) {
@@ -389,7 +389,7 @@ export class PreAggregations {
389389
if (tables.length === 1) {
390390
status = 'done';
391391
} else {
392-
status = result && result.error
392+
status = result?.error
393393
? `failure: ${result.error}`
394394
: 'missing_partition';
395395
}
@@ -418,12 +418,12 @@ export class PreAggregations {
418418
return [true, status];
419419
}
420420

421-
public loadAllPreAggregationsIfNeeded(
421+
public async loadAllPreAggregationsIfNeeded(
422422
queryBody: PreAggregationQueryBody,
423423
): Promise<{
424424
preAggregationsTablesToTempTables: PreAggTableToTempTable[],
425425
values: null | string[],
426-
}> {
426+
}> {
427427
const preAggregations = queryBody.preAggregations || [];
428428

429429
const loadCacheByDataSource = queryBody.preAggregationsLoadCacheByDataSource || {};
@@ -490,7 +490,7 @@ export class PreAggregations {
490490

491491
if (i === preAggregations.length - 1 && queryBody.values) {
492492
queryParamsReplacement = await loader.replaceQueryBuildRangeParams(
493-
<string[]>queryBody.values,
493+
queryBody.values,
494494
);
495495
}
496496

@@ -516,8 +516,7 @@ export class PreAggregations {
516516
preAggregations.map(async (preAggregation) => {
517517
const { preAggregationStartEndQueries } = preAggregation;
518518
const invalidate =
519-
preAggregation.invalidateKeyQueries &&
520-
preAggregation.invalidateKeyQueries[0]
519+
preAggregation?.invalidateKeyQueries[0]
521520
? preAggregation.invalidateKeyQueries[0].slice(0, 2)
522521
: false;
523522
const isCached = preAggregation.partitionGranularity

packages/cubejs-query-orchestrator/test/unit/PreAggregations.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe('PreAggregations', () => {
155155
);
156156
});
157157

158-
test('syncronously create rollup from scratch', async () => {
158+
test('synchronously create rollup from scratch', async () => {
159159
mockDriver.now = 12345000;
160160
const { preAggregationsTablesToTempTables: result } = await preAggregations.loadAllPreAggregationsIfNeeded(basicQueryWithRenew);
161161
expect(result[0][1].targetTableName).toMatch(/stb_pre_aggregations.orders_number_and_count20191101_kjypcoio_5yftl5il/);

packages/cubejs-server-core/src/core/RefreshScheduler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export class RefreshScheduler {
254254
authInfo: null,
255255
...ctx,
256256
securityContext: ctx?.securityContext ? ctx.securityContext : {},
257-
requestId: `scheduler-${ctx && ctx.requestId || uuidv4()}`,
257+
requestId: `scheduler-${ctx?.requestId || uuidv4()}`,
258258
};
259259

260260
const concurrency =
@@ -424,7 +424,7 @@ export class RefreshScheduler {
424424
return {
425425
dependencies,
426426
partitions: query.groupedPartitions.length && query.groupedPartitions[query.groupedPartitions.length - 1]
427-
.filter(p => !partitionsFilter || !partitionsFilter.length || partitionsFilter.includes(p?.tableName)) || []
427+
.filter(p => !partitionsFilter?.length || partitionsFilter.includes(p?.tableName)) || []
428428
};
429429
});
430430

@@ -486,7 +486,7 @@ export class RefreshScheduler {
486486
});
487487
const queriesForPreAggregation = async (preAggregationIndex, timezone) => {
488488
const key = `${preAggregationIndex}_${timezone}`;
489-
if (!queriesCache[key]) {
489+
if (!(await queriesCache[key])) {
490490
const preAggregation = scheduledPreAggregations[preAggregationIndex];
491491
queriesCache[key] = this.refreshQueriesForPreAggregation(
492492
context, compilerApi, preAggregation, { ...queryingOptions, timezone }
@@ -591,7 +591,7 @@ export class RefreshScheduler {
591591
.filter(workerIndex => workerIndices.indexOf(workerIndex) !== -1)
592592
.map(async workerIndex => {
593593
const queryIteratorStateKey = JSON.stringify({ ...securityContext, workerIndex });
594-
const queryIterator = queryIteratorState && queryIteratorState[queryIteratorStateKey] ||
594+
const queryIterator = queryIteratorState?.[queryIteratorStateKey] ||
595595
(await this.roundRobinRefreshPreAggregationsQueryIterator(
596596
context, compilerApi, queryingOptions, queriesCache
597597
));
@@ -631,7 +631,7 @@ export class RefreshScheduler {
631631
preAggregations: dependencies.concat([partition]),
632632
continueWait: true,
633633
renewQuery: true,
634-
forceBuildPreAggregations: queryingOptions.forceBuildPreAggregations != null ? queryingOptions.forceBuildPreAggregations : true,
634+
forceBuildPreAggregations: queryingOptions.forceBuildPreAggregations ?? true,
635635
orphanedTimeout: 60 * 60,
636636
requestId: context.requestId,
637637
timezone: partition.timezone,

0 commit comments

Comments
 (0)