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

refactor(executor): use plan node to infer column name #458

Merged
merged 1 commit into from
Feb 14, 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
2 changes: 2 additions & 0 deletions src/array/data_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ impl DataChunk {
self.arrays.iter().map(|a| a.get_estimated_size()).sum()
}

/// This function should only be called in plan nodes. If you want to change column name, you
/// should change the plan node, instead of directly attaching a header to the chunk.
pub fn set_header(&mut self, header: Vec<String>) {
self.header = Some(header);
}
Expand Down
3 changes: 1 addition & 2 deletions src/executor/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ impl<S: Storage> CreateTableExecutor<S> {
)
.await?;

let mut chunk = DataChunk::single(0);
chunk.set_header(vec!["$create".to_string()]);
let chunk = DataChunk::single(0);
yield chunk
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/optimizer/plan_nodes/logical_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Serialize;

use super::*;
use crate::catalog::ColumnCatalog;
use crate::types::{DatabaseId, SchemaId};
use crate::types::{DataTypeKind, DatabaseId, SchemaId};

/// The logical plan of `CREATE TABLE`.
#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -54,8 +54,18 @@ impl LogicalCreateTable {
}
}
impl PlanTreeNodeLeaf for LogicalCreateTable {}

impl_plan_tree_node_for_leaf!(LogicalCreateTable);
impl PlanNode for LogicalCreateTable {}

impl PlanNode for LogicalCreateTable {
fn schema(&self) -> Vec<ColumnDesc> {
vec![ColumnDesc::new(
DataType::new(DataTypeKind::Int(None), false),
"$create".to_string(),
false,
)]
}
}

impl fmt::Display for LogicalCreateTable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
6 changes: 5 additions & 1 deletion src/optimizer/plan_nodes/physical_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ impl PhysicalCreateTable {
impl PlanTreeNodeLeaf for PhysicalCreateTable {}
impl_plan_tree_node_for_leaf!(PhysicalCreateTable);

impl PlanNode for PhysicalCreateTable {}
impl PlanNode for PhysicalCreateTable {
fn schema(&self) -> Vec<ColumnDesc> {
self.logical.schema()
}
}

impl fmt::Display for PhysicalCreateTable {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down