cgivre commented on code in PR #2585: URL: https://github.com/apache/drill/pull/2585#discussion_r924455886
########## contrib/storage-googlesheets/src/main/java/org/apache/drill/exec/store/googlesheets/GoogleSheetsPushDownListener.java: ########## @@ -0,0 +1,149 @@ +/* + * 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.drill.exec.store.googlesheets; + +import org.apache.calcite.rex.RexNode; +import org.apache.calcite.util.Pair; +import org.apache.drill.common.expression.SchemaPath; +import org.apache.drill.common.map.CaseInsensitiveMap; +import org.apache.drill.common.types.TypeProtos.MinorType; +import org.apache.drill.exec.ops.OptimizerRulesContext; +import org.apache.drill.exec.physical.base.GroupScan; +import org.apache.drill.exec.store.StoragePluginOptimizerRule; +import org.apache.drill.exec.store.base.filter.ExprNode; +import org.apache.drill.exec.store.base.filter.ExprNode.AndNode; +import org.apache.drill.exec.store.base.filter.ExprNode.ColRelOpConstNode; +import org.apache.drill.exec.store.base.filter.ExprNode.OrNode; +import org.apache.drill.exec.store.base.filter.FilterPushDownListener; +import org.apache.drill.exec.store.base.filter.FilterPushDownStrategy; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * The GoogleSheets storage plugin accepts filters which are: + * <ul> + * <li>A single column = value expression </li> + * <li>An AND'ed set of such expressions,</li> + * <li>If the value is one with an unambiguous conversion to + * a string. (That is, not dates, binary, maps, etc.)</li> + * </ul> + */ +public class GoogleSheetsPushDownListener implements FilterPushDownListener { + + public static Set<StoragePluginOptimizerRule> rulesFor(OptimizerRulesContext optimizerRulesContext) { + return FilterPushDownStrategy.rulesFor(new GoogleSheetsPushDownListener()); + } + + @Override + public String prefix() { + return "GoogleSheets"; + } + + @Override + public boolean isTargetScan(GroupScan groupScan) { + return groupScan instanceof GoogleSheetsGroupScan; + } + + @Override + public ScanPushDownListener builderFor(GroupScan groupScan) { + GoogleSheetsGroupScan gsScan = (GoogleSheetsGroupScan) groupScan; + if (gsScan.hasFilters() || !gsScan.allowsFilters()) { + return null; + } else { + return new GoogleSheetsScanPushDownListener(gsScan); + } + } + + private static class GoogleSheetsScanPushDownListener implements ScanPushDownListener { + + private final GoogleSheetsGroupScan groupScan; + private final Map<String, String> filterParams = CaseInsensitiveMap.newHashMap(); + + GoogleSheetsScanPushDownListener(GoogleSheetsGroupScan groupScan) { + this.groupScan = groupScan; + for (SchemaPath field : groupScan.columns()) { + filterParams.put(field.getAsUnescapedPath(), field.getAsUnescapedPath()); + } + } + + @Override + public ExprNode accept(ExprNode node) { + if (node instanceof OrNode) { + return null; + } else if (node instanceof ColRelOpConstNode) { + return null; + //return acceptRelOp((ColRelOpConstNode) node); + } else { + return null; + } Review Comment: For now yes. If we can figure out how to use the Google SDK for filter pushdowns, we should uncomment out that line. I'll add a comment there, explaining. I'll do my best to keep the snark factor low, but no promises. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@drill.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org