Skip to content

Commit b8d7507

Browse files
committed
make all native cubestore_result_transform functions async
1 parent 696a125 commit b8d7507

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
@@ -1590,7 +1590,7 @@ class ApiGateway {
15901590
* result object.
15911591
* @internal
15921592
*/
1593-
private getResultInternal(
1593+
private async getResultInternal(
15941594
context: RequestContext,
15951595
queryType: QueryType,
15961596
normalizedQuery: NormalizedQuery,
@@ -1627,13 +1627,14 @@ class ApiGateway {
16271627
// We postpone data transformation until the last minute
16281628
// in case when all responses are native - we process them in native part
16291629
const dataCb: TransformDataResponseCb = response.data.isNative ?
1630-
() => JSON.parse(
1631-
transformDataNative(
1630+
async () => {
1631+
const jsonData = await transformDataNative(
16321632
JSON.stringify(transformDataParams), response.data.getNativeRef()
1633-
).result
1634-
) as TransformDataResponse
1633+
);
1634+
return JSON.parse(jsonData.result) as TransformDataResponse;
1635+
}
16351636
:
1636-
() => transformData({
1637+
async () => transformData({
16371638
...transformDataParams,
16381639
data: response.data,
16391640
});
@@ -1844,20 +1845,20 @@ class ApiGateway {
18441845
};
18451846
const resultDataJson = JSON.stringify(responseDataObj);
18461847

1847-
res(getFinalCubestoreResultMulti(transformDataJson, rawDataRef, resultDataJson));
1848+
res(await getFinalCubestoreResultMulti(transformDataJson, rawDataRef, resultDataJson));
18481849
} else {
18491850
// if we have mixed query results (there are js and native)
18501851
// we prepare results separately: on js and native sides
18511852
// and serve final response from JS side
18521853
res({
18531854
queryType,
1854-
results: results.map(r => {
1855-
const data = r.dataCb();
1855+
results: await Promise.all(results.map(async (r) => {
1856+
const data = await r.dataCb();
18561857
return {
18571858
...cleanupResult(r),
18581859
data,
18591860
};
1860-
}),
1861+
})),
18611862
pivotQuery: getPivotQuery(queryType, normalizedQueries),
18621863
slowQuery
18631864
});
@@ -1868,9 +1869,9 @@ class ApiGateway {
18681869
const transformDataJson = JSON.stringify(r.transformDataParams);
18691870
const rawDataRef = r.rawData.getNativeRef();
18701871
const resultDataJson = JSON.stringify(cleanupResult(r));
1871-
res(getFinalCubestoreResult(transformDataJson, rawDataRef, resultDataJson));
1872+
res(await getFinalCubestoreResult(transformDataJson, rawDataRef, resultDataJson));
18721873
} else {
1873-
const data = results[0].dataCb();
1874+
const data = await results[0].dataCb();
18741875
res({
18751876
...cleanupResult(results[0]),
18761877
data,
@@ -2023,19 +2024,19 @@ class ApiGateway {
20232024
[[], [], []]
20242025
);
20252026

2026-
res(getFinalCubestoreResultArray(transformDataJson, rawDataRef, resultDataJson));
2027+
res(await getFinalCubestoreResultArray(transformDataJson, rawDataRef, resultDataJson));
20272028
} else {
20282029
// if we have mixed query results (there are js and native)
20292030
// we prepare results separately: on js and native sides
20302031
// and serve final response from JS side
20312032
res({
2032-
results: results.map(r => {
2033-
const data = r.dataCb();
2033+
results: await Promise.all(results.map(async (r) => {
2034+
const data = await r.dataCb();
20342035
return {
20352036
...cleanupResult(r),
20362037
data,
20372038
};
2038-
}),
2039+
})),
20392040
});
20402041
}
20412042
} 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)