MCPcopy Create free account
hub / github.com/apache/datafusion / try_with_sort_information

Method try_with_sort_information

datafusion/datasource/src/memory.rs:435–465  ·  view source on GitHub ↗

A memory table can be ordered by multiple expressions simultaneously. [`EquivalenceProperties`] keeps track of expressions that describe the global ordering of the schema. These columns are not necessarily same; e.g. ```text ┌-------┐ | a | b | |---|---| | 1 | 9 | | 2 | 8 | | 3 | 7 | | 5 | 5 | └---┴---┘ ``` where both `a ASC` and `b DESC` can describe the table ordering. With [`EquivalenceProperti

(
        mut self,
        mut sort_information: Vec<LexOrdering>,
    )

Source from the content-addressed store, hash-verified

433 /// Note that if there is an internal projection, that projection will be
434 /// also applied to the given `sort_information`.
435 pub fn try_with_sort_information(
436 mut self,
437 mut sort_information: Vec<LexOrdering>,
438 ) -> Result<Self> {
439 // All sort expressions must refer to the original schema
440 let fields = self.schema.fields();
441 let ambiguous_column = sort_information
442 .iter()
443 .flat_map(|ordering| ordering.clone())
444 .flat_map(|expr| collect_columns(&expr.expr))
445 .find(|col| {
446 fields
447 .get(col.index())
448 .map(|field| field.name() != col.name())
449 .unwrap_or(true)
450 });
451 assert_or_internal_err!(
452 ambiguous_column.is_none(),
453 "Column {:?} is not found in the original schema of the MemorySourceConfig",
454 ambiguous_column.as_ref().unwrap()
455 );
456
457 // If there is a projection on the source, we also need to project orderings
458 if self.projection.is_some() {
459 sort_information =
460 project_orderings(&sort_information, &self.projected_schema);
461 }
462
463 self.sort_information = sort_information;
464 Ok(self)
465 }
466
467 /// Arc clone of ref to original schema
468 pub fn original_schema(&self) -> SchemaRef {

Calls 9

collect_columnsFunction · 0.85
project_orderingsFunction · 0.85
fieldsMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
mapMethod · 0.45
getMethod · 0.45
indexMethod · 0.45
nameMethod · 0.45

Tested by 6

test_memory_order_eqFunction · 0.36
memory_exec_sortedFunction · 0.36
run_window_testFunction · 0.36
run_aggregate_testFunction · 0.36
scanMethod · 0.36