Skip to content

Commit

Permalink
put native parseCubestoreResultMessage behind the flag
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Nov 20, 2024
1 parent bec28f7 commit 3f3e17d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
3 changes: 3 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ const variables: Record<string, (...args: any) => any> = {
.default('1')
.asInt(),
nativeSqlPlanner: () => get('CUBEJS_TESSERACT_SQL_PLANNER').asBool(),
nativeOrchestrator: () => get('CUBEJS_TESSERACT_ORCHESTRATOR')
.default('false')
.asBoolStrict(),

/** ****************************************************************
* Common db options *
Expand Down
59 changes: 54 additions & 5 deletions packages/cubejs-cubestore-driver/src/WebSocketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import { getEnv } from '@cubejs-backend/shared';
import { parseCubestoreResultMessage } from '@cubejs-backend/native';
import {
HttpCommand,
HttpError,
HttpMessage,
HttpQuery,
HttpResultSet,
HttpTable
} from '../codegen';

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

try {
const nativeResMsg = parseCubestoreResultMessage(msg);
resolvers.resolve(nativeResMsg);
} catch (e) {
resolvers.reject(e);
if (getEnv('nativeOrchestrator')) {
try {
const nativeResMsg = parseCubestoreResultMessage(msg);
resolvers.resolve(nativeResMsg);
} catch (e) {
resolvers.reject(e);
}
} else {
const commandType = httpMessage.commandType();

if (commandType === HttpCommand.HttpError) {
resolvers.reject(new Error(`${httpMessage.command(new HttpError())?.error()}`));
} else if (commandType === HttpCommand.HttpResultSet) {
const resultSet = httpMessage.command(new HttpResultSet());

if (!resultSet) {
resolvers.reject(new Error('Empty resultSet'));
return;
}

const columnsLen = resultSet.columnsLength();
const columns: Array<string> = [];
for (let i = 0; i < columnsLen; i++) {
const columnName = resultSet.columns(i);
if (!columnName) {
resolvers.reject(new Error('Column name is not defined'));
return;
}
columns.push(columnName);
}

const rowLen = resultSet.rowsLength();
const result: any[] = [];
for (let i = 0; i < rowLen; i++) {
const row = resultSet.rows(i);
if (!row) {
resolvers.reject(new Error('Null row'));
return;
}
const valueLen = row.valuesLength();
const rowObj = {};
for (let j = 0; j < valueLen; j++) {
const value = row.values(j);
rowObj[columns[j]] = value?.stringValue();
}
result.push(rowObj);
}

resolvers.resolve(result);
} else {
resolvers.reject(new Error('Unsupported command'));
}
}
});
});
Expand Down

0 comments on commit 3f3e17d

Please sign in to comment.