cgivre commented on a change in pull request #2089: URL: https://github.com/apache/drill/pull/2089#discussion_r569135503
########## File path: contrib/storage-splunk/src/main/java/org/apache/drill/exec/store/splunk/SplunkGroupScan.java ########## @@ -0,0 +1,320 @@ +/* + * 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.splunk; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.drill.common.PlanStringBuilder; +import org.apache.drill.common.expression.SchemaPath; +import org.apache.drill.exec.physical.base.AbstractGroupScan; +import org.apache.drill.exec.physical.base.GroupScan; +import org.apache.drill.exec.physical.base.PhysicalOperator; +import org.apache.drill.exec.physical.base.ScanStats; +import org.apache.drill.exec.physical.base.SubScan; +import org.apache.drill.exec.planner.logical.DrillScanRel; +import org.apache.drill.exec.proto.CoordinationProtos; +import org.apache.drill.exec.store.base.filter.ExprNode; +import org.apache.drill.exec.util.Utilities; +import org.apache.drill.shaded.guava.com.google.common.base.Preconditions; + +import java.util.List; +import java.util.Map; +import java.util.Objects; + +public class SplunkGroupScan extends AbstractGroupScan { + + private final SplunkPluginConfig config; + private final List<SchemaPath> columns; + private final SplunkScanSpec splunkScanSpec; + private final Map<String, ExprNode.ColRelOpConstNode> filters; + private final ScanStats scanStats; + private final double filterSelectivity; + private final int maxRecords; + + private int hashCode; + + /** + * Creates a new group scan from the storage plugin. + */ + public SplunkGroupScan (SplunkScanSpec scanSpec) { + super("no-user"); + this.splunkScanSpec = scanSpec; + this.config = scanSpec.getConfig(); + this.columns = ALL_COLUMNS; + this.filters = null; + this.filterSelectivity = 0.0; + this.maxRecords = -1; + this.scanStats = computeScanStats(); + + } + + /** + * Copies the group scan during many stages of Calcite operation. + */ + public SplunkGroupScan(SplunkGroupScan that) { + super(that); + this.config = that.config; + this.splunkScanSpec = that.splunkScanSpec; + this.columns = that.columns; + this.filters = that.filters; + this.filterSelectivity = that.filterSelectivity; + this.maxRecords = that.maxRecords; + + // Calcite makes many copies in the later stage of planning + // without changing anything. Retain the previous stats. + this.scanStats = that.scanStats; + } + + /** + * Applies columns. Oddly called multiple times, even when + * the scan already has columns. + */ + public SplunkGroupScan(SplunkGroupScan that, List<SchemaPath> columns) { + super(that); + this.columns = columns; + this.splunkScanSpec = that.splunkScanSpec; + this.config = that.config; + + // Oddly called later in planning, after earlier assigning columns, + // to again assign columns. Retain filters, but compute new stats. + this.filters = that.filters; + this.filterSelectivity = that.filterSelectivity; + this.maxRecords = that.maxRecords; + this.scanStats = computeScanStats(); + + } + + /** + * Adds a filter to the scan. + */ + public SplunkGroupScan(SplunkGroupScan that, Map<String, ExprNode.ColRelOpConstNode> filters, + double filterSelectivity) { + super(that); + this.columns = that.columns; + this.splunkScanSpec = that.splunkScanSpec; + this.config = that.config; + + // Applies a filter. + this.filters = filters; + this.filterSelectivity = filterSelectivity; + this.maxRecords = that.maxRecords; + this.scanStats = computeScanStats(); + } + + /** + * Deserialize a group scan. Not called in normal operation. Probably used + * only if Drill executes a logical plan. + */ + @JsonCreator + public SplunkGroupScan( + @JsonProperty("config") SplunkPluginConfig config, + @JsonProperty("columns") List<SchemaPath> columns, + @JsonProperty("splunkScanSpec") SplunkScanSpec splunkScanSpec, + @JsonProperty("filters") Map<String, ExprNode.ColRelOpConstNode> filters, + @JsonProperty("filterSelectivity") double selectivity, + @JsonProperty("maxRecords") int maxRecords + ) { + super("no-user"); + this.config = config; + this.columns = columns; + this.splunkScanSpec = splunkScanSpec; + this.filters = filters; + this.filterSelectivity = selectivity; + this.maxRecords = maxRecords; + this.scanStats = computeScanStats(); + } + + /** + * Adds a limit to the group scan + * @param that Previous SplunkGroupScan + * @param maxRecords the limit pushdown + */ + public SplunkGroupScan(SplunkGroupScan that, int maxRecords) { + super(that); + this.columns = that.columns; + // Apply the limit + this.maxRecords = maxRecords; + this.splunkScanSpec = that.splunkScanSpec; + this.config = that.config; + this.filters = that.filters; + this.filterSelectivity = that.filterSelectivity; + this.scanStats = computeScanStats(); + } + + @JsonProperty("config") + public SplunkPluginConfig config() { return config; } + + @JsonProperty("columns") + public List<SchemaPath> columns() { return columns; } + + @JsonProperty("splunkScanSpec") + public SplunkScanSpec splunkScanSpec() { return splunkScanSpec; } + + @JsonProperty("filters") + public Map<String, ExprNode.ColRelOpConstNode> filters() { return filters; } + + @JsonProperty("maxRecords") + public int maxRecords() { return maxRecords; } + + @JsonProperty("filterSelectivity") + public double selectivity() { return filterSelectivity; } + + + @Override + public void applyAssignments(List<CoordinationProtos.DrillbitEndpoint> endpoints) { } + + @Override + public SubScan getSpecificScan(int minorFragmentId) { + return new SplunkSubScan(config, splunkScanSpec, columns, filters, maxRecords); + } + + @Override + public int getMaxParallelizationWidth() { + return 1; Review comment: It may be possible. I'm uncertain as to whether or not there would be a performance advantage or not. In theory you could break up queries with `OR` filters and send them to different search heads. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
