Skip to content

Commit 08bffcb

Browse files
authored
refactor(schema-compiler): Migrate code to TypeScript (#7486)
1 parent 2875265 commit 08bffcb

File tree

12 files changed

+237
-165
lines changed

12 files changed

+237
-165
lines changed

packages/cubejs-databricks-jdbc-driver/src/DatabricksQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DatabricksFilter extends BaseFilter {
2121
}
2222

2323
export class DatabricksQuery extends BaseQuery {
24-
public newFilter(filter: any) {
24+
public newFilter(filter: any): BaseFilter {
2525
return new DatabricksFilter(this, filter);
2626
}
2727

packages/cubejs-duckdb-driver/src/DuckDBQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class DuckDBFilter extends BaseFilter {
1515
}
1616

1717
export class DuckDBQuery extends BaseQuery {
18-
public newFilter(filter: any) {
18+
public newFilter(filter: any): BaseFilter {
1919
return new DuckDBFilter(this, filter);
2020
}
2121

packages/cubejs-firebolt-driver/src/FireboltQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class FireboltQuery extends BaseQuery {
4747
return `DATE_TRUNC('${GRANULARITY_TO_INTERVAL[granularity]}', ${dimension})`;
4848
}
4949

50-
public newFilter(filter: any) {
50+
public newFilter(filter: any): BaseFilter {
5151
return new FireboltFilter(this, filter);
5252
}
5353
}

packages/cubejs-questdb-driver/src/QuestQuery.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class QuestFilter extends BaseFilter {
3030
}
3131

3232
export class QuestQuery extends BaseQuery {
33-
public newFilter(filter: any) {
33+
public newFilter(filter: any): BaseFilter {
3434
return new QuestFilter(this, filter);
3535
}
3636

packages/cubejs-schema-compiler/src/adapter/BaseDimension.js renamed to packages/cubejs-schema-compiler/src/adapter/BaseDimension.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
1+
import type { BaseQuery } from './BaseQuery';
2+
13
export class BaseDimension {
2-
constructor(query, dimension) {
3-
this.query = query;
4+
public readonly expression: any;
5+
6+
public readonly expressionCubeName: any;
7+
8+
public readonly expressionName: string | undefined;
9+
10+
public readonly isMemberExpression: boolean = false;
11+
12+
public constructor(
13+
protected readonly query: BaseQuery,
14+
public readonly dimension: any
15+
) {
416
if (dimension && dimension.expression) {
517
this.expression = dimension.expression;
618
this.expressionCubeName = dimension.cubeName;
719
this.expressionName = dimension.expressionName || `${dimension.cubeName}.${dimension.name}`;
820
this.isMemberExpression = !!dimension.definition;
921
}
10-
this.dimension = dimension;
1122
}
1223

13-
selectColumns() {
24+
public selectColumns(): string[] | null {
1425
return [`${this.dimensionSql()} ${this.aliasName()}`];
1526
}
1627

17-
hasNoRemapping() {
28+
public hasNoRemapping() {
1829
return this.dimensionSql() === this.aliasName();
1930
}
2031

21-
cumulativeSelectColumns() {
32+
public cumulativeSelectColumns() {
2233
return [`${this.aliasName()}`];
2334
}
2435

25-
dimensionSql() {
36+
public dimensionSql() {
2637
if (this.expression) {
2738
return this.convertTzForRawTimeDimensionIfNeeded(() => this.query.evaluateSymbolSql(this.expressionCubeName, this.expressionName, this.definition(), 'dimension'));
2839
}
@@ -32,7 +43,7 @@ export class BaseDimension {
3243
return this.convertTzForRawTimeDimensionIfNeeded(() => this.query.dimensionSql(this));
3344
}
3445

35-
convertTzForRawTimeDimensionIfNeeded(sql) {
46+
public convertTzForRawTimeDimensionIfNeeded(sql) {
3647
if (this.query.options.convertTzForRawTimeDimension) {
3748
return this.query.evaluateSymbolSqlWithContext(sql, {
3849
convertTzForRawTimeDimension: true
@@ -42,29 +53,29 @@ export class BaseDimension {
4253
}
4354
}
4455

45-
sqlDefinition() {
56+
public sqlDefinition() {
4657
return this.dimensionDefinition().sql;
4758
}
4859

49-
getMembers() {
60+
public getMembers() {
5061
return [this];
5162
}
5263

53-
cube() {
64+
public cube() {
5465
if (this.expression) {
5566
return this.query.cubeEvaluator.cubeFromPath(this.expressionCubeName);
5667
}
5768
return this.query.cubeEvaluator.cubeFromPath(this.dimension);
5869
}
5970

60-
dimensionDefinition() {
71+
public dimensionDefinition() {
6172
if (this.query.cubeEvaluator.isSegment(this.dimension)) {
6273
return this.query.cubeEvaluator.segmentByPath(this.dimension);
6374
}
6475
return this.query.cubeEvaluator.dimensionByPath(this.dimension);
6576
}
6677

67-
definition() {
78+
public definition() {
6879
if (this.expression) {
6980
return {
7081
sql: this.expression,
@@ -75,33 +86,36 @@ export class BaseDimension {
7586
return this.dimensionDefinition();
7687
}
7788

78-
aliasName() {
89+
public aliasName(): string | null {
7990
// Require should be here because of cycle depend
8091
return this.query.escapeColumnName(this.unescapedAliasName());
8192
}
8293

83-
unescapedAliasName() {
84-
if (this.expression) {
94+
public unescapedAliasName(): string {
95+
if (this.expression && this.expressionName) {
8596
return this.query.aliasName(this.expressionName);
8697
}
98+
8799
return this.query.aliasName(this.dimension);
88100
}
89101

90-
dateFieldType() {
102+
public dateFieldType() {
91103
return this.dimensionDefinition().fieldType;
92104
}
93105

94-
path() {
106+
public path() {
95107
if (this.expression) {
96108
return null;
97109
}
110+
98111
if (this.query.cubeEvaluator.isSegment(this.dimension)) {
99112
return this.query.cubeEvaluator.parsePath('segments', this.dimension);
100113
}
114+
101115
return this.query.cubeEvaluator.parsePath('dimensions', this.dimension);
102116
}
103117

104-
expressionPath() {
118+
public expressionPath() {
105119
if (this.expression) {
106120
return `expr:${this.expression.expressionName}`;
107121
}

0 commit comments

Comments
 (0)