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

feat(streaming): use table_id as AppendOnlytopN prefix for keyspace #2992

Merged
merged 1 commit into from
Jun 6, 2022
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
24 changes: 23 additions & 1 deletion src/frontend/src/stream_fragmenter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ impl StreamFragmenter {
top_n_node.table_id = state.gen_table_id();
}

NodeBody::AppendOnlyTopN(append_only_top_n_node) => {
append_only_top_n_node.table_id = state.gen_table_id();
}

_ => {}
}
}
Expand Down Expand Up @@ -461,7 +465,7 @@ mod tests {
}

{
// test HashJoin Type
// test TopN Type
let mut stream_node = StreamNode {
node_body: Some(NodeBody::TopN(TopNNode {
..Default::default()
Expand All @@ -475,5 +479,23 @@ mod tests {
assert_eq!(expect_table_id, top_n_node.table_id);
}
}

{
// test AppendOnlyTopN Type
let mut stream_node = StreamNode {
node_body: Some(NodeBody::AppendOnlyTopN(TopNNode {
..Default::default()
})),
..Default::default()
};
StreamFragmenter::assign_local_table_id_to_stream_node(&mut state, &mut stream_node);

if let NodeBody::AppendOnlyTopN(append_only_top_n_node) =
stream_node.node_body.as_ref().unwrap()
{
expect_table_id += 1;
assert_eq!(expect_table_id, append_only_top_n_node.table_id);
}
}
}
}
55 changes: 27 additions & 28 deletions src/meta/src/stream/stream_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,41 +541,40 @@ impl StreamGraphBuilder {
let mut new_stream_node = stream_node.clone();

// Table id rewrite done below.
match new_stream_node.node_body.as_mut().unwrap() {
NodeBody::HashJoin(node) => {
// The operator id must be assigned with table ids. Otherwise it is a logic
// error.
let left_table_id = node.left_table_id + table_id_offset;
let right_table_id = left_table_id + 1;
node.left_table_id = left_table_id;
node.right_table_id = right_table_id;
}

if let NodeBody::HashJoin(node) = new_stream_node.node_body.as_mut().unwrap() {
// The operator id must be assigned with table ids. Otherwise it is a logic
// error.
let left_table_id = node.left_table_id + table_id_offset;
let right_table_id = left_table_id + 1;
node.left_table_id = left_table_id;
node.right_table_id = right_table_id;
}

if let NodeBody::Lookup(node) = new_stream_node.node_body.as_mut().unwrap() {
if let Some(ArrangementTableId::TableId(table_id)) =
&mut node.arrangement_table_id
{
*table_id += table_id_offset;
NodeBody::Lookup(node) => {
if let Some(ArrangementTableId::TableId(table_id)) =
&mut node.arrangement_table_id
{
*table_id += table_id_offset;
}
}
}

if let NodeBody::Arrange(node) = new_stream_node.node_body.as_mut().unwrap() {
node.table_id += table_id_offset;
}
NodeBody::Arrange(node) => {
node.table_id += table_id_offset;
}

if let NodeBody::HashAgg(node) = new_stream_node.node_body.as_mut().unwrap() {
assert_eq!(node.table_ids.len(), node.agg_calls.len());
// In-place update the table id. Convert from local to global.
for table_id in &mut node.table_ids {
*table_id += table_id_offset;
NodeBody::HashAgg(node) => {
assert_eq!(node.table_ids.len(), node.agg_calls.len());
// In-place update the table id. Convert from local to global.
for table_id in &mut node.table_ids {
*table_id += table_id_offset;
}
}
}

if let NodeBody::TopN(node) = new_stream_node.node_body.as_mut().unwrap() {
node.table_id += table_id_offset;
}
NodeBody::TopN(node) | NodeBody::AppendOnlyTopN(node) => {
node.table_id += table_id_offset;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing AppendOnlyTopN here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NodeBody::TopN(node) | NodeBody::AppendOnlyTopN(node) => xxx

TopN and AppendOnlyTopN use the same table_id assign logic, so they use the same pattern

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool. I missed that 🤣


match new_stream_node.node_body.as_mut().unwrap() {
NodeBody::GlobalSimpleAgg(node) | NodeBody::LocalSimpleAgg(node) => {
assert_eq!(node.table_ids.len(), node.agg_calls.len());
// In-place update the table id. Convert from local to global.
Expand Down
4 changes: 3 additions & 1 deletion src/stream/src/from_proto/top_n_appendonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use risingwave_common::catalog::TableId;
use risingwave_common::util::sort_util::OrderPair;

use super::*;
Expand Down Expand Up @@ -39,7 +40,8 @@ impl ExecutorBuilder for AppendOnlyTopNExecutorBuilder {
};
let cache_size = Some(1024);
let total_count = (0, 0);
let keyspace = Keyspace::executor_root(store, params.executor_id);
let table_id = TableId::new(node.table_id);
let keyspace = Keyspace::table_root(store, &table_id);
let key_indices = node
.get_distribution_keys()
.iter()
Expand Down