Github user maryannxue commented on a diff in the pull request:
https://github.com/apache/incubator-phoenix/pull/31#discussion_r11866024
--- Diff:
phoenix-core/src/main/java/org/apache/phoenix/compile/SubselectRewriter.java ---
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.compile;
+
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.phoenix.jdbc.PhoenixConnection;
+import org.apache.phoenix.parse.AliasedNode;
+import org.apache.phoenix.parse.ColumnParseNode;
+import org.apache.phoenix.parse.DerivedTableNode;
+import org.apache.phoenix.parse.HintNode;
+import org.apache.phoenix.parse.LimitNode;
+import org.apache.phoenix.parse.OrderByNode;
+import org.apache.phoenix.parse.ParseNode;
+import org.apache.phoenix.parse.ParseNodeRewriter;
+import org.apache.phoenix.parse.SelectStatement;
+import org.apache.phoenix.parse.TableNode;
+import org.apache.phoenix.parse.TableWildcardParseNode;
+import org.apache.phoenix.parse.WildcardParseNode;
+import org.apache.phoenix.util.SchemaUtil;
+
+import com.google.common.collect.Lists;
+
+public class SubselectRewriter extends ParseNodeRewriter {
+ private final String tableAlias;
+ private final Map<String, ParseNode> aliasMap;
+
+ public static SelectStatement applyPostFilters(SelectStatement
statement, List<ParseNode> postFilters, String subqueryAlias) throws
SQLException {
+ if (postFilters.isEmpty())
+ return statement;
+
+ // TODO handle this from caller
+ if (statement.getLimit() != null || (statement.isAggregate() &&
statement.getGroupBy().isEmpty()))
--- End diff --
This applyPostFilter() method is for subqueries in joins. We can have some
conditions in ON clause or WHERE clause to be pushed down into individual join
tables, and if the join table is a subquery, we call this method to merge this
post-filter into the subquery, as a WHERE condition or a HAVING condition so
that in some cases these post-filters can be optimized as pre-filters.
Those cases that would throw exceptions from here are very rare, basically
like:
1) select ... from A join (select id, b from T limit 10) as B on A.id =
B.id where B.b = 'b'
2) select ... from A join (select count(*) c from T) as B on A.a = B.c
where B.c > 10
However, this post-filter can be easily handled in joins. I will make
another check-in later.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---