Skip to content

Commit 2b1d272

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

File tree

7 files changed

+226
-160
lines changed

7 files changed

+226
-160
lines changed

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

+10-9
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+
)).result;
1632+
return JSON.parse(jsonData) as TransformDataResponse;
1633+
}
16331634
:
1634-
() => transformData({
1635+
async () => transformData({
16351636
...transformDataParams,
16361637
data: response.data,
16371638
});
@@ -1842,7 +1843,7 @@ 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
@@ -1866,7 +1867,7 @@ 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 {
18711872
const data = results[0].dataCb();
18721873
res({
@@ -2021,7 +2022,7 @@ 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

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

+1-1
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

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/cubejs-backend-native/Cargo.toml

+1
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

+4-4
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)