@@ -92,6 +92,7 @@ import {
9292 transformJoins ,
9393 transformPreAggregations ,
9494} from './helpers/transformMetaExtended' ;
95+ import { TransformDataResponseCb } from './types/responses' ;
9596
9697type HandleErrorOptions = {
9798 e : any ,
@@ -1595,34 +1596,36 @@ class ApiGateway {
15951596 response : any ,
15961597 responseType ?: ResultType ,
15971598 ) {
1598- const data = response . data . isNative ?
1599- JSON . parse ( transformDataNative ( JSON . stringify ( {
1600- aliasToMemberNameMap : sqlQuery . aliasNameToMember ,
1601- annotation : {
1602- ...annotation . measures ,
1603- ...annotation . dimensions ,
1604- ...annotation . timeDimensions
1605- } ,
1606- query : normalizedQuery ,
1607- queryType,
1608- resType : responseType ,
1609- } ) , response . data . getNativeRef ( ) ) . result ) as TransformDataResponse
1599+ const transformDataParams = {
1600+ aliasToMemberNameMap : sqlQuery . aliasNameToMember ,
1601+ annotation : {
1602+ ...annotation . measures ,
1603+ ...annotation . dimensions ,
1604+ ...annotation . timeDimensions
1605+ } as { [ member : string ] : ConfigItem } ,
1606+ query : normalizedQuery ,
1607+ queryType,
1608+ resType : responseType ,
1609+ } ;
1610+
1611+ // We postpone data transformation until the last minute
1612+ // in case when all responses are native - we process them in native part
1613+ const dataCb : TransformDataResponseCb = response . data . isNative ?
1614+ ( ) => JSON . parse (
1615+ transformDataNative (
1616+ JSON . stringify ( transformDataParams ) , response . data . getNativeRef ( )
1617+ ) . result
1618+ ) as TransformDataResponse
16101619 :
1611- transformData (
1612- sqlQuery . aliasNameToMember ,
1613- {
1614- ...annotation . measures ,
1615- ...annotation . dimensions ,
1616- ...annotation . timeDimensions
1617- } as { [ member : string ] : ConfigItem } ,
1618- response . data ,
1619- normalizedQuery ,
1620- queryType ,
1621- responseType ,
1622- ) ;
1620+ ( ) => transformData ( {
1621+ ...transformDataParams ,
1622+ data : response . data ,
1623+ } ) ;
1624+
16231625 return {
16241626 query : normalizedQuery ,
1625- data,
1627+ dataCb,
1628+ transformDataParams,
16261629 lastRefreshTime : response . lastRefreshTime ?. toISOString ( ) ,
16271630 ...(
16281631 getEnv ( 'devMode' ) ||
@@ -1642,6 +1645,7 @@ class ApiGateway {
16421645 external : response . external ,
16431646 slowQuery : Boolean ( response . slowQuery ) ,
16441647 total : normalizedQuery . total ? response . total : null ,
1648+ isNative : response . data . isNative
16451649 } ;
16461650 }
16471651
@@ -1791,22 +1795,40 @@ class ApiGateway {
17911795 r . usedPreAggregations || { }
17921796 ) . length
17931797 ) . length ,
1794- queriesWithData :
1795- results . filter ( ( r : any ) => r . data ?. length ) . length ,
1798+ // Have to omit because data could be processed natively
1799+ // so it is not known at this point
1800+ // queriesWithData:
1801+ // results.filter((r: any) => r.data?.length).length,
17961802 dbType : results . map ( r => r . dbType ) ,
17971803 } ,
17981804 context ,
17991805 ) ;
18001806
1807+ const allNative = results . every ( r => r . isNative ) ;
1808+
18011809 if ( props . queryType === 'multi' ) {
18021810 res ( {
18031811 queryType,
1804- results,
1812+ results : results . map ( r => {
1813+ const data = r . dataCb ( ) ;
1814+ return {
1815+ ...r ,
1816+ data,
1817+ dataCb : undefined ,
1818+ transformDataParams : undefined
1819+ } ;
1820+ } ) ,
18051821 pivotQuery : getPivotQuery ( queryType , normalizedQueries ) ,
18061822 slowQuery
18071823 } ) ;
18081824 } else {
1809- res ( results [ 0 ] ) ;
1825+ const data = results [ 0 ] . dataCb ( ) ;
1826+ res ( {
1827+ ...results [ 0 ] ,
1828+ data,
1829+ dataCb : undefined ,
1830+ transformDataParams : undefined
1831+ } ) ;
18101832 }
18111833 } catch ( e : any ) {
18121834 this . handleError ( {
0 commit comments