Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/cubejs-backend-native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions packages/cubejs-backend-native/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,7 @@ export const sql4sql = async (instance: SqlInterfaceInstance, sqlQuery: string,

export const buildSqlAndParams = (cubeEvaluator: any): String => {
const native = loadNative();
const safeCallFn = (fn: Function, thisArg: any, ...args: any[]) => {
try {
return {
result: fn.apply(thisArg, args),
};
} catch (e: any) {
return {
error: e.toString(),
};
}
};
return native.buildSqlAndParams(cubeEvaluator, safeCallFn);
return native.buildSqlAndParams(cubeEvaluator);
};

export type ResultRow = Record<string, string>;
Expand Down
49 changes: 9 additions & 40 deletions packages/cubejs-backend-native/src/node_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ use crate::stream::OnDrainHandler;
use crate::tokio_runtime_node;
use crate::transport::NodeBridgeTransport;
use crate::utils::{batch_to_rows, NonDebugInRelease};
use cubenativeutils::wrappers::neon::context::neon_run_with_guarded_lifetime;
use cubenativeutils::wrappers::neon::context::neon_guarded_funcion_call;
use cubenativeutils::wrappers::neon::inner_types::NeonInnerTypes;
use cubenativeutils::wrappers::neon::object::NeonObject;
use cubenativeutils::wrappers::object_handle::NativeObjectHandle;
use cubenativeutils::wrappers::serializer::NativeDeserialize;
use cubenativeutils::wrappers::NativeContextHolder;
use cubesqlplanner::cube_bridge::base_query_options::NativeBaseQueryOptions;
use cubesqlplanner::planner::base_query::BaseQuery;
Expand Down Expand Up @@ -603,43 +600,15 @@ pub fn reset_logger(mut cx: FunctionContext) -> JsResult<JsUndefined> {
//============ sql planner ===================

fn build_sql_and_params(cx: FunctionContext) -> JsResult<JsValue> {
neon_run_with_guarded_lifetime(cx, |neon_context_holder| {
let options = NativeObjectHandle::<NeonInnerTypes<FunctionContext<'static>>>::new(
NeonObject::new(
neon_context_holder.clone(),
neon_context_holder
.with_context(|cx| cx.argument::<JsValue>(0))
.unwrap()?,
)
.unwrap(),
);

let safe_call_fn = neon_context_holder
.with_context(|cx| {
if let Ok(func) = cx.argument::<JsFunction>(1) {
Some(func)
} else {
None
}
})
.unwrap();

neon_context_holder.set_safe_call_fn(safe_call_fn).unwrap();

let context_holder = NativeContextHolder::<NeonInnerTypes<FunctionContext<'static>>>::new(
neon_context_holder,
);

let base_query_options = Rc::new(NativeBaseQueryOptions::from_native(options).unwrap());
neon_guarded_funcion_call(
cx,
|context_holder: NativeContextHolder<_>,
options: NativeBaseQueryOptions<NeonInnerTypes<FunctionContext<'static>>>| {
let base_query = BaseQuery::try_new(context_holder.clone(), Rc::new(options))?;

let base_query = BaseQuery::try_new(context_holder.clone(), base_query_options).unwrap();

let res = base_query.build_sql_and_params();

let result: NeonObject<FunctionContext<'static>> = res.into_object();
let result = result.get_object().unwrap();
Ok(result)
})
base_query.build_sql_and_params()
},
)
}

fn debug_js_to_clrepr_to_js(mut cx: FunctionContext) -> JsResult<JsValue> {
Expand Down
27 changes: 12 additions & 15 deletions packages/cubejs-schema-compiler/src/adapter/BaseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,24 +900,21 @@ export class BaseQuery {
cubestoreSupportMultistage: this.options.cubestoreSupportMultistage ?? getEnv('cubeStoreRollingWindowJoin')
};

const buildResult = nativeBuildSqlAndParams(queryParams);
try {
const buildResult = nativeBuildSqlAndParams(queryParams);

if (buildResult.error) {
if (buildResult.error.cause && buildResult.error.cause === 'User') {
throw new UserError(buildResult.error.message);
} else {
throw new Error(buildResult.error.message);
const [query, params, preAggregation] = buildResult;
const paramsArray = [...params];
if (preAggregation) {
this.preAggregations.preAggregationForQuery = preAggregation;
}
return [query, paramsArray];
} catch (e) {
if (e.name === 'TesseractUserError') {
throw new UserError(e.message);
}
throw e;
}

const res = buildResult.result;
const [query, params, preAggregation] = res;
// FIXME
const paramsArray = [...params];
if (preAggregation) {
this.preAggregations.preAggregationForQuery = preAggregation;
}
return [query, paramsArray];
}

// FIXME Temporary solution
Expand Down
1 change: 1 addition & 0 deletions rust/cubenativeutils/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ node_modules
/cubesql/egraph-debug-intermediate
egraph-debug
/cubesql/debug-qtrace
CLAUDE.md
Loading
Loading