Skip to content
Open
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
14 changes: 11 additions & 3 deletions rust/lance/src/io/exec/fts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
use datafusion::physical_plan::union::UnionExec;
use datafusion::physical_plan::{DisplayAs, DisplayFormatType, ExecutionPlan, PlanProperties};
use datafusion_physical_expr::expressions::Column;
use datafusion_physical_expr::{Distribution, EquivalenceProperties, Partitioning};
use datafusion_physical_expr::{Distribution, EquivalenceProperties, Partitioning, PhysicalSortExpr};
use arrow_schema::SortOptions;
use datafusion_physical_plan::joins::{HashJoinExec, PartitionMode};
use datafusion_physical_plan::metrics::{BaselineMetrics, Count};
use futures::future::try_join_all;
Expand Down Expand Up @@ -189,6 +190,7 @@ impl MetricsCollector for FtsIndexMetrics {
}
}


#[derive(Debug)]
pub struct MatchQueryExec {
dataset: Arc<Dataset>,
Expand Down Expand Up @@ -246,7 +248,10 @@ impl MatchQueryExec {
prefilter_source: PreFilterSource,
) -> Self {
let properties = Arc::new(PlanProperties::new(
EquivalenceProperties::new(FTS_SCHEMA.clone()),
EquivalenceProperties::new_with_orderings(FTS_SCHEMA.clone(), [[PhysicalSortExpr::new(
Arc::new(Column::new(SCORE_COL, 1)),
SortOptions { descending: true, nulls_first: true },
)]]),
Partitioning::RoundRobinBatch(1),
EmissionType::Final,
Boundedness::Bounded,
Expand Down Expand Up @@ -281,7 +286,10 @@ impl MatchQueryExec {
segments: Vec<IndexMetadata>,
) -> Self {
let properties = Arc::new(PlanProperties::new(
EquivalenceProperties::new(FTS_SCHEMA.clone()),
EquivalenceProperties::new_with_orderings(FTS_SCHEMA.clone(), [[PhysicalSortExpr::new(
Arc::new(Column::new(SCORE_COL, 1)),
SortOptions { descending: true, nulls_first: true },
)]]),
Partitioning::RoundRobinBatch(1),
EmissionType::Final,
Boundedness::Bounded,
Expand Down
25 changes: 23 additions & 2 deletions rust/lance/src/io/exec/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ use datafusion::physical_plan::stream::RecordBatchStreamAdapter;
use datafusion::physical_plan::{
DisplayAs, DisplayFormatType, ExecutionPlan, PlanProperties, SendableRecordBatchStream,
};
use datafusion_physical_expr::EquivalenceProperties;
use datafusion_physical_expr::expressions::Column;
use datafusion_physical_expr::projection::ProjectionMapping;
use datafusion_physical_expr::{EquivalenceProperties, PhysicalExpr};
use futures::FutureExt;
use futures::stream::{FuturesOrdered, Stream, StreamExt, TryStreamExt};
use lance_arrow::RecordBatchExt;
Expand Down Expand Up @@ -477,12 +479,31 @@ impl TakeExec {
&projection,
));
let output_arrow = Arc::new(ArrowSchema::from(output_schema.as_ref()));
// Propagate input ordering through the schema change. TakeExec always
// places input fields first in the same order, so input field at index i
// maps to output field at index i. New dataset fields appended at the end
// have no ordering and are simply not included in the mapping.
let input_schema_ref = input.schema();
let mapping_exprs = input_schema_ref.fields().iter().enumerate().map(|(i, f)| {
(
Arc::new(Column::new(f.name(), i)) as Arc<dyn PhysicalExpr>,
f.name().to_string(),
)
});
let eq_props = ProjectionMapping::try_new(mapping_exprs, &input_schema_ref)
.map(|m| {
input
.properties()
.equivalence_properties()
.project(&m, output_arrow.clone())
})
.unwrap_or_else(|_| EquivalenceProperties::new(output_arrow.clone()));
let properties = Arc::new(
input
.properties()
.as_ref()
.clone()
.with_eq_properties(EquivalenceProperties::new(output_arrow.clone())),
.with_eq_properties(eq_props),
);

Ok(Some(Self {
Expand Down
Loading