Skip to content

Commit 8461ed8

Browse files
authored
Merge pull request #297 from Mytherin/topn
Fix for dynamic filters generated through top-n
2 parents 79fcce4 + 14afa7a commit 8461ed8

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/postgres_filter_pushdown.cpp

+17-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ string PostgresFilterPushdown::CreateExpression(string &column_name, vector<uniq
1111
string op) {
1212
vector<string> filter_entries;
1313
for (auto &filter : filters) {
14-
filter_entries.push_back(TransformFilter(column_name, *filter));
14+
auto filter_str = TransformFilter(column_name, *filter);
15+
if (!filter_str.empty()) {
16+
filter_entries.push_back(std::move(filter_str));
17+
}
18+
}
19+
if (filter_entries.empty()) {
20+
return string();
1521
}
1622
return "(" + StringUtil::Join(filter_entries, " " + op + " ") + ")";
1723
}
@@ -98,6 +104,8 @@ string PostgresFilterPushdown::TransformFilter(string &column_name, TableFilter
98104
}
99105
return column_name + " IN (" + in_list + ")";
100106
}
107+
case TableFilterType::DYNAMIC_FILTER:
108+
return string();
101109
default:
102110
throw InternalException("Unsupported table filter type");
103111
}
@@ -111,13 +119,17 @@ string PostgresFilterPushdown::TransformFilters(const vector<column_t> &column_i
111119
}
112120
string result;
113121
for (auto &entry : filters->filters) {
114-
if (!result.empty()) {
115-
result += " AND ";
116-
}
117122
auto column_name = KeywordHelper::WriteQuoted(names[column_ids[entry.first]], '"');
118123
auto &filter = *entry.second;
124+
auto filter_text = TransformFilter(column_name, filter);
119125

120-
result += TransformFilter(column_name, filter);
126+
if (filter_text.empty()) {
127+
continue;
128+
}
129+
if (!result.empty()) {
130+
result += " AND ";
131+
}
132+
result += filter_text;
121133
}
122134
return result;
123135
}

test/sql/storage/attach_top_n.test

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# name: test/sql/storage/attach_top_n.test
2+
# description: Attach with Top-N queries
3+
# group: [storage]
4+
5+
require postgres_scanner
6+
7+
require-env POSTGRES_TEST_DATABASE_AVAILABLE
8+
9+
statement ok
10+
ATTACH 'dbname=postgresscanner' AS s (TYPE POSTGRES);
11+
12+
query IIIIIIII
13+
select * from s.pg_numtypes order by smallint_col limit 1
14+
----
15+
false -42 -42 -42 -42.01 -42.01 -42.0 -42.01
16+
17+
query IIIIIIII
18+
select * from s.pg_numtypes where smallint_col >= 0 order by 2 limit 1
19+
----
20+
0 0 0 0 0.0 0.0 0.0 0.0

0 commit comments

Comments
 (0)