Skip to content

Commit 3d58fb5

Browse files
committed
in work
1 parent 2b4b702 commit 3d58fb5

File tree

10 files changed

+458
-182
lines changed

10 files changed

+458
-182
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ export class BaseQuery {
996996
ungrouped: this.options.ungrouped,
997997
exportAnnotatedSql: false,
998998
preAggregationQuery: this.options.preAggregationQuery,
999+
securityContext: this.contextSymbols.securityContext,
9991000
cubestoreSupportMultistage: this.options.cubestoreSupportMultistage ?? getEnv('cubeStoreRollingWindowJoin'),
10001001
disableExternalPreAggregations: !!this.options.disableExternalPreAggregations,
10011002
};

packages/cubejs-schema-compiler/test/integration/postgres/sql-generation.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ describe('SQL Generation', () => {
665665
cube('ReferenceVisitors', {
666666
sql: \`
667667
select * from \${visitors.sql()} as t
668+
WHERE \${FILTER_PARAMS.ReferenceVisitors.createdAt.filter(\`(t.created_at + interval '28 day')\`)} AND
669+
\${FILTER_PARAMS.ReferenceVisitors.createdAt.filter((from, to) => \`(t.created_at + interval '28 day') >= \${from} AND (t.created_at + interval '28 day') <= \${to}\`)}
668670
\`,
669671
670672
measures: {
@@ -3112,7 +3114,7 @@ SELECT 1 AS revenue, cast('2024-01-01' AS timestamp) as time UNION ALL
31123114
);
31133115
});
31143116

3115-
it('security context 1', async () => {
3117+
it('security context', async () => {
31163118
await compiler.compile();
31173119

31183120
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {

rust/cubenativeutils/src/wrappers/serializer/deserializer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ impl<'de, IT: InnerTypes> Deserializer<'de> for NativeSerdeDeserializer<IT> {
4949
let deserializer = NativeMapDeserializer::<IT>::new(val)?;
5050
visitor.visit_map(deserializer)
5151
} else {
52-
panic!("des");
5352
Err(NativeObjSerializerError::Message(
5453
"deserializer is not implemented".to_string(),
5554
))
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use cubenativeutils::wrappers::serializer::{
2+
NativeDeserialize, NativeDeserializer, NativeSerialize,
3+
};
4+
use cubenativeutils::wrappers::{inner_types::InnerTypes, NativeString};
5+
use cubenativeutils::wrappers::{NativeContextHolder, NativeFunction};
6+
use cubenativeutils::wrappers::{NativeContextHolderRef, NativeObjectHandle};
7+
use cubenativeutils::CubeError;
8+
use std::any::Any;
9+
use std::rc::Rc;
10+
11+
pub trait FilterParamsCallback {
12+
fn call(&self, filter_params: &Vec<String>) -> Result<String, CubeError>;
13+
fn as_any(self: Rc<Self>) -> Rc<dyn Any>;
14+
fn clone_to_context(
15+
&self,
16+
context_ref: &dyn NativeContextHolderRef,
17+
) -> Result<Rc<dyn FilterParamsCallback>, CubeError>;
18+
}
19+
20+
#[derive(Clone)]
21+
pub struct NativeFilterParamsCallback<IT: InnerTypes> {
22+
native_object: NativeObjectHandle<IT>,
23+
}
24+
25+
impl<IT: InnerTypes> NativeFilterParamsCallback<IT> {
26+
pub fn new(native_object: NativeObjectHandle<IT>) -> Self {
27+
Self { native_object }
28+
}
29+
}
30+
31+
impl<IT: InnerTypes> FilterParamsCallback for NativeFilterParamsCallback<IT> {
32+
fn call(&self, filter_params: &Vec<String>) -> Result<String, CubeError> {
33+
let func = self.native_object.to_function()?;
34+
let context = NativeContextHolder::<IT>::new(self.native_object.get_context());
35+
let args = filter_params
36+
.iter()
37+
.map(|param| param.to_native(context.clone()))
38+
.collect::<Result<Vec<_>, _>>()?;
39+
let res = func.call(args)?;
40+
String::from_native(res).map_err(|_| {
41+
CubeError::user("Callback for FILTER_PARAMS should return string".to_string())
42+
})
43+
}
44+
45+
fn as_any(self: Rc<Self>) -> Rc<dyn Any> {
46+
self
47+
}
48+
fn clone_to_context(
49+
&self,
50+
context_ref: &dyn NativeContextHolderRef,
51+
) -> Result<Rc<dyn FilterParamsCallback>, CubeError> {
52+
Ok(Rc::new(Self {
53+
native_object: self.native_object.try_clone_to_context_ref(context_ref)?,
54+
}))
55+
}
56+
}
57+
58+
impl<IT: InnerTypes> NativeSerialize<IT> for NativeFilterParamsCallback<IT> {
59+
fn to_native(
60+
&self,
61+
_context: NativeContextHolder<IT>,
62+
) -> Result<NativeObjectHandle<IT>, CubeError> {
63+
Ok(self.native_object.clone())
64+
}
65+
}
66+
impl<IT: InnerTypes> NativeDeserialize<IT> for NativeFilterParamsCallback<IT> {
67+
fn from_native(native_object: NativeObjectHandle<IT>) -> Result<Self, CubeError> {
68+
Ok(Self::new(native_object))
69+
}
70+
}
71+
72+
impl<IT: InnerTypes> std::fmt::Debug for NativeFilterParamsCallback<IT> {
73+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74+
write!(f, "NativeFilterParamsCallback")
75+
}
76+
}

0 commit comments

Comments
 (0)