@@ -338,8 +338,7 @@ class BaseQuery {
338338 // eslint-disable-next-line prefer-template
339339 const inlineWhereConditions = [ ] ;
340340 const commonQuery = this . rewriteInlineWhere ( ( ) => this . commonQuery ( ) , inlineWhereConditions ) ;
341- const inlineFilters = inlineWhereConditions . map ( f => ( { filterToWhere : ( ) => f } ) ) ;
342- return `${ commonQuery } ${ this . baseWhere ( this . allFilters . concat ( inlineFilters ) ) } ` +
341+ return `${ commonQuery } ${ this . baseWhere ( this . allFilters . concat ( inlineWhereConditions ) ) } ` +
343342 this . groupByClause ( ) +
344343 this . baseHaving ( this . measureFilters ) +
345344 this . orderBy ( ) +
@@ -632,7 +631,8 @@ class BaseQuery {
632631 this . cubeEvaluator . cubeFromPath ( cube ) . rewriteQueries &&
633632 parser . isSimpleAsteriskQuery ( )
634633 ) {
635- this . safeEvaluateSymbolContext ( ) . inlineWhereConditions . push ( parser . extractWhereConditions ( cubeAlias ) ) ;
634+ const conditions = parser . extractWhereConditions ( cubeAlias ) ;
635+ this . safeEvaluateSymbolContext ( ) . inlineWhereConditions . push ( { filterToWhere : ( ) => conditions } ) ;
636636 return [ parser . extractTableFrom ( ) , cubeAlias ] ;
637637 } else {
638638 return [ sql , cubeAlias ] ;
@@ -719,15 +719,18 @@ class BaseQuery {
719719 regularMeasuresSubQuery ( measures , filters ) {
720720 filters = filters || this . allFilters ;
721721
722- return `SELECT ${ this . selectAllDimensionsAndMeasures ( measures ) } FROM ${
723- this . joinQuery (
724- this . join ,
725- this . collectFrom (
726- this . dimensionsForSelect ( ) . concat ( measures ) . concat ( this . allFilters ) ,
727- this . collectSubQueryDimensionsFor . bind ( this )
728- )
722+ const inlineWhereConditions = [ ] ;
723+
724+ const query = this . rewriteInlineWhere ( ( ) => this . joinQuery (
725+ this . join ,
726+ this . collectFrom (
727+ this . dimensionsForSelect ( ) . concat ( measures ) . concat ( this . allFilters ) ,
728+ this . collectSubQueryDimensionsFor . bind ( this )
729729 )
730- } ${ this . baseWhere ( filters ) } ` +
730+ ) , inlineWhereConditions ) ;
731+ return `SELECT ${ this . selectAllDimensionsAndMeasures ( measures ) } FROM ${
732+ query
733+ } ${ this . baseWhere ( filters . concat ( inlineWhereConditions ) ) } ` +
731734 ( ! this . safeEvaluateSymbolContext ( ) . ungrouped && this . groupByClause ( ) || '' ) ;
732735 }
733736
@@ -736,8 +739,8 @@ class BaseQuery {
736739 const primaryKeyDimension = this . newDimension ( this . primaryKeyName ( keyCubeName ) ) ;
737740 const shouldBuildJoinForMeasureSelect = this . checkShouldBuildJoinForMeasureSelect ( measures , keyCubeName ) ;
738741
739- let keyCubeSql = this . cubeSql ( keyCubeName ) ;
740-
742+ let keyCubeSql ;
743+ const inlineWhereConditionsForKeyCube = [ ] ;
741744 const measureSubQueryDimensions = this . collectFrom ( measures , this . collectSubQueryDimensionsFor . bind ( this ) ) ;
742745
743746 if ( shouldBuildJoinForMeasureSelect ) {
@@ -749,6 +752,11 @@ class BaseQuery {
749752 ) ;
750753 }
751754 keyCubeSql = `(${ this . aggregateSubQueryMeasureJoin ( keyCubeName , measures , measuresJoin , primaryKeyDimension , measureSubQueryDimensions ) } )` ;
755+ } else {
756+ [ keyCubeSql ] = this . rewriteInlineWhere (
757+ ( ) => this . rewriteInlineCubeSql ( keyCubeName ) ,
758+ inlineWhereConditionsForKeyCube
759+ ) ;
752760 }
753761
754762 const measureSelectFn = ( ) => measures . map ( m => m . selectColumns ( ) ) ;
@@ -769,6 +777,7 @@ class BaseQuery {
769777 `LEFT OUTER JOIN ${ keyCubeSql } ${ this . asSyntaxJoin } ${ this . cubeAlias ( keyCubeName ) } ON
770778 ${ this . escapeColumnName ( 'keys' ) } .${ primaryKeyDimension . aliasName ( ) } = ${ keyInMeasureSelect } ` +
771779 subQueryJoins +
780+ this . baseWhere ( inlineWhereConditionsForKeyCube ) +
772781 ( ! this . safeEvaluateSymbolContext ( ) . ungrouped && this . groupByClause ( ) || '' ) ;
773782 }
774783
@@ -817,12 +826,14 @@ class BaseQuery {
817826 }
818827
819828 keysQuery ( primaryKeyDimension , filters ) {
829+ const inlineWhereConditions = [ ] ;
830+ const query = this . rewriteInlineWhere ( ( ) => this . joinQuery (
831+ this . join ,
832+ this . collectFrom ( this . keyDimensions ( primaryKeyDimension ) , this . collectSubQueryDimensionsFor . bind ( this ) )
833+ ) , inlineWhereConditions ) ;
820834 return `SELECT DISTINCT ${ this . keysSelect ( primaryKeyDimension ) } FROM ${
821- this . joinQuery (
822- this . join ,
823- this . collectFrom ( this . keyDimensions ( primaryKeyDimension ) , this . collectSubQueryDimensionsFor . bind ( this ) )
824- )
825- } ${ this . baseWhere ( filters ) } `;
835+ query
836+ } ${ this . baseWhere ( filters . concat ( inlineWhereConditions ) ) } `;
826837 }
827838
828839 keysSelect ( primaryKeyDimension ) {
0 commit comments