Skip to content

Commit

Permalink
Merge pull request #297 from Mytherin/topn
Browse files Browse the repository at this point in the history
Fix for dynamic filters generated through top-n
  • Loading branch information
Mytherin authored Feb 7, 2025
2 parents 79fcce4 + 14afa7a commit 8461ed8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/postgres_filter_pushdown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ string PostgresFilterPushdown::CreateExpression(string &column_name, vector<uniq
string op) {
vector<string> filter_entries;
for (auto &filter : filters) {
filter_entries.push_back(TransformFilter(column_name, *filter));
auto filter_str = TransformFilter(column_name, *filter);
if (!filter_str.empty()) {
filter_entries.push_back(std::move(filter_str));
}
}
if (filter_entries.empty()) {
return string();
}
return "(" + StringUtil::Join(filter_entries, " " + op + " ") + ")";
}
Expand Down Expand Up @@ -98,6 +104,8 @@ string PostgresFilterPushdown::TransformFilter(string &column_name, TableFilter
}
return column_name + " IN (" + in_list + ")";
}
case TableFilterType::DYNAMIC_FILTER:
return string();
default:
throw InternalException("Unsupported table filter type");
}
Expand All @@ -111,13 +119,17 @@ string PostgresFilterPushdown::TransformFilters(const vector<column_t> &column_i
}
string result;
for (auto &entry : filters->filters) {
if (!result.empty()) {
result += " AND ";
}
auto column_name = KeywordHelper::WriteQuoted(names[column_ids[entry.first]], '"');
auto &filter = *entry.second;
auto filter_text = TransformFilter(column_name, filter);

result += TransformFilter(column_name, filter);
if (filter_text.empty()) {
continue;
}
if (!result.empty()) {
result += " AND ";
}
result += filter_text;
}
return result;
}
Expand Down
20 changes: 20 additions & 0 deletions test/sql/storage/attach_top_n.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# name: test/sql/storage/attach_top_n.test
# description: Attach with Top-N queries
# group: [storage]

require postgres_scanner

require-env POSTGRES_TEST_DATABASE_AVAILABLE

statement ok
ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES);

query IIIIIIII
select * from s.pg_numtypes order by smallint_col limit 1
----
false -42 -42 -42 -42.01 -42.01 -42.0 -42.01

query IIIIIIII
select * from s.pg_numtypes where smallint_col >= 0 order by 2 limit 1
----
0 0 0 0 0.0 0.0 0.0 0.0

0 comments on commit 8461ed8

Please sign in to comment.