Skip to content

Commit

Permalink
refactor(schema-compiler): Migrate code to TypeScript (#7486)
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr authored Dec 4, 2023
1 parent 2875265 commit 08bffcb
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DatabricksFilter extends BaseFilter {
}

export class DatabricksQuery extends BaseQuery {
public newFilter(filter: any) {
public newFilter(filter: any): BaseFilter {
return new DatabricksFilter(this, filter);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-duckdb-driver/src/DuckDBQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class DuckDBFilter extends BaseFilter {
}

export class DuckDBQuery extends BaseQuery {
public newFilter(filter: any) {
public newFilter(filter: any): BaseFilter {
return new DuckDBFilter(this, filter);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-firebolt-driver/src/FireboltQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class FireboltQuery extends BaseQuery {
return `DATE_TRUNC('${GRANULARITY_TO_INTERVAL[granularity]}', ${dimension})`;
}

public newFilter(filter: any) {
public newFilter(filter: any): BaseFilter {
return new FireboltFilter(this, filter);
}
}
2 changes: 1 addition & 1 deletion packages/cubejs-questdb-driver/src/QuestQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class QuestFilter extends BaseFilter {
}

export class QuestQuery extends BaseQuery {
public newFilter(filter: any) {
public newFilter(filter: any): BaseFilter {
return new QuestFilter(this, filter);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import type { BaseQuery } from './BaseQuery';

export class BaseDimension {
constructor(query, dimension) {
this.query = query;
public readonly expression: any;

public readonly expressionCubeName: any;

public readonly expressionName: string | undefined;

public readonly isMemberExpression: boolean = false;

public constructor(
protected readonly query: BaseQuery,
public readonly dimension: any
) {
if (dimension && dimension.expression) {
this.expression = dimension.expression;
this.expressionCubeName = dimension.cubeName;
this.expressionName = dimension.expressionName || `${dimension.cubeName}.${dimension.name}`;
this.isMemberExpression = !!dimension.definition;
}
this.dimension = dimension;
}

selectColumns() {
public selectColumns(): string[] | null {
return [`${this.dimensionSql()} ${this.aliasName()}`];
}

hasNoRemapping() {
public hasNoRemapping() {
return this.dimensionSql() === this.aliasName();
}

cumulativeSelectColumns() {
public cumulativeSelectColumns() {
return [`${this.aliasName()}`];
}

dimensionSql() {
public dimensionSql() {
if (this.expression) {
return this.convertTzForRawTimeDimensionIfNeeded(() => this.query.evaluateSymbolSql(this.expressionCubeName, this.expressionName, this.definition(), 'dimension'));
}
Expand All @@ -32,7 +43,7 @@ export class BaseDimension {
return this.convertTzForRawTimeDimensionIfNeeded(() => this.query.dimensionSql(this));
}

convertTzForRawTimeDimensionIfNeeded(sql) {
public convertTzForRawTimeDimensionIfNeeded(sql) {
if (this.query.options.convertTzForRawTimeDimension) {
return this.query.evaluateSymbolSqlWithContext(sql, {
convertTzForRawTimeDimension: true
Expand All @@ -42,29 +53,29 @@ export class BaseDimension {
}
}

sqlDefinition() {
public sqlDefinition() {
return this.dimensionDefinition().sql;
}

getMembers() {
public getMembers() {
return [this];
}

cube() {
public cube() {
if (this.expression) {
return this.query.cubeEvaluator.cubeFromPath(this.expressionCubeName);
}
return this.query.cubeEvaluator.cubeFromPath(this.dimension);
}

dimensionDefinition() {
public dimensionDefinition() {
if (this.query.cubeEvaluator.isSegment(this.dimension)) {
return this.query.cubeEvaluator.segmentByPath(this.dimension);
}
return this.query.cubeEvaluator.dimensionByPath(this.dimension);
}

definition() {
public definition() {
if (this.expression) {
return {
sql: this.expression,
Expand All @@ -75,33 +86,36 @@ export class BaseDimension {
return this.dimensionDefinition();
}

aliasName() {
public aliasName(): string | null {
// Require should be here because of cycle depend
return this.query.escapeColumnName(this.unescapedAliasName());
}

unescapedAliasName() {
if (this.expression) {
public unescapedAliasName(): string {
if (this.expression && this.expressionName) {
return this.query.aliasName(this.expressionName);
}

return this.query.aliasName(this.dimension);
}

dateFieldType() {
public dateFieldType() {
return this.dimensionDefinition().fieldType;
}

path() {
public path() {
if (this.expression) {
return null;
}

if (this.query.cubeEvaluator.isSegment(this.dimension)) {
return this.query.cubeEvaluator.parsePath('segments', this.dimension);
}

return this.query.cubeEvaluator.parsePath('dimensions', this.dimension);
}

expressionPath() {
public expressionPath() {
if (this.expression) {
return `expr:${this.expression.expressionName}`;
}
Expand Down
Loading

0 comments on commit 08bffcb

Please sign in to comment.