Skip to content

Commit 8ee640d

Browse files
committed
Pull data from pipeline and commit insertion.
1 parent 07fc475 commit 8ee640d

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/query/service/src/interpreters/interpreter_insert_v2.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ use common_functions::scalars::CastFunction;
2323
use common_planners::StageKind;
2424
use common_streams::DataBlockStream;
2525
use common_streams::SendableDataBlockStream;
26+
use futures_util::StreamExt;
2627
use parking_lot::Mutex;
2728

2829
use super::commit2table;
2930
use super::commit2table_with_append_entries;
3031
use super::interpreter_common::append2table;
3132
use super::plan_schedulers::build_schedule_pipepline;
33+
use super::ProcessorExecutorStream;
3234
use crate::clusters::ClusterHelper;
3335
use crate::interpreters::Interpreter;
3436
use crate::interpreters::InterpreterPtr;
@@ -198,11 +200,11 @@ impl InsertInterpreterV2 {
198200

199201
async fn schedule_insert_select(
200202
&self,
201-
plan: &Box<Plan>,
203+
plan: &Plan,
202204
catalog: String,
203205
table: Arc<dyn Table>,
204206
) -> Result<SendableDataBlockStream> {
205-
let inner_plan = match &**plan {
207+
let inner_plan = match plan {
206208
Plan::Query {
207209
s_expr, metadata, ..
208210
} => {
@@ -214,14 +216,15 @@ impl InsertInterpreterV2 {
214216

215217
table.get_table_info();
216218

217-
let insert_select_plan = PhysicalPlan::DistributedInsertSelect(DistributedInsertSelect {
218-
input: Box::new(inner_plan),
219-
catalog,
220-
table_info: table.get_table_info().clone(),
221-
select_schema: plan.schema(),
222-
insert_schema: self.plan.schema(),
223-
cast_needed: self.check_schema_cast(plan)?,
224-
});
219+
let insert_select_plan =
220+
PhysicalPlan::DistributedInsertSelect(Box::new(DistributedInsertSelect {
221+
input: Box::new(inner_plan),
222+
catalog,
223+
table_info: table.get_table_info().clone(),
224+
select_schema: plan.schema(),
225+
insert_schema: self.plan.schema(),
226+
cast_needed: self.check_schema_cast(plan)?,
227+
}));
225228

226229
let final_plan = PhysicalPlan::Exchange(Exchange {
227230
input: Box::new(insert_select_plan),
@@ -242,8 +245,20 @@ impl InsertInterpreterV2 {
242245
executor_settings,
243246
)?;
244247

245-
commit2table_with_append_entries(self.ctx.clone(), table, self.plan.overwrite, vec![])
246-
.await?;
248+
let mut append_entries = vec![];
249+
let mut stream: SendableDataBlockStream =
250+
Box::pin(ProcessorExecutorStream::create(executor)?);
251+
while let Some(block) = stream.next().await {
252+
append_entries.push(block?);
253+
}
254+
255+
commit2table_with_append_entries(
256+
self.ctx.clone(),
257+
table,
258+
self.plan.overwrite,
259+
append_entries,
260+
)
261+
.await?;
247262

248263
Ok(Box::pin(DataBlockStream::create(
249264
self.plan.schema(),

src/query/service/src/sql/executor/physical_plan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ pub enum PhysicalPlan {
336336
UnionAll(UnionAll),
337337

338338
/// For insert into ... select ... in cluster
339-
DistributedInsertSelect(DistributedInsertSelect),
339+
DistributedInsertSelect(Box<DistributedInsertSelect>),
340340

341341
/// Synthesized by fragmenter
342342
ExchangeSource(ExchangeSource),

src/query/service/src/sql/executor/physical_plan_visitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub trait PhysicalPlanReplacer {
180180
fn replace_insert_select(&mut self, plan: &DistributedInsertSelect) -> Result<PhysicalPlan> {
181181
let input = self.replace(&plan.input)?;
182182

183-
Ok(PhysicalPlan::DistributedInsertSelect(
183+
Ok(PhysicalPlan::DistributedInsertSelect(Box::new(
184184
DistributedInsertSelect {
185185
input: Box::new(input),
186186
catalog: plan.catalog.clone(),
@@ -189,7 +189,7 @@ pub trait PhysicalPlanReplacer {
189189
insert_schema: plan.insert_schema.clone(),
190190
cast_needed: plan.cast_needed,
191191
},
192-
))
192+
)))
193193
}
194194
}
195195

0 commit comments

Comments
 (0)