@@ -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 ,
@@ -1593,34 +1594,36 @@ class ApiGateway {
15931594 response : any ,
15941595 responseType ?: ResultType ,
15951596 ) {
1596- const data = response . data . isNative ?
1597- JSON . parse ( transformDataNative ( JSON . stringify ( {
1598- aliasToMemberNameMap : sqlQuery . aliasNameToMember ,
1599- annotation : {
1600- ...annotation . measures ,
1601- ...annotation . dimensions ,
1602- ...annotation . timeDimensions
1603- } ,
1604- query : normalizedQuery ,
1605- queryType,
1606- resType : responseType ,
1607- } ) , response . data . getNativeRef ( ) ) . result ) as TransformDataResponse
1597+ const transformDataParams = {
1598+ aliasToMemberNameMap : sqlQuery . aliasNameToMember ,
1599+ annotation : {
1600+ ...annotation . measures ,
1601+ ...annotation . dimensions ,
1602+ ...annotation . timeDimensions
1603+ } as { [ member : string ] : ConfigItem } ,
1604+ query : normalizedQuery ,
1605+ queryType,
1606+ resType : responseType ,
1607+ } ;
1608+
1609+ // We postpone data transformation until the last minute
1610+ // in case when all responses are native - we process them in native part
1611+ const dataCb : TransformDataResponseCb = response . data . isNative ?
1612+ ( ) => JSON . parse (
1613+ transformDataNative (
1614+ JSON . stringify ( transformDataParams ) , response . data . getNativeRef ( )
1615+ ) . result
1616+ ) as TransformDataResponse
16081617 :
1609- transformData (
1610- sqlQuery . aliasNameToMember ,
1611- {
1612- ...annotation . measures ,
1613- ...annotation . dimensions ,
1614- ...annotation . timeDimensions
1615- } as { [ member : string ] : ConfigItem } ,
1616- response . data ,
1617- normalizedQuery ,
1618- queryType ,
1619- responseType ,
1620- ) ;
1618+ ( ) => transformData ( {
1619+ ...transformDataParams ,
1620+ data : response . data ,
1621+ } ) ;
1622+
16211623 return {
16221624 query : normalizedQuery ,
1623- data,
1625+ dataCb,
1626+ transformDataParams,
16241627 lastRefreshTime : response . lastRefreshTime ?. toISOString ( ) ,
16251628 ...(
16261629 getEnv ( 'devMode' ) ||
@@ -1640,6 +1643,7 @@ class ApiGateway {
16401643 external : response . external ,
16411644 slowQuery : Boolean ( response . slowQuery ) ,
16421645 total : normalizedQuery . total ? response . total : null ,
1646+ isNative : response . data . isNative
16431647 } ;
16441648 }
16451649
@@ -1789,22 +1793,40 @@ class ApiGateway {
17891793 r . usedPreAggregations || { }
17901794 ) . length
17911795 ) . length ,
1792- queriesWithData :
1793- results . filter ( ( r : any ) => r . data ?. length ) . length ,
1796+ // Have to omit because data could be processed natively
1797+ // so it is not known at this point
1798+ // queriesWithData:
1799+ // results.filter((r: any) => r.data?.length).length,
17941800 dbType : results . map ( r => r . dbType ) ,
17951801 } ,
17961802 context ,
17971803 ) ;
17981804
1805+ const allNative = results . every ( r => r . isNative ) ;
1806+
17991807 if ( props . queryType === 'multi' ) {
18001808 res ( {
18011809 queryType,
1802- results,
1810+ results : results . map ( r => {
1811+ const data = r . dataCb ( ) ;
1812+ return {
1813+ ...r ,
1814+ data,
1815+ dataCb : undefined ,
1816+ transformDataParams : undefined
1817+ } ;
1818+ } ) ,
18031819 pivotQuery : getPivotQuery ( queryType , normalizedQueries ) ,
18041820 slowQuery
18051821 } ) ;
18061822 } else {
1807- res ( results [ 0 ] ) ;
1823+ const data = results [ 0 ] . dataCb ( ) ;
1824+ res ( {
1825+ ...results [ 0 ] ,
1826+ data,
1827+ dataCb : undefined ,
1828+ transformDataParams : undefined
1829+ } ) ;
18081830 }
18091831 } catch ( e : any ) {
18101832 this . handleError ( {
0 commit comments