Skip to content

Commit debb3a8

Browse files
committed
make all native cubestore_result_transform functions async
1 parent 87c424d commit debb3a8

File tree

7 files changed

+233
-167
lines changed

7 files changed

+233
-167
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ class ApiGateway {
15881588
* result object.
15891589
* @internal
15901590
*/
1591-
private getResultInternal(
1591+
private async getResultInternal(
15921592
context: RequestContext,
15931593
queryType: QueryType,
15941594
normalizedQuery: NormalizedQuery,
@@ -1625,13 +1625,14 @@ class ApiGateway {
16251625
// We postpone data transformation until the last minute
16261626
// in case when all responses are native - we process them in native part
16271627
const dataCb: TransformDataResponseCb = response.data.isNative ?
1628-
() => JSON.parse(
1629-
transformDataNative(
1628+
async () => {
1629+
const jsonData = await transformDataNative(
16301630
JSON.stringify(transformDataParams), response.data.getNativeRef()
1631-
).result
1632-
) as TransformDataResponse
1631+
);
1632+
return JSON.parse(jsonData.result) as TransformDataResponse;
1633+
}
16331634
:
1634-
() => transformData({
1635+
async () => transformData({
16351636
...transformDataParams,
16361637
data: response.data,
16371638
});
@@ -1842,20 +1843,20 @@ class ApiGateway {
18421843
};
18431844
const resultDataJson = JSON.stringify(responseDataObj);
18441845

1845-
res(getFinalCubestoreResultMulti(transformDataJson, rawDataRef, resultDataJson));
1846+
res(await getFinalCubestoreResultMulti(transformDataJson, rawDataRef, resultDataJson));
18461847
} else {
18471848
// if we have mixed query results (there are js and native)
18481849
// we prepare results separately: on js and native sides
18491850
// and serve final response from JS side
18501851
res({
18511852
queryType,
1852-
results: results.map(r => {
1853-
const data = r.dataCb();
1853+
results: await Promise.all(results.map(async (r) => {
1854+
const data = await r.dataCb();
18541855
return {
18551856
...cleanupResult(r),
18561857
data,
18571858
};
1858-
}),
1859+
})),
18591860
pivotQuery: getPivotQuery(queryType, normalizedQueries),
18601861
slowQuery
18611862
});
@@ -1866,9 +1867,9 @@ class ApiGateway {
18661867
const transformDataJson = JSON.stringify(r.transformDataParams);
18671868
const rawDataRef = r.rawData.getNativeRef();
18681869
const resultDataJson = JSON.stringify(cleanupResult(r));
1869-
res(getFinalCubestoreResult(transformDataJson, rawDataRef, resultDataJson));
1870+
res(await getFinalCubestoreResult(transformDataJson, rawDataRef, resultDataJson));
18701871
} else {
1871-
const data = results[0].dataCb();
1872+
const data = await results[0].dataCb();
18721873
res({
18731874
...cleanupResult(results[0]),
18741875
data,
@@ -2021,19 +2022,19 @@ class ApiGateway {
20212022
[[], [], []]
20222023
);
20232024

2024-
res(getFinalCubestoreResultArray(transformDataJson, rawDataRef, resultDataJson));
2025+
res(await getFinalCubestoreResultArray(transformDataJson, rawDataRef, resultDataJson));
20252026
} else {
20262027
// if we have mixed query results (there are js and native)
20272028
// we prepare results separately: on js and native sides
20282029
// and serve final response from JS side
20292030
res({
2030-
results: results.map(r => {
2031-
const data = r.dataCb();
2031+
results: await Promise.all(results.map(async (r) => {
2032+
const data = await r.dataCb();
20322033
return {
20332034
...cleanupResult(r),
20342035
data,
20352036
};
2036-
}),
2037+
})),
20372038
});
20382039
}
20392040
} else {

packages/cubejs-api-gateway/src/types/responses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ export type TransformDataRequest = {
3434
resType?: ResultType
3535
};
3636

37-
export type TransformDataResponseCb = () => TransformDataResponse;
37+
export type TransformDataResponseCb = () => Promise<TransformDataResponse>;

packages/cubejs-backend-native/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cubejs-backend-native/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ crate-type = ["cdylib", "lib"]
1919
cubesqlplanner = { path = "../../rust/cubesqlplanner/cubesqlplanner" }
2020
cubeorchestrator = { path = "../../rust/cubeorchestrator" }
2121
cubenativeutils = { path = "../../rust/cubenativeutils" }
22+
anyhow = "1.0"
2223
async-channel = { version = "2" }
2324
async-trait = "0.1.36"
2425
convert_case = "0.6.0"

packages/cubejs-backend-native/js/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,25 +383,25 @@ export const getCubestoreResult = (ref: CubeStoreResultWrapper): ResultRow[] =>
383383
return native.getCubestoreResult(ref);
384384
};
385385

386-
export const transformData = (transformDataJson: string, rows: any): TransformDataResponseNative => {
386+
export const transformData = (transformDataJson: string, rows: any): Promise<TransformDataResponseNative> => {
387387
const native = loadNative();
388388

389389
return native.transformQueryData(transformDataJson, rows);
390390
};
391391

392-
export const getFinalCubestoreResult = (transformDataJson: string, rows: any, resultData: string): ArrayBuffer => {
392+
export const getFinalCubestoreResult = (transformDataJson: string, rows: any, resultData: string): Promise<ArrayBuffer> => {
393393
const native = loadNative();
394394

395395
return native.getFinalCubestoreResult(transformDataJson, rows, resultData);
396396
};
397397

398-
export const getFinalCubestoreResultArray = (transformDataJson: string[], rows: any[], resultDataJson: string[]): ArrayBuffer => {
398+
export const getFinalCubestoreResultArray = (transformDataJson: string[], rows: any[], resultDataJson: string[]): Promise<ArrayBuffer> => {
399399
const native = loadNative();
400400

401401
return native.getFinalCubestoreResultArray(transformDataJson, rows, resultDataJson);
402402
};
403403

404-
export const getFinalCubestoreResultMulti = (transformDataJson: string[], rows: any[], responseData: string): ArrayBuffer => {
404+
export const getFinalCubestoreResultMulti = (transformDataJson: string[], rows: any[], responseData: string): Promise<ArrayBuffer> => {
405405
const native = loadNative();
406406

407407
return native.getFinalCubestoreResultMulti(transformDataJson, rows, responseData);

0 commit comments

Comments
 (0)