Skip to content

Commit 3ef1192

Browse files
committed
put native parseCubestoreResultMessage behind the flag
1 parent cb73e0a commit 3ef1192

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed

packages/cubejs-backend-shared/src/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ const variables: Record<string, (...args: any) => any> = {
193193
.default('1')
194194
.asInt(),
195195
nativeSqlPlanner: () => get('CUBEJS_TESSERACT_SQL_PLANNER').asBool(),
196+
nativeOrchestrator: () => get('CUBEJS_TESSERACT_ORCHESTRATOR')
197+
.default('false')
198+
.asBoolStrict(),
196199

197200
/** ****************************************************************
198201
* Common db options *

packages/cubejs-cubestore-driver/src/WebSocketConnection.ts

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { getEnv } from '@cubejs-backend/shared';
66
import { parseCubestoreResultMessage } from '@cubejs-backend/native';
77
import {
88
HttpCommand,
9+
HttpError,
910
HttpMessage,
1011
HttpQuery,
12+
HttpResultSet,
1113
HttpTable
1214
} from '../codegen';
1315

@@ -116,11 +118,58 @@ export class WebSocketConnection {
116118
throw new Error(`Cube Store missed message id: ${httpMessage.messageId()}`); // logging
117119
}
118120

119-
try {
120-
const nativeResMsg = parseCubestoreResultMessage(msg);
121-
resolvers.resolve(nativeResMsg);
122-
} catch (e) {
123-
resolvers.reject(e);
121+
if (getEnv('nativeOrchestrator')) {
122+
try {
123+
const nativeResMsg = parseCubestoreResultMessage(msg);
124+
resolvers.resolve(nativeResMsg);
125+
} catch (e) {
126+
resolvers.reject(e);
127+
}
128+
} else {
129+
const commandType = httpMessage.commandType();
130+
131+
if (commandType === HttpCommand.HttpError) {
132+
resolvers.reject(new Error(`${httpMessage.command(new HttpError())?.error()}`));
133+
} else if (commandType === HttpCommand.HttpResultSet) {
134+
const resultSet = httpMessage.command(new HttpResultSet());
135+
136+
if (!resultSet) {
137+
resolvers.reject(new Error('Empty resultSet'));
138+
return;
139+
}
140+
141+
const columnsLen = resultSet.columnsLength();
142+
const columns: Array<string> = [];
143+
for (let i = 0; i < columnsLen; i++) {
144+
const columnName = resultSet.columns(i);
145+
if (!columnName) {
146+
resolvers.reject(new Error('Column name is not defined'));
147+
return;
148+
}
149+
columns.push(columnName);
150+
}
151+
152+
const rowLen = resultSet.rowsLength();
153+
const result: any[] = [];
154+
for (let i = 0; i < rowLen; i++) {
155+
const row = resultSet.rows(i);
156+
if (!row) {
157+
resolvers.reject(new Error('Null row'));
158+
return;
159+
}
160+
const valueLen = row.valuesLength();
161+
const rowObj = {};
162+
for (let j = 0; j < valueLen; j++) {
163+
const value = row.values(j);
164+
rowObj[columns[j]] = value?.stringValue();
165+
}
166+
result.push(rowObj);
167+
}
168+
169+
resolvers.resolve(result);
170+
} else {
171+
resolvers.reject(new Error('Unsupported command'));
172+
}
124173
}
125174
});
126175
});

0 commit comments

Comments
 (0)