Skip to content

Commit

Permalink
chore(query): fix topk in native (#17003)
Browse files Browse the repository at this point in the history
* chore(query): fix topk in native

* chore(query): fix topk in native
  • Loading branch information
sundy-li authored Dec 5, 2024
1 parent fd8b259 commit 5ca9e64
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 57 deletions.
6 changes: 3 additions & 3 deletions scripts/setup/rust-tools.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cargo-audit@0.18.3
cargo-machete@0.6.0
cargo-nextest@0.9.67
taplo-cli@0.8.1
typos-cli@1.17.2
cargo-nextest@0.9.85
taplo-cli@0.9.3
typos-cli@1.28.2
18 changes: 7 additions & 11 deletions src/query/catalog/src/plan/pushdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,17 @@ impl PushDownInfo {
if !TopK::support_type(data_type) {
return None;
}

let leaf_fields = schema.leaf_fields();
let (leaf_id, f) = leaf_fields
leaf_fields
.iter()
.enumerate()
.find(|&(_, p)| p.name() == id)
.unwrap();

let top_k = TopK {
limit: self.limit.unwrap(),
field: f.clone(),
asc: order.1,
leaf_id,
};
Some(top_k)
.map(|(leaf_id, f)| TopK {
limit: self.limit.unwrap(),
field: f.clone(),
asc: order.1,
leaf_id,
})
} else {
None
}
Expand Down
82 changes: 39 additions & 43 deletions src/query/sql/src/executor/physical_plans/physical_table_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,51 +478,47 @@ impl PhysicalPlanBuilder {
})
.transpose()?;

let order_by = scan
.order_by
.clone()
.map(|items| {
items
.into_iter()
.map(|item| {
let metadata = self.metadata.read();
let column = metadata.column(item.index);
let (name, data_type) = match column {
ColumnEntry::BaseTableColumn(BaseTableColumn {
column_name,
data_type,
..
}) => (column_name.clone(), DataType::from(data_type)),
ColumnEntry::DerivedColumn(DerivedColumn {
alias, data_type, ..
}) => (alias.clone(), data_type.clone()),
ColumnEntry::InternalColumn(TableInternalColumn {
internal_column,
..
}) => (
internal_column.column_name().to_owned(),
internal_column.data_type(),
),
ColumnEntry::VirtualColumn(VirtualColumn {
column_name,
data_type,
..
}) => (column_name.clone(), DataType::from(data_type)),
};

// sort item is already a column
let scalar = RemoteExpr::ColumnRef {
span: None,
id: name.clone(),
let order_by = scan.order_by.clone().map(|items| {
items
.into_iter()
.filter_map(|item| {
let metadata = self.metadata.read();
let column = metadata.column(item.index);
let (name, data_type) = match column {
ColumnEntry::BaseTableColumn(BaseTableColumn {
column_name,
data_type,
..
}) => (column_name.clone(), DataType::from(data_type)),
ColumnEntry::InternalColumn(TableInternalColumn {
internal_column,
..
}) => (
internal_column.column_name().to_owned(),
internal_column.data_type(),
),
ColumnEntry::VirtualColumn(VirtualColumn {
column_name,
data_type,
display_name: name,
};
..
}) => (column_name.clone(), DataType::from(data_type)),
ColumnEntry::DerivedColumn(_) => {
return None;
}
};

Ok((scalar, item.asc, item.nulls_first))
})
.collect::<Result<Vec<_>>>()
})
.transpose()?;
// sort item is already a column
let scalar = RemoteExpr::ColumnRef {
span: None,
id: name.clone(),
data_type,
display_name: name,
};

Some((scalar, item.asc, item.nulls_first))
})
.collect::<Vec<_>>()
});

let virtual_column = self.build_virtual_column(&scan.columns);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ select * from test where url like '%google%' order by event_time limit 10;
0 2024-01-03 00:00:00.000000 http://www.google.com/xxx/
0 2024-01-04 00:00:00.000000 http://www.google.com/xxx/


statement ok
create table test_k storage_format = 'native' as select * from test;


query ITT
select * from test_k where url like '%google%' order by event_time limit 1;
----
0 2024-01-01 00:00:00.000000 http://www.google.com/xxx/

statement ok
drop table test

statement ok
drop table test_k

0 comments on commit 5ca9e64

Please sign in to comment.