Skip to content

Commit a50f0ad

Browse files
committed
11 tests left
1 parent df31e89 commit a50f0ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+666
-322
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,12 @@ impl<IT: InnerTypes> ser::Serializer for NativeSerdeSerializer<IT> {
184184
_name: &'static str,
185185
_variant_index: u32,
186186
_variant: &'static str,
187-
_value: &T,
187+
value: &T,
188188
) -> Result<Self::Ok, Self::Error>
189189
where
190190
T: ?Sized + Serialize,
191191
{
192-
Err(NativeObjSerializerError::Message(
193-
"serialize_newtype_variant is not implemented".to_string(),
194-
))
192+
NativeSerdeSerializer::serialize(value, self.context.clone())
195193
}
196194

197195
fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {

rust/cubesqlplanner/\

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use crate::cube_bridge::join_hints::JoinHintItem;
2+
use crate::planner::sql_evaluator::{MemberSymbol, TraversalVisitor};
3+
use crate::planner::BaseMeasure;
4+
use cubenativeutils::CubeError;
5+
use std::rc::Rc;
6+
7+
pub struct JoinHintsCollector {
8+
hints: Vec<JoinHintItem>,
9+
}
10+
11+
impl JoinHintsCollector {
12+
pub fn new() -> Self {
13+
Self { hints: Vec::new() }
14+
}
15+
16+
pub fn extract_result(self) -> Vec<JoinHintItem> {
17+
self.hints
18+
}
19+
}
20+
21+
impl TraversalVisitor for JoinHintsCollector {
22+
type State = ();
23+
fn on_node_traverse(
24+
&mut self,
25+
node: &Rc<MemberSymbol>,
26+
path: &Vec<String>,
27+
_: &Self::State,
28+
) -> Result<Option<Self::State>, CubeError> {
29+
match node.as_ref() {
30+
MemberSymbol::Dimension(e) => {
31+
if e.owned_by_cube() {
32+
if !path.is_empty() {
33+
if path.len() == 1 {
34+
self.hints.push(JoinHintItem::Single(path[0].clone()))
35+
} else {
36+
self.hints.push(JoinHintItem::Vector(path.clone()))
37+
}
38+
}
39+
}
40+
if e.is_sub_query() {
41+
return Ok(None);
42+
}
43+
}
44+
MemberSymbol::TimeDimension(e) => return self.on_node_traverse(e.base_symbol(), path, &()),
45+
MemberSymbol::Measure(e) => {
46+
if e.owned_by_cube() {
47+
self.hints.push(JoinHintItem::Single(e.cube_name().clone()));
48+
}
49+
for name in e.get_dependent_cubes().into_iter() {
50+
self.hints.push(JoinHintItem::Single(name));
51+
}
52+
}
53+
MemberSymbol::CubeName(e) => {
54+
self.hints.push(JoinHintItem::Single(e.cube_name().clone()));
55+
}
56+
MemberSymbol::CubeTable(e) => {
57+
self.hints.push(JoinHintItem::Single(e.cube_name().clone()));
58+
}
59+
MemberSymbol::SqlCall(s) => {
60+
for name in s.get_dependent_cubes().into_iter() {
61+
self.hints.push(JoinHintItem::Single(name));
62+
}
63+
}
64+
};
65+
Ok(Some(()))
66+
}
67+
}
68+
69+
pub fn collect_join_hints(node: &Rc<MemberSymbol>) -> Result<Vec<JoinHintItem>, CubeError> {
70+
let mut visitor = JoinHintsCollector::new();
71+
visitor.apply(node, &())?;
72+
let res = visitor.extract_result();
73+
Ok(res)
74+
}
75+
76+
pub fn collect_join_hints_for_measures(
77+
measures: &Vec<Rc<BaseMeasure>>,
78+
) -> Result<Vec<JoinHintItem>, CubeError> {
79+
let mut visitor = JoinHintsCollector::new();
80+
for meas in measures.iter() {
81+
visitor.apply(&meas.member_evaluator(), &())?;
82+
}
83+
let res = visitor.extract_result();
84+
Ok(res)
85+
}

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/base_query_options.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use super::join_graph::{JoinGraph, NativeJoinGraph};
2+
use super::options_member::OptionsMember;
23
use crate::cube_bridge::base_tools::{BaseTools, NativeBaseTools};
34
use crate::cube_bridge::evaluator::{CubeEvaluator, NativeCubeEvaluator};
45
use cubenativeutils::wrappers::serializer::{
56
NativeDeserialize, NativeDeserializer, NativeSerialize,
67
};
7-
use cubenativeutils::wrappers::NativeContextHolder;
8-
use cubenativeutils::wrappers::NativeObjectHandle;
8+
use cubenativeutils::wrappers::{NativeArray, NativeContextHolder, NativeObjectHandle};
99
use cubenativeutils::CubeError;
1010
use serde::{Deserialize, Serialize};
1111
use std::any::Any;
@@ -50,7 +50,6 @@ impl FilterItem {
5050
#[derive(Serialize, Deserialize, Debug)]
5151
pub struct BaseQueryOptionsStatic {
5252
pub measures: Option<Vec<String>>,
53-
pub dimensions: Option<Vec<String>>,
5453
#[serde(rename = "timeDimensions")]
5554
pub time_dimensions: Option<Vec<TimeDimension>>,
5655
pub timezone: Option<String>,
@@ -66,9 +65,13 @@ pub struct BaseQueryOptionsStatic {
6665
#[nativebridge::native_bridge(BaseQueryOptionsStatic)]
6766
pub trait BaseQueryOptions {
6867
#[field]
69-
fn measures(&self) -> Result<Option<Vec<String>>, CubeError>;
68+
#[optional]
69+
#[vec]
70+
fn measures(&self) -> Result<Option<Vec<OptionsMember>>, CubeError>;
7071
#[field]
71-
fn dimensions(&self) -> Result<Option<Vec<String>>, CubeError>;
72+
#[optional]
73+
#[vec]
74+
fn dimensions(&self) -> Result<Option<Vec<OptionsMember>>, CubeError>;
7275
#[field]
7376
fn cube_evaluator(&self) -> Result<Rc<dyn CubeEvaluator>, CubeError>;
7477
#[field]

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/join_definition.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use super::join_item::{JoinItemsVec, NativeJoinItemsVec};
1+
use super::join_item::{JoinItem, NativeJoinItem};
22
use cubenativeutils::wrappers::serializer::{
33
NativeDeserialize, NativeDeserializer, NativeSerialize,
44
};
5+
use cubenativeutils::wrappers::NativeArray;
56
use cubenativeutils::wrappers::NativeContextHolder;
67
use cubenativeutils::wrappers::NativeObjectHandle;
78
use cubenativeutils::CubeError;
@@ -20,5 +21,6 @@ pub struct JoinDefinitionStatic {
2021
#[nativebridge::native_bridge(JoinDefinitionStatic)]
2122
pub trait JoinDefinition {
2223
#[field]
23-
fn joins(&self) -> Result<Rc<dyn JoinItemsVec>, CubeError>;
24+
#[vec]
25+
fn joins(&self) -> Result<Vec<Rc<dyn JoinItem>>, CubeError>;
2426
}

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/join_graph.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::join_definition::{JoinDefinition, NativeJoinDefinition};
2+
use super::join_hints::JoinHintItem;
23
use cubenativeutils::wrappers::serializer::{
34
NativeDeserialize, NativeDeserializer, NativeSerialize,
45
};
@@ -10,5 +11,8 @@ use std::rc::Rc;
1011

1112
#[nativebridge::native_bridge]
1213
pub trait JoinGraph {
13-
fn build_join(&self, cubes_to_join: Vec<String>) -> Result<Rc<dyn JoinDefinition>, CubeError>;
14+
fn build_join(
15+
&self,
16+
cubes_to_join: Vec<JoinHintItem>,
17+
) -> Result<Rc<dyn JoinDefinition>, CubeError>;
1418
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
4+
pub enum JoinHintItem {
5+
Single(String),
6+
Vector(Vec<String>),
7+
}
Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use super::join_item_definition::{JoinItemDefinition, NativeJoinItemDefinition};
2-
use cubenativeutils::wrappers::object::NativeArray;
32
use cubenativeutils::wrappers::serializer::{
43
NativeDeserialize, NativeDeserializer, NativeSerialize,
54
};
@@ -8,7 +7,6 @@ use cubenativeutils::wrappers::NativeObjectHandle;
87
use cubenativeutils::CubeError;
98
use serde::{Deserialize, Serialize};
109
use std::any::Any;
11-
use std::marker::PhantomData;
1210
use std::rc::Rc;
1311

1412
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq, Hash)]
@@ -26,41 +24,3 @@ pub trait JoinItem {
2624
#[field]
2725
fn join(&self) -> Result<Rc<dyn JoinItemDefinition>, CubeError>;
2826
}
29-
30-
pub trait JoinItemsVec {
31-
fn items(&self) -> &Vec<Rc<dyn JoinItem>>;
32-
}
33-
34-
pub struct NativeJoinItemsVec<IT: InnerTypes> {
35-
items: Vec<Rc<dyn JoinItem>>,
36-
phantom: PhantomData<IT>,
37-
}
38-
39-
impl<IT: InnerTypes> NativeJoinItemsVec<IT> {
40-
pub fn try_new(native_items: NativeObjectHandle<IT>) -> Result<Self, CubeError> {
41-
let items = native_items
42-
.into_array()?
43-
.to_vec()?
44-
.into_iter()
45-
.map(|v| -> Result<Rc<dyn JoinItem>, CubeError> {
46-
Ok(Rc::new(NativeJoinItem::from_native(v)?))
47-
})
48-
.collect::<Result<Vec<_>, _>>()?;
49-
Ok(Self {
50-
items,
51-
phantom: PhantomData::default(),
52-
})
53-
}
54-
}
55-
56-
impl<IT: InnerTypes> JoinItemsVec for NativeJoinItemsVec<IT> {
57-
fn items(&self) -> &Vec<Rc<dyn JoinItem>> {
58-
&self.items
59-
}
60-
}
61-
62-
impl<IT: InnerTypes> NativeDeserialize<IT> for NativeJoinItemsVec<IT> {
63-
fn from_native(v: NativeObjectHandle<IT>) -> Result<Self, CubeError> {
64-
Self::try_new(v)
65-
}
66-
}

rust/cubesqlplanner/cubesqlplanner/src/cube_bridge/measure_definition.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use super::cube_definition::{CubeDefinition, NativeCubeDefinition};
2-
use super::measure_filter::{MeasureFiltersVec, NativeMeasureFiltersVec};
3-
use super::member_order_by::{MemberOrderByVec, NativeMemberOrderByVec};
2+
use super::measure_filter::{MeasureFilter, NativeMeasureFilter};
3+
use super::member_order_by::{MemberOrderBy, NativeMemberOrderBy};
44
use super::member_sql::{MemberSql, NativeMemberSql};
55
use cubenativeutils::wrappers::serializer::{
66
NativeDeserialize, NativeDeserializer, NativeSerialize,
77
};
8+
use cubenativeutils::wrappers::NativeArray;
89
use cubenativeutils::wrappers::NativeContextHolder;
910
use cubenativeutils::wrappers::NativeObjectHandle;
1011
use cubenativeutils::CubeError;
@@ -61,13 +62,16 @@ pub trait MeasureDefinition {
6162

6263
#[optional]
6364
#[field]
64-
fn filters(&self) -> Result<Option<Rc<dyn MeasureFiltersVec>>, CubeError>;
65+
#[vec]
66+
fn filters(&self) -> Result<Option<Vec<Rc<dyn MeasureFilter>>>, CubeError>;
6567

6668
#[optional]
6769
#[field]
68-
fn drill_filters(&self) -> Result<Option<Rc<dyn MeasureFiltersVec>>, CubeError>;
70+
#[vec]
71+
fn drill_filters(&self) -> Result<Option<Vec<Rc<dyn MeasureFilter>>>, CubeError>;
6972

7073
#[optional]
7174
#[field]
72-
fn order_by(&self) -> Result<Option<Rc<dyn MemberOrderByVec>>, CubeError>;
75+
#[vec]
76+
fn order_by(&self) -> Result<Option<Vec<Rc<dyn MemberOrderBy>>>, CubeError>;
7377
}
Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,15 @@
11
use super::member_sql::{MemberSql, NativeMemberSql};
2-
use cubenativeutils::wrappers::object::NativeArray;
32
use cubenativeutils::wrappers::serializer::{
43
NativeDeserialize, NativeDeserializer, NativeSerialize,
54
};
65
use cubenativeutils::wrappers::NativeContextHolder;
76
use cubenativeutils::wrappers::NativeObjectHandle;
87
use cubenativeutils::CubeError;
98
use std::any::Any;
10-
use std::marker::PhantomData;
119
use std::rc::Rc;
1210

1311
#[nativebridge::native_bridge]
1412
pub trait MeasureFilter {
1513
#[field]
1614
fn sql(&self) -> Result<Rc<dyn MemberSql>, CubeError>;
1715
}
18-
19-
pub trait MeasureFiltersVec {
20-
fn items(&self) -> &Vec<Rc<dyn MeasureFilter>>;
21-
}
22-
23-
pub struct NativeMeasureFiltersVec<IT: InnerTypes> {
24-
items: Vec<Rc<dyn MeasureFilter>>,
25-
phantom: PhantomData<IT>,
26-
}
27-
28-
impl<IT: InnerTypes> NativeMeasureFiltersVec<IT> {
29-
pub fn try_new(native_items: NativeObjectHandle<IT>) -> Result<Self, CubeError> {
30-
let items = native_items
31-
.into_array()?
32-
.to_vec()?
33-
.into_iter()
34-
.map(|v| -> Result<Rc<dyn MeasureFilter>, CubeError> {
35-
Ok(Rc::new(NativeMeasureFilter::from_native(v)?))
36-
})
37-
.collect::<Result<Vec<_>, _>>()?;
38-
Ok(Self {
39-
items,
40-
phantom: PhantomData::default(),
41-
})
42-
}
43-
}
44-
45-
impl<IT: InnerTypes> MeasureFiltersVec for NativeMeasureFiltersVec<IT> {
46-
fn items(&self) -> &Vec<Rc<dyn MeasureFilter>> {
47-
&self.items
48-
}
49-
}
50-
51-
impl<IT: InnerTypes> NativeDeserialize<IT> for NativeMeasureFiltersVec<IT> {
52-
fn from_native(v: NativeObjectHandle<IT>) -> Result<Self, CubeError> {
53-
Self::try_new(v)
54-
}
55-
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use super::member_sql::{MemberSql, NativeMemberSql};
2+
use cubenativeutils::wrappers::serializer::{
3+
NativeDeserialize, NativeDeserializer, NativeSerialize,
4+
};
5+
use cubenativeutils::wrappers::{NativeContextHolder, NativeObjectHandle};
6+
use cubenativeutils::CubeError;
7+
use serde::{Deserialize, Serialize};
8+
use std::any::Any;
9+
use std::rc::Rc;
10+
11+
#[derive(Serialize, Deserialize, Debug, Clone)]
12+
pub struct MemberExpressionDefinitionStatic {
13+
#[serde(rename = "expressionName")]
14+
pub expression_name: Option<String>,
15+
#[serde(rename = "cubeName")]
16+
pub cube_name: Option<String>,
17+
pub definition: Option<String>,
18+
}
19+
20+
#[nativebridge::native_bridge(MemberExpressionDefinitionStatic)]
21+
pub trait MemberExpressionDefinition {
22+
#[field]
23+
fn expression(&self) -> Result<Rc<dyn MemberSql>, CubeError>;
24+
}

0 commit comments

Comments
 (0)