Skip to content

Commit 2053022

Browse files
committed
WIP - Connector predicate pushdown
1 parent 49edfa7 commit 2053022

File tree

13 files changed

+582
-1
lines changed

13 files changed

+582
-1
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.prestosql.metadata;
15+
16+
import io.prestosql.spi.connector.ColumnHandle;
17+
import io.prestosql.spi.type.Type;
18+
import io.prestosql.spi.expression.ConnectorExpression;
19+
20+
import java.util.List;
21+
22+
public class FilterApplicationResult
23+
{
24+
private final TableHandle table;
25+
private final ConnectorExpression remainingFilter;
26+
private final List<Column> newProjections;
27+
28+
public FilterApplicationResult(TableHandle table, ConnectorExpression remainingFilter, List<Column> newProjections)
29+
{
30+
this.table = table;
31+
this.remainingFilter = remainingFilter;
32+
this.newProjections = newProjections;
33+
}
34+
35+
public TableHandle getTable()
36+
{
37+
return table;
38+
}
39+
40+
public ConnectorExpression getRemainingFilter()
41+
{
42+
return remainingFilter;
43+
}
44+
45+
public List<Column> getNewProjections()
46+
{
47+
return newProjections;
48+
}
49+
50+
public static class Column
51+
{
52+
private final ColumnHandle column;
53+
private final Type type;
54+
55+
public Column(ColumnHandle column, Type type)
56+
{
57+
this.column = column;
58+
this.type = type;
59+
}
60+
61+
public ColumnHandle getColumn()
62+
{
63+
return column;
64+
}
65+
66+
public Type getType()
67+
{
68+
return type;
69+
}
70+
}
71+
}

presto-main/src/main/java/io/prestosql/metadata/Metadata.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import io.prestosql.spi.type.TypeManager;
3838
import io.prestosql.spi.type.TypeSignature;
3939
import io.prestosql.sql.planner.PartitioningHandle;
40+
import io.prestosql.spi.expression.ConnectorExpression;
4041
import io.prestosql.sql.tree.QualifiedName;
4142

4243
import java.util.Collection;
@@ -380,4 +381,7 @@ public interface Metadata
380381
ColumnPropertyManager getColumnPropertyManager();
381382

382383
AnalyzePropertyManager getAnalyzePropertyManager();
384+
385+
// => TableHandle + remaining filter + new projections
386+
Optional<FilterApplicationResult> applyFilter(TableHandle table, ConnectorExpression expression);
383387
}

presto-main/src/main/java/io/prestosql/metadata/MetadataManager.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
import io.prestosql.spi.type.TypeSignature;
6666
import io.prestosql.sql.analyzer.FeaturesConfig;
6767
import io.prestosql.sql.planner.PartitioningHandle;
68+
import io.prestosql.spi.expression.Apply;
69+
import io.prestosql.spi.expression.ColumnReference;
70+
import io.prestosql.spi.expression.ConnectorExpression;
6871
import io.prestosql.sql.tree.QualifiedName;
6972
import io.prestosql.transaction.TransactionManager;
7073
import io.prestosql.type.TypeDeserializer;
@@ -1151,6 +1154,47 @@ public AnalyzePropertyManager getAnalyzePropertyManager()
11511154
return analyzePropertyManager;
11521155
}
11531156

1157+
@Override
1158+
public Optional<FilterApplicationResult> applyFilter(TableHandle table, ConnectorExpression expression)
1159+
{
1160+
// TODO: dispatch to connector that owns "table"
1161+
1162+
1163+
/////////////////////////////////// testing code
1164+
class CustomColumn implements ColumnHandle {
1165+
int id;
1166+
1167+
public CustomColumn(int id)
1168+
{
1169+
this.id = id;
1170+
}
1171+
1172+
@Override
1173+
public int hashCode()
1174+
{
1175+
return id;
1176+
}
1177+
1178+
@Override
1179+
public boolean equals(Object obj)
1180+
{
1181+
return id == ((CustomColumn) obj).id;
1182+
}
1183+
}
1184+
1185+
if (expression instanceof Apply) {
1186+
ColumnHandle column = new CustomColumn(1);
1187+
return Optional.of(new FilterApplicationResult(
1188+
table,
1189+
new ColumnReference(column, BOOLEAN),
1190+
ImmutableList.of(new FilterApplicationResult.Column(column, BOOLEAN))));
1191+
}
1192+
/////////////////////////////////// testing code
1193+
1194+
1195+
return Optional.empty();
1196+
}
1197+
11541198
private ViewDefinition deserializeView(String data)
11551199
{
11561200
try {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.prestosql.spi.expression;
15+
16+
import io.prestosql.spi.type.Type;
17+
18+
import java.util.List;
19+
20+
public class Apply
21+
extends ConnectorExpression
22+
{
23+
private final FunctionId function;
24+
private final List<ConnectorExpression> arguments;
25+
26+
public Apply(Type returnType, FunctionId function, List<ConnectorExpression> arguments)
27+
{
28+
super(returnType);
29+
this.function = function;
30+
this.arguments = arguments;
31+
}
32+
33+
// TODO: this will need to be a FunctionHandle
34+
public FunctionId getFunction()
35+
{
36+
return function;
37+
}
38+
39+
public List<ConnectorExpression> getArguments()
40+
{
41+
return arguments;
42+
}
43+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.prestosql.spi.expression;
15+
16+
import io.prestosql.spi.connector.ColumnHandle;
17+
import io.prestosql.spi.type.Type;
18+
19+
public class ColumnReference
20+
extends ConnectorExpression
21+
{
22+
private final ColumnHandle column;
23+
24+
public ColumnReference(ColumnHandle column, Type type)
25+
{
26+
super(type);
27+
this.column = column;
28+
}
29+
30+
public ColumnHandle getColumn()
31+
{
32+
return column;
33+
}
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.prestosql.spi.expression;
15+
16+
import io.prestosql.spi.type.Type;
17+
18+
public class ConnectorExpression
19+
{
20+
private final Type type;
21+
22+
public ConnectorExpression(Type type)
23+
{
24+
this.type = type;
25+
}
26+
27+
public Type getType()
28+
{
29+
return type;
30+
}
31+
}

0 commit comments

Comments
 (0)