Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(query): fix topk in native #17003

Merged
merged 2 commits into from
Dec 5, 2024
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
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
Loading