@@ -2033,9 +2033,31 @@ export class BaseQuery {
20332033 }
20342034
20352035 checkShouldBuildJoinForMeasureSelect ( measures , keyCubeName ) {
2036+ // When member expression references view, it would have to collect join hints from view
2037+ // Consider join A->B, as many-to-one, so B is multiplied and A is not, and member expression like SUM(AB_view.dimB)
2038+ // Both `collectCubeNamesFor` and `collectJoinHintsFor` would return too many cubes here
2039+ // They both walk join hints, and gather every cube present there
2040+ // For view we would get both A and B, because join hints would go from join tree root
2041+ // Even though expression references only B, and should be OK to use it with B as keyCube
2042+ // So this check would build new join tree from both A and B, B will be multiplied, and that would break check
2043+
20362044 return measures . map ( measure => {
2037- const cubes = this . collectFrom ( [ measure ] , this . collectCubeNamesFor . bind ( this ) , 'collectCubeNamesFor' ) ;
2038- const joinHints = this . collectFrom ( [ measure ] , this . collectJoinHintsFor . bind ( this ) , 'collectJoinHintsFor' ) ;
2045+ const memberNamesForMeasure = this . collectFrom (
2046+ [ measure ] ,
2047+ this . collectMemberNamesFor . bind ( this ) ,
2048+ 'collectMemberNamesFor' ,
2049+ ) ;
2050+
2051+ const nonViewMembers = memberNamesForMeasure
2052+ . filter ( mem => {
2053+ const cubeName = this . cubeEvaluator . parsePathAnyType ( mem ) [ 0 ] ;
2054+ const cubeDef = this . cubeEvaluator . getCubeDefinition ( cubeName ) ;
2055+ return ! cubeDef . isView ;
2056+ } )
2057+ . map ( m => this . memberInstanceByPath ( m ) ) ;
2058+
2059+ const cubes = this . collectFrom ( nonViewMembers , this . collectCubeNamesFor . bind ( this ) , 'collectCubeNamesFor' ) ;
2060+ const joinHints = this . collectFrom ( nonViewMembers , this . collectJoinHintsFor . bind ( this ) , 'collectJoinHintsFor' ) ;
20392061 if ( R . any ( cubeName => keyCubeName !== cubeName , cubes ) ) {
20402062 const measuresJoin = this . joinGraph . buildJoin ( joinHints ) ;
20412063 if ( measuresJoin . multiplicationFactor [ keyCubeName ] ) {
0 commit comments