Skip to content
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
5 changes: 4 additions & 1 deletion src/execution/physical_plan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
mod physical_create_table;
mod physical_dummy_scan;
mod physical_expression_scan;
mod physical_insert;
mod physical_projection;
mod physical_table_scan;

use derive_new::new;
pub use physical_create_table::*;
pub use physical_dummy_scan::*;
pub use physical_expression_scan::*;
pub use physical_insert::*;
pub use physical_projection::*;
Expand All @@ -17,12 +19,13 @@ use crate::types_v2::LogicalType;
pub struct PhysicalOperatorBase {
pub(crate) children: Vec<PhysicalOperator>,
/// The types returned by this physical operator
pub(crate) _types: Vec<LogicalType>,
pub(crate) types: Vec<LogicalType>,
}

#[derive(Clone)]
pub enum PhysicalOperator {
PhysicalCreateTable(PhysicalCreateTable),
PhysicalDummyScan(PhysicalDummyScan),
PhysicalExpressionScan(PhysicalExpressionScan),
PhysicalInsert(PhysicalInsert),
PhysicalTableScan(PhysicalTableScan),
Expand Down
17 changes: 17 additions & 0 deletions src/execution/physical_plan/physical_dummy_scan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use derive_new::new;

use super::{PhysicalOperator, PhysicalOperatorBase};
use crate::execution::PhysicalPlanGenerator;
use crate::planner_v2::LogicalDummyScan;

#[derive(new, Clone)]
pub struct PhysicalDummyScan {
pub(crate) base: PhysicalOperatorBase,
}

impl PhysicalPlanGenerator {
pub(crate) fn create_physical_dummy_scan(&self, op: LogicalDummyScan) -> PhysicalOperator {
let base = PhysicalOperatorBase::new(vec![], op.base.types);
PhysicalOperator::PhysicalDummyScan(PhysicalDummyScan::new(base))
}
}
1 change: 1 addition & 0 deletions src/execution/physical_plan_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl PhysicalPlanGenerator {
LogicalOperator::LogicalInsert(op) => self.create_physical_insert(op),
LogicalOperator::LogicalGet(op) => self.create_physical_table_scan(op),
LogicalOperator::LogicalProjection(op) => self.create_physical_projection(op),
LogicalOperator::LogicalDummyScan(op) => self.create_physical_dummy_scan(op),
}
}
}
30 changes: 30 additions & 0 deletions src/execution/volcano_executor/dummy_scan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::collections::HashMap;
use std::sync::Arc;

use arrow::datatypes::{Field, Schema, SchemaRef};
use arrow::record_batch::RecordBatch;
use derive_new::new;
use futures_async_stream::try_stream;

use crate::execution::{ExecutionContext, ExecutorError, PhysicalDummyScan};

#[derive(new)]
pub struct DummyScan {
pub(crate) plan: PhysicalDummyScan,
}

impl DummyScan {
#[try_stream(boxed, ok = RecordBatch, error = ExecutorError)]
pub async fn execute(self, _context: Arc<ExecutionContext>) {
let mut fields = vec![];
for (idx, ty) in self.plan.base.types.iter().enumerate() {
fields.push(Field::new(
format!("col{}", idx).as_str(),
ty.clone().into(),
true,
));
}
let schema = SchemaRef::new(Schema::new_with_metadata(fields, HashMap::new()));
yield RecordBatch::new_empty(schema.clone());
}
}
3 changes: 3 additions & 0 deletions src/execution/volcano_executor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod create_table;
mod dummy_scan;
mod expression_scan;
mod insert;
mod projection;
Expand All @@ -7,6 +8,7 @@ use std::sync::Arc;

use arrow::record_batch::RecordBatch;
pub use create_table::*;
pub use dummy_scan::*;
pub use expression_scan::*;
use futures::stream::BoxStream;
use futures::TryStreamExt;
Expand Down Expand Up @@ -43,6 +45,7 @@ impl VolcanoExecutor {
let child_executor = self.build(child, context.clone());
Projection::new(op, child_executor).execute(context)
}
PhysicalOperator::PhysicalDummyScan(op) => DummyScan::new(op).execute(context),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl ExpressionBinder<'_> {
result_types: &mut Vec<LogicalType>,
) -> Result<BoundExpression, BindError> {
let scalar: ScalarValue = v.into();
let base = BoundExpressionBase::new("".to_string(), scalar.get_logical_type());
let base = BoundExpressionBase::new(scalar.to_string(), scalar.get_logical_type());
result_names.push(base.alias.clone());
result_types.push(base.return_type.clone());
let expr =
Expand Down
5 changes: 4 additions & 1 deletion src/planner_v2/binder/query_node/plan_select_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::BoundSelectNode;
use crate::planner_v2::BoundTableRef::{BoundBaseTableRef, BoundExpressionListRef};
use crate::planner_v2::BoundTableRef::{
BoundBaseTableRef, BoundDummyTableRef, BoundExpressionListRef,
};
use crate::planner_v2::{
BindError, Binder, BoundCastExpression, BoundStatement, LogicalOperator, LogicalOperatorBase,
LogicalProjection,
Expand All @@ -16,6 +18,7 @@ impl Binder {
self.create_plan_for_expression_list_ref(bound_ref)?
}
BoundBaseTableRef(bound_ref) => self.create_plan_for_base_tabel_ref(*bound_ref)?,
BoundDummyTableRef(bound_ref) => self.create_plan_for_dummy_table_ref(bound_ref)?,
};

let root = LogicalOperator::LogicalProjection(LogicalProjection::new(
Expand Down
18 changes: 18 additions & 0 deletions src/planner_v2/binder/tableref/bind_dummy_table_ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use derive_new::new;

use super::BoundTableRef;
use crate::planner_v2::{BindError, Binder};

#[derive(new, Debug)]
pub struct BoundDummyTableRef {
pub(crate) bind_index: usize,
}

impl Binder {
pub fn bind_dummy_table_ref(&mut self) -> Result<BoundTableRef, BindError> {
let table_index = self.generate_table_index();
let bound_tabel_ref =
BoundTableRef::BoundDummyTableRef(BoundDummyTableRef::new(table_index));
Ok(bound_tabel_ref)
}
}
8 changes: 8 additions & 0 deletions src/planner_v2/binder/tableref/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
mod bind_base_table_ref;
mod bind_dummy_table_ref;
mod bind_expression_list_ref;
mod plan_base_table_ref;
mod plan_dummy_table_ref;
mod plan_expression_list_ref;
pub use bind_base_table_ref::*;
pub use bind_dummy_table_ref::*;
pub use bind_expression_list_ref::*;
pub use plan_base_table_ref::*;
pub use plan_dummy_table_ref::*;
pub use plan_expression_list_ref::*;

use super::{BindError, Binder};
Expand All @@ -13,13 +17,17 @@ use super::{BindError, Binder};
pub enum BoundTableRef {
BoundExpressionListRef(BoundExpressionListRef),
BoundBaseTableRef(Box<BoundBaseTableRef>),
BoundDummyTableRef(BoundDummyTableRef),
}

impl Binder {
pub fn bind_table_ref(
&mut self,
table_refs: &[sqlparser::ast::TableWithJoins],
) -> Result<BoundTableRef, BindError> {
if table_refs.is_empty() {
return self.bind_dummy_table_ref();
}
let first_table = table_refs[0].clone();
match first_table.relation.clone() {
sqlparser::ast::TableFactor::Table { .. } => {
Expand Down
13 changes: 13 additions & 0 deletions src/planner_v2/binder/tableref/plan_dummy_table_ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use super::BoundDummyTableRef;
use crate::planner_v2::{BindError, Binder, LogicalDummyScan, LogicalOperator};

impl Binder {
pub fn create_plan_for_dummy_table_ref(
&mut self,
bound_ref: BoundDummyTableRef,
) -> Result<LogicalOperator, BindError> {
Ok(LogicalOperator::LogicalDummyScan(LogicalDummyScan::new(
bound_ref.bind_index,
)))
}
}
11 changes: 11 additions & 0 deletions src/planner_v2/operator/logical_dummy_scan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use derive_new::new;

use super::LogicalOperatorBase;

/// LogicalDummyScan represents a dummy scan returning nothing.
#[derive(new, Debug)]
pub struct LogicalDummyScan {
#[new(default)]
pub(crate) base: LogicalOperatorBase,
pub(crate) table_idx: usize,
}
8 changes: 8 additions & 0 deletions src/planner_v2/operator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::types_v2::LogicalType;

mod logical_create_table;
mod logical_dummy_scan;
mod logical_expression_get;
mod logical_get;
mod logical_insert;
mod logical_projection;
use derive_new::new;
pub use logical_create_table::*;
pub use logical_dummy_scan::*;
pub use logical_expression_get::*;
pub use logical_get::*;
pub use logical_insert::*;
Expand All @@ -26,6 +28,7 @@ pub struct LogicalOperatorBase {
#[derive(Debug)]
pub enum LogicalOperator {
LogicalCreateTable(LogicalCreateTable),
LogicalDummyScan(LogicalDummyScan),
LogicalExpressionGet(LogicalExpressionGet),
LogicalInsert(LogicalInsert),
LogicalGet(LogicalGet),
Expand All @@ -40,6 +43,7 @@ impl LogicalOperator {
LogicalOperator::LogicalInsert(op) => &mut op.base.children,
LogicalOperator::LogicalGet(op) => &mut op.base.children,
LogicalOperator::LogicalProjection(op) => &mut op.base.children,
LogicalOperator::LogicalDummyScan(op) => &mut op.base.children,
}
}

Expand All @@ -50,6 +54,7 @@ impl LogicalOperator {
LogicalOperator::LogicalInsert(op) => &mut op.base.expressioins,
LogicalOperator::LogicalGet(op) => &mut op.base.expressioins,
LogicalOperator::LogicalProjection(op) => &mut op.base.expressioins,
LogicalOperator::LogicalDummyScan(op) => &mut op.base.expressioins,
}
}

Expand All @@ -60,6 +65,7 @@ impl LogicalOperator {
LogicalOperator::LogicalInsert(op) => &op.base.types,
LogicalOperator::LogicalGet(op) => &op.base.types,
LogicalOperator::LogicalProjection(op) => &op.base.types,
LogicalOperator::LogicalDummyScan(op) => &op.base.types,
}
}

Expand All @@ -77,6 +83,7 @@ impl LogicalOperator {
LogicalOperator::LogicalProjection(op) => {
self.generate_column_bindings(op.table_idx, op.base.expressioins.len())
}
LogicalOperator::LogicalDummyScan(op) => vec![ColumnBinding::new(op.table_idx, 0)],
}
}

Expand All @@ -102,6 +109,7 @@ impl LogicalOperator {
.collect::<Vec<_>>();
op.base.types.extend(types);
}
LogicalOperator::LogicalDummyScan(op) => op.base.types.push(LogicalType::Integer),
}
}

Expand Down
7 changes: 7 additions & 0 deletions tests/slt/select.slt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,10 @@ select t.v1 as a, v2 as b from t1 as t;
----
1 4
2 5


onlyif sqlrs_v2
query III
select 1, 2.3, '😇', true, null;
----
1 2.3 😇 true null