Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(cubesql): Avoid allocations in MetaContext methods #9228

Merged
merged 11 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 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: 11 additions & 2 deletions rust/cubenativeutils/Cargo.lock

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

17 changes: 13 additions & 4 deletions rust/cubesql/Cargo.lock

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

2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sqlparser = { git = 'https://github.com/cube-js/sqlparser-rs.git', rev = "6a54d2
base64 = "0.13.0"
tokio = { version = "^1.35", features = ["full", "rt", "tracing"] }
serde = { version = "^1.0", features = ["derive"] }
itertools = "0.10.2"
itertools = "0.14.0"
serde_json = "^1.0"
bytes = "1.2"
futures = "0.3.23"
Expand Down
32 changes: 15 additions & 17 deletions rust/cubesql/cubesql/src/compile/rewrite/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1551,14 +1551,13 @@ impl LanguageToLogicalPlanConverter {
match_data_node!(node_by_id, measure_params[0], MeasureName);
let expr = self.to_expr(measure_params[1])?;
query_measures.push(measure.to_string());
let data_type = self
.cube_context
.meta
.find_df_data_type(measure.to_string())
.ok_or(CubeError::internal(format!(
"Can't find measure '{}'",
measure
)))?;
let data_type =
self.cube_context.meta.find_df_data_type(&measure).ok_or(
CubeError::internal(format!(
"Can't find measure '{}'",
measure
)),
)?;
fields.push((
DFField::new(
expr_relation(&expr),
Expand Down Expand Up @@ -1608,14 +1607,13 @@ impl LanguageToLogicalPlanConverter {
LogicalPlanLanguage::Dimension(params) => {
let dimension = match_data_node!(node_by_id, params[0], DimensionName);
let expr = self.to_expr(params[1])?;
let data_type = self
.cube_context
.meta
.find_df_data_type(dimension.to_string())
.ok_or(CubeError::internal(format!(
"Can't find dimension '{}'",
dimension
)))?;
let data_type =
self.cube_context.meta.find_df_data_type(&dimension).ok_or(
CubeError::internal(format!(
"Can't find dimension '{}'",
dimension
)),
)?;
query_dimensions.push(dimension.to_string());
fields.push((
DFField::new(
Expand Down Expand Up @@ -1705,7 +1703,7 @@ impl LanguageToLogicalPlanConverter {
if self
.cube_context
.meta
.is_synthetic_field(column.member_name().to_string())
.is_synthetic_field(column.member_name())
{
fields.push((
DFField::new(
Expand Down
2 changes: 1 addition & 1 deletion rust/cubesql/cubesql/src/compile/rewrite/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl BestCubePlan {

let time_dimensions_used_as_dimensions = match enode {
LogicalPlanLanguage::DimensionName(DimensionName(name)) => {
if let Some(dimension) = self.meta_context.find_dimension_with_name(name.clone()) {
if let Some(dimension) = self.meta_context.find_dimension_with_name(name) {
if dimension.is_time() {
1
} else {
Expand Down
12 changes: 6 additions & 6 deletions rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3730,15 +3730,15 @@
}
}

fn filter_member_name(
fn filter_member_name<'meta>(
egraph: &mut CubeEGraph,
subst: &Subst,
meta_context: &Arc<MetaContext>,
meta_context: &'meta MetaContext,
alias_to_cube_var: Var,
column_var: Var,
members_var: Var,
aliases: &Vec<(String, String)>,
) -> Option<(String, V1CubeMeta)> {
) -> Option<(String, &'meta V1CubeMeta)> {
Self::filter_member_name_with_granularity(
egraph,
subst,
Expand All @@ -3751,15 +3751,15 @@
.map(|(name, _, meta)| (name, meta))
}

fn filter_member_name_with_granularity(
fn filter_member_name_with_granularity<'meta>(
egraph: &mut CubeEGraph,
subst: &Subst,
meta_context: &Arc<MetaContext>,
meta_context: &'meta MetaContext,
alias_to_cube_var: Var,
column_var: Var,
members_var: Var,
aliases: &Vec<(String, String)>,
) -> Option<(String, Option<String>, V1CubeMeta)> {
) -> Option<(String, Option<String>, &'meta V1CubeMeta)> {
let alias_to_cubes: Vec<_> =
var_iter!(egraph[subst[alias_to_cube_var]], FilterReplacerAliasToCube)
.cloned()
Expand Down Expand Up @@ -4836,7 +4836,7 @@
};
let ts_seconds = *ts / 1_000_000_000;
let ts_nanos = (*ts % 1_000_000_000) as u32;
let dt = NaiveDateTime::from_timestamp_opt(ts_seconds, ts_nanos).map(|dt| Some(dt));

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / build

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / unit (22.x, 3.11, false, true)

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / unit (20.x, 3.11, false, true)

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / unit (22.x, 3.11, false, false)

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / unit (20.x, 3.11, false, false)

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / unit (22.x, 3.11, true, false)

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead

Check warning on line 4839 in rust/cubesql/cubesql/src/compile/rewrite/rules/filters.rs

View workflow job for this annotation

GitHub Actions / unit (20.x, 3.11, true, false)

use of deprecated associated function `chrono::NaiveDateTime::from_timestamp_opt`: use `DateTime::from_timestamp` instead
return dt;
};

Expand Down
6 changes: 3 additions & 3 deletions rust/cubesql/cubesql/src/compile/rewrite/rules/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2166,7 +2166,7 @@
.cloned()
{
if let Some(measure) =
meta_context.find_measure_with_name(measure_name.to_string())
meta_context.find_measure_with_name(&measure_name)
{
let measure_cube_name = measure_name.split(".").next().unwrap();
if let Some(((_, cube_alias), _)) = alias_to_cube
Expand Down Expand Up @@ -2205,7 +2205,7 @@
}

if let Some(dimension) =
meta_context.find_dimension_with_name(measure_name.to_string())
meta_context.find_dimension_with_name(&measure_name)
{
let alias_to_cube = alias_to_cube.clone();
subst.insert(
Expand Down Expand Up @@ -2309,7 +2309,7 @@
call_agg_type,
alias,
measure_out_var,
cube_alias,
cube_alias.to_string(),

Check warning on line 2312 in rust/cubesql/cubesql/src/compile/rewrite/rules/members.rs

View check run for this annotation

Codecov / codecov/patch

rust/cubesql/cubesql/src/compile/rewrite/rules/members.rs#L2312

Added line #L2312 was not covered by tests
subst[aggr_expr_var],
alias_to_cube,
disable_strict_agg_type_match,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4922,7 +4922,7 @@
// TODO unwrap
let name = expr.name(&DFSchema::empty()).unwrap();
let column1 = Column {
relation: Some(alias),
relation: Some(alias.to_string()),

Check warning on line 4925 in rust/cubesql/cubesql/src/compile/rewrite/rules/old_split.rs

View check run for this annotation

Codecov / codecov/patch

rust/cubesql/cubesql/src/compile/rewrite/rules/old_split.rs#L4925

Added line #L4925 was not covered by tests
name: name.to_string(),
};
let alias = egraph.add(LogicalPlanLanguage::ColumnExprColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,7 @@ impl WrapperRules {
&column.name,
)
{
if let Some(measure) =
meta.find_measure_with_name(member.to_string())
{
if let Some(measure) = meta.find_measure_with_name(member) {
if call_agg_type.is_none()
|| measure.is_same_agg_type(
call_agg_type.as_ref().unwrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl WrapperRules {
.data
.find_member_by_alias(&column.name)
{
if let Some(measure) = meta.find_measure_with_name(member.to_string()) {
if let Some(measure) = meta.find_measure_with_name(member) {
if measure.agg_type != Some("number".to_string()) {
return true;
}
Expand Down
Loading
Loading