arina-ielchiieva commented on a change in pull request #1914: DRILL-7458: Base framework for storage plugins URL: https://github.com/apache/drill/pull/1914#discussion_r368564963
########## File path: exec/java-exec/src/test/java/org/apache/drill/exec/store/base/DummyGroupScan.java ########## @@ -0,0 +1,214 @@ +/* + * 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.base; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.drill.common.expression.SchemaPath; +import org.apache.drill.common.types.TypeProtos.MinorType; +import org.apache.drill.exec.physical.base.ScanStats; +import org.apache.drill.exec.physical.base.ScanStats.GroupScanProperty; +import org.apache.drill.exec.physical.base.SubScan; +import org.apache.drill.exec.store.StoragePluginRegistry; +import org.apache.drill.exec.store.base.filter.FilterSpec; +import org.apache.drill.exec.store.base.filter.RelOp; +import org.apache.drill.shaded.guava.com.google.common.base.Preconditions; +import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList; + +import com.fasterxml.jackson.annotation.JacksonInject; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonTypeName; + +@JsonTypeName("dummy-scan") +@JsonPropertyOrder({"userName", "scanSpec", "columns", + "filters", "cost", "config"}) +@JsonInclude(value=Include.NON_EMPTY, content=Include.NON_NULL) +public class DummyGroupScan extends BaseGroupScan { + + private final DummyScanSpec scanSpec; + private final FilterSpec filters; + + public DummyGroupScan(DummyStoragePlugin storagePlugin, String userName, + DummyScanSpec scanSpec) { + super(storagePlugin, userName, null); + this.scanSpec = scanSpec; + filters = null; + } + + public DummyGroupScan(DummyGroupScan from, List<SchemaPath> columns) { + super(from.storagePlugin, from.getUserName(), columns); + this.scanSpec = from.scanSpec; + this.filters = from.filters; + } + + @JsonCreator + public DummyGroupScan( + @JsonProperty("config") DummyStoragePluginConfig config, + @JsonProperty("userName") String userName, + @JsonProperty("scanSpec") DummyScanSpec scanSpec, + @JsonProperty("columns") List<SchemaPath> columns, + @JsonProperty("filters") FilterSpec filters, + @JacksonInject StoragePluginRegistry engineRegistry) { + super(config, userName, columns, engineRegistry); + this.scanSpec = scanSpec; + this.filters = filters; + } + + public DummyGroupScan(DummyGroupScan from, FilterSpec filters) { + super(from); + this.scanSpec = from.scanSpec; + this.filters = filters; + } + + @JsonProperty("scanSpec") + public DummyScanSpec scanSpec() { return scanSpec; } + + @JsonProperty("filters") + public FilterSpec andFilters() { return filters; } + + public boolean hasFilters() { + return filters != null && ! filters.isEmpty(); + } + + private static final List<String> FILTER_COLS = ImmutableList.of("a", "b", "id"); + + public RelOp acceptFilter(RelOp relOp) { + + // Pretend that "id" is a special integer column. Can handle + // equality only. + + if (relOp.colName.contentEquals("id")) { + + // To allow easier testing, require exact type match: no + // attempt at type conversion here. + + if (relOp.op != RelOp.Op.EQ || relOp.value.type != MinorType.INT) { + return null; + } + return relOp; + } + + // All other columns apply only if projected + + if (!FILTER_COLS.contains(relOp.colName)) { + return null; + } + + // Only supports a few operators so we can verify that the + // others are left in the WHERE clause. + // Neither are really implemented. Less-than lets us check + // inverting operations for the const op col case. + + switch (relOp.op) { + case EQ: + case LT: + case LE: + + // Convert to target type (pretend all columns are VARCHAR) + + return relOp.normalize(relOp.value.toVarChar()); + case IS_NULL: + case IS_NOT_NULL: + return relOp; + default: + return null; + } + } + +// private boolean hasColumn(String colName) { Review comment: Please remove if not needed ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services