@@ -24,6 +24,7 @@ import {
2424 timeSeriesFromCustomInterval
2525} from '@cubejs-backend/shared' ;
2626
27+ import { CubeSymbols } from "../compiler/CubeSymbols" ;
2728import { UserError } from '../compiler/UserError' ;
2829import { SqlParser } from '../parser/SqlParser' ;
2930import { BaseDimension } from './BaseDimension' ;
@@ -1411,7 +1412,7 @@ export class BaseQuery {
14111412 // TODO condition should something else instead of rank
14121413 multiStageQuery : ! ! withQuery . measures . find ( d => {
14131414 const { type } = this . newMeasure ( d ) . definition ( ) ;
1414- return type === 'rank' || BaseQuery . isCalculatedMeasureType ( type ) ;
1415+ return type === 'rank' || CubeSymbols . isCalculatedMeasureType ( type ) ;
14151416 } ) ,
14161417 disableExternalPreAggregations : true ,
14171418 } ;
@@ -2946,7 +2947,7 @@ export class BaseQuery {
29462947 funDef = this . countDistinctApprox ( evaluateSql ) ;
29472948 } else if ( symbol . type === 'countDistinct' || symbol . type === 'count' && ! symbol . sql && multiplied ) {
29482949 funDef = `count(distinct ${ evaluateSql } )` ;
2949- } else if ( BaseQuery . isCalculatedMeasureType ( symbol . type ) ) {
2950+ } else if ( CubeSymbols . isCalculatedMeasureType ( symbol . type ) ) {
29502951 // TODO calculated measure type will be ungrouped
29512952 // if (this.multiStageDimensions.length !== this.dimensions.length) {
29522953 // throw new UserError(`Calculated measure '${measurePath}' uses group_by or reduce_by context modifiers while it isn't allowed`);
@@ -2972,23 +2973,12 @@ export class BaseQuery {
29722973 return this . primaryKeyCount ( cubeName , true ) ;
29732974 }
29742975 }
2975- if ( BaseQuery . isCalculatedMeasureType ( symbol . type ) ) {
2976+ if ( CubeSymbols . isCalculatedMeasureType ( symbol . type ) ) {
29762977 return evaluateSql ;
29772978 }
29782979 return `${ symbol . type } (${ evaluateSql } )` ;
29792980 }
29802981
2981- static isCalculatedMeasureType ( type ) {
2982- return type === 'number' || type === 'string' || type === 'time' || type === 'boolean' ;
2983- }
2984-
2985- /**
2986- TODO: support type qualifiers on min and max
2987- */
2988- static toMemberDataType ( type ) {
2989- return this . isCalculatedMeasureType ( type ) ? type : 'number' ;
2990- }
2991-
29922982 aggregateOnGroupedColumn ( symbol , evaluateSql , topLevelMerge , measurePath ) {
29932983 const cumulativeMeasureFilters = ( this . safeEvaluateSymbolContext ( ) . cumulativeMeasureFilters || { } ) [ measurePath ] ;
29942984 if ( cumulativeMeasureFilters ) {
@@ -4095,7 +4085,7 @@ export class BaseQuery {
40954085 sqlUtils : {
40964086 convertTz : ( field ) => field ,
40974087 } ,
4098- securityContext : BaseQuery . contextSymbolsProxyFrom ( { } , allocateParam ) ,
4088+ securityContext : CubeSymbols . contextSymbolsProxyFrom ( { } , allocateParam ) ,
40994089 } ;
41004090 }
41014091
@@ -4110,41 +4100,7 @@ export class BaseQuery {
41104100 }
41114101
41124102 contextSymbolsProxy ( symbols ) {
4113- return BaseQuery . contextSymbolsProxyFrom ( symbols , this . paramAllocator . allocateParam . bind ( this . paramAllocator ) ) ;
4114- }
4115-
4116- static contextSymbolsProxyFrom ( symbols , allocateParam ) {
4117- return new Proxy ( symbols , {
4118- get : ( target , name ) => {
4119- const propValue = target [ name ] ;
4120- const methods = ( paramValue ) => ( {
4121- filter : ( column ) => {
4122- if ( paramValue ) {
4123- const value = Array . isArray ( paramValue ) ?
4124- paramValue . map ( allocateParam ) :
4125- allocateParam ( paramValue ) ;
4126- if ( typeof column === 'function' ) {
4127- return column ( value ) ;
4128- } else {
4129- return `${ column } = ${ value } ` ;
4130- }
4131- } else {
4132- return '1 = 1' ;
4133- }
4134- } ,
4135- requiredFilter : ( column ) => {
4136- if ( ! paramValue ) {
4137- throw new UserError ( `Filter for ${ column } is required` ) ;
4138- }
4139- return methods ( paramValue ) . filter ( column ) ;
4140- } ,
4141- unsafeValue : ( ) => paramValue
4142- } ) ;
4143- return methods ( target ) [ name ] ||
4144- typeof propValue === 'object' && propValue !== null && BaseQuery . contextSymbolsProxyFrom ( propValue , allocateParam ) ||
4145- methods ( propValue ) ;
4146- }
4147- } ) ;
4103+ return CubeSymbols . contextSymbolsProxyFrom ( symbols , this . paramAllocator . allocateParam . bind ( this . paramAllocator ) ) ;
41484104 }
41494105
41504106 static extractFilterMembers ( filter ) {
0 commit comments