-
Notifications
You must be signed in to change notification settings - Fork 613
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
feat(frontend): add InternalStateTable Catalog #3139
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4607610
use TableMessage for internal table
WindowsXp-Beta 6efee84
fix risedev check
WindowsXp-Beta 434544c
update planner test
WindowsXp-Beta f1cbf21
fix unit test
WindowsXp-Beta 55dabd9
fix misc check
WindowsXp-Beta 5923002
Merge remote-tracking branch 'upstream/main' into WindowsXp/store-sta…
WindowsXp-Beta eb466ec
fix ci
WindowsXp-Beta ce0089f
Merge remote-tracking branch 'upstream/main' into WindowsXp/store-sta…
WindowsXp-Beta 2e2911a
fix issues in PR comments
WindowsXp-Beta 303d1e5
Merge remote-tracking branch 'upstream/main' into WindowsXp/store-sta…
WindowsXp-Beta d4165e7
fix clippy
WindowsXp-Beta a14b31e
Merge remote-tracking branch 'upstream/main' into WindowsXp/store-sta…
WindowsXp-Beta d67565b
fix ci
WindowsXp-Beta e439ccb
update planner test
WindowsXp-Beta a72f976
replace clone with as_ref
WindowsXp-Beta 2a3f220
Merge remote-tracking branch 'upstream/main' into WindowsXp/store-sta…
WindowsXp-Beta a7d7b66
remove table_id in proto
WindowsXp-Beta 2c39ebc
Merge remote-tracking branch 'upstream/main' into WindowsXp/store-sta…
WindowsXp-Beta 23dc3c9
rename to column_mapping
WindowsXp-Beta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,16 +17,19 @@ use std::fmt; | |
|
||
use fixedbitset::FixedBitSet; | ||
use itertools::Itertools; | ||
use risingwave_common::catalog::{Field, Schema}; | ||
use risingwave_common::catalog::{ColumnDesc, ColumnId, Field, OrderedColumnDesc, Schema, TableId}; | ||
use risingwave_common::error::{ErrorCode, Result}; | ||
use risingwave_common::types::DataType; | ||
use risingwave_common::util::sort_util::OrderType; | ||
use risingwave_expr::expr::AggKind; | ||
use risingwave_pb::expr::AggCall as ProstAggCall; | ||
|
||
use super::{ | ||
BatchHashAgg, BatchSimpleAgg, ColPrunable, PlanBase, PlanRef, PlanTreeNodeUnary, | ||
PredicatePushdown, StreamHashAgg, StreamSimpleAgg, ToBatch, ToStream, | ||
}; | ||
use crate::catalog::column_catalog::ColumnCatalog; | ||
use crate::catalog::table_catalog::TableCatalog; | ||
use crate::expr::{AggCall, Expr, ExprImpl, ExprRewriter, ExprType, FunctionCall, InputRef}; | ||
use crate::optimizer::plan_node::{gen_filter_and_pushdown, LogicalProject}; | ||
use crate::optimizer::property::RequiredDist; | ||
|
@@ -120,6 +123,78 @@ pub struct LogicalAgg { | |
input: PlanRef, | ||
} | ||
|
||
impl LogicalAgg { | ||
pub fn infer_internal_table_catalog(&self) -> (Vec<TableCatalog>, HashMap<usize, i32>) { | ||
let mut table_catalogs = vec![]; | ||
let mut column_mapping = HashMap::new(); | ||
let base = self.input.plan_base(); | ||
let schema = &base.schema; | ||
let fields = schema.fields(); | ||
for agg_call in &self.agg_calls { | ||
let mut internal_pk_indices = vec![]; | ||
let mut columns = vec![]; | ||
let mut order_desc = vec![]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need add the group by keys as the prefix of the table's pk |
||
for &idx in &self.group_keys { | ||
let column_id = columns.len() as i32; | ||
internal_pk_indices.push(column_id as usize); // Currently our column index is same as column id | ||
column_mapping.insert(idx, column_id); | ||
let column_desc = ColumnDesc::from_field_with_column_id(&fields[idx], column_id); | ||
columns.push(ColumnCatalog { | ||
column_desc: column_desc.clone(), | ||
is_hidden: false, | ||
}); | ||
order_desc.push(OrderedColumnDesc { | ||
column_desc, | ||
order: OrderType::Ascending, | ||
}) | ||
} | ||
match agg_call.agg_kind { | ||
AggKind::Min | AggKind::Max | AggKind::StringAgg => { | ||
for input in &agg_call.inputs { | ||
let column_id = columns.len() as i32; | ||
column_mapping.insert(input.index, column_id); | ||
columns.push(ColumnCatalog { | ||
column_desc: ColumnDesc::from_field_with_column_id( | ||
&fields[input.index], | ||
column_id, | ||
), | ||
is_hidden: false, | ||
}); | ||
} | ||
} | ||
AggKind::Sum | ||
| AggKind::Count | ||
| AggKind::RowCount | ||
| AggKind::Avg | ||
| AggKind::SingleValue | ||
| AggKind::ApproxCountDistinct => { | ||
columns.push(ColumnCatalog { | ||
column_desc: ColumnDesc::unnamed( | ||
ColumnId::new(columns.len() as i32), | ||
agg_call.return_type.clone(), | ||
), | ||
is_hidden: false, | ||
}); | ||
} | ||
} | ||
table_catalogs.push(TableCatalog { | ||
id: TableId::placeholder(), | ||
associated_source_id: None, | ||
name: String::new(), | ||
columns, | ||
order_desc, | ||
pks: internal_pk_indices, | ||
is_index_on: None, | ||
distribution_keys: base.dist.dist_column_indices().to_vec(), | ||
appendonly: false, | ||
owner: risingwave_common::catalog::DEFAULT_SUPPER_USER.to_string(), | ||
vnode_mapping: None, | ||
}); | ||
} | ||
(table_catalogs, column_mapping) | ||
} | ||
} | ||
|
||
/// `ExprHandler` extracts agg calls and references to group columns from select list, in | ||
/// preparation for generating a plan like `LogicalProject - LogicalAgg - LogicalProject`. | ||
struct ExprHandler { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can merge these fields. but delaying this after the executor really uses the catalog in proto is ok.