drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [drill] akkapur commented on a change in pull request #1888: DRILL-5956: Add Storage Plugin for Apache Druid
Date Mon, 22 Jun 2020 11:37:32 GMT

akkapur commented on a change in pull request #1888:
URL: https://github.com/apache/drill/pull/1888#discussion_r443496786



##########
File path: contrib/storage-druid/src/main/java/org/apache/drill/exec/store/druid/DruidGroupScan.java
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.druid;
+
+import com.fasterxml.jackson.annotation.JacksonInject;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import org.apache.drill.common.PlanStringBuilder;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.physical.EndpointAffinity;
+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.proto.CoordinationProtos;
+import org.apache.drill.exec.store.StoragePluginRegistry;
+
+import org.apache.drill.exec.store.schedule.AffinityCreator;
+import org.apache.drill.exec.store.schedule.AssignmentCreator;
+import org.apache.drill.exec.store.schedule.CompleteWork;
+import org.apache.drill.exec.store.schedule.EndpointByteMap;
+import org.apache.drill.exec.store.schedule.EndpointByteMapImpl;
+import org.apache.drill.shaded.guava.com.google.common.base.Preconditions;
+import org.apache.drill.shaded.guava.com.google.common.collect.ListMultimap;
+import org.apache.drill.shaded.guava.com.google.common.collect.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@JsonTypeName("druid-scan")
+public class DruidGroupScan extends AbstractGroupScan {
+
+  private static final Logger logger = LoggerFactory.getLogger(DruidGroupScan.class);
+  private static final long DEFAULT_TABLET_SIZE = 1000;
+  private final DruidScanSpec scanSpec;
+  private final DruidStoragePlugin storagePlugin;
+
+  private List<SchemaPath> columns;
+  private boolean filterPushedDown = false;
+  private List<DruidWork> druidWorkList = new ArrayList<>();
+  private ListMultimap<Integer,DruidWork> assignments;
+  private List<EndpointAffinity> affinities;
+
+  @JsonCreator
+  public DruidGroupScan(@JsonProperty("userName") String userName,
+                        @JsonProperty("scanSpec") DruidScanSpec scanSpec,
+                        @JsonProperty("storagePluginConfig") DruidStoragePluginConfig storagePluginConfig,
+                        @JsonProperty("columns") List<SchemaPath> columns,
+                        @JacksonInject StoragePluginRegistry pluginRegistry) {
+    this(userName,
+        pluginRegistry.resolve(storagePluginConfig, DruidStoragePlugin.class),
+        scanSpec,
+        columns);
+  }
+
+  public DruidGroupScan(String userName, DruidStoragePlugin storagePlugin, DruidScanSpec
scanSpec,
+                        List<SchemaPath> columns) {
+    super(userName);
+    this.storagePlugin = storagePlugin;
+    this.scanSpec = scanSpec;
+    this.columns = columns == null || columns.size() == 0? ALL_COLUMNS : columns;
+    init();
+  }
+
+  /**
+   * Private constructor, used for cloning.
+   * @param that The DruidGroupScan to clone
+   */
+  private DruidGroupScan(DruidGroupScan that) {
+    super(that);
+    this.columns = that.columns;
+    this.scanSpec = that.scanSpec;
+    this.storagePlugin = that.storagePlugin;
+    this.filterPushedDown = that.filterPushedDown;
+    this.druidWorkList = that.druidWorkList;
+    this.assignments = that.assignments;
+  }
+
+  @Override
+  public GroupScan clone(List<SchemaPath> columns) {
+    DruidGroupScan newScan = new DruidGroupScan(this);
+    newScan.columns = columns;
+    return newScan;
+  }
+
+  @Override
+  public List<EndpointAffinity> getOperatorAffinity() {
+    if (affinities == null) {
+      affinities = AffinityCreator.getAffinityMap(druidWorkList);
+    }
+    return affinities;
+  }
+
+  @Override
+  public boolean canPushdownProjects(List<SchemaPath> columns) {
+    return true;
+  }
+
+  @JsonIgnore
+  public boolean isFilterPushedDown() {
+    return filterPushedDown;
+  }
+
+  @JsonIgnore
+  public void setFilterPushedDown(boolean filterPushedDown) {
+    this.filterPushedDown = filterPushedDown;
+  }
+
+  private void init() {
+    logger.debug("Adding Druid Work for Table - {}. Filter - {}", getTableName(), getScanSpec().getFilter());
+
+    DruidWork druidWork =
+      new DruidWork(
+        new DruidSubScan.DruidSubScanSpec(
+          getTableName(),
+          getScanSpec().getFilter()
+        )
+      );
+    druidWorkList.add(druidWork);
+  }
+
+  private static class DruidWork implements CompleteWork {
+    private final EndpointByteMapImpl byteMap = new EndpointByteMapImpl();
+    private final DruidSubScan.DruidSubScanSpec druidSubScanSpec;
+
+    public DruidWork(DruidSubScan.DruidSubScanSpec druidSubScanSpec) {
+      this.druidSubScanSpec = druidSubScanSpec;
+    }
+
+    public DruidSubScan.DruidSubScanSpec getDruidSubScanSpec() {
+      return druidSubScanSpec;
+    }
+
+    @Override
+    public long getTotalBytes() {
+      return DEFAULT_TABLET_SIZE;
+    }
+
+    @Override
+    public EndpointByteMap getByteMap() {
+      return byteMap;
+    }
+
+    @Override
+    public int compareTo(CompleteWork o) {
+      return 0;
+    }
+  }
+
+  //TODO - MAY GET MORE PRECISE COUNT FROM DRUID ITSELF.
+  public ScanStats getScanStats() {
+    long recordCount = 100000 * druidWorkList.size();
+    return new ScanStats(
+        ScanStats.GroupScanProperty.NO_EXACT_ROW_COUNT,
+        recordCount,
+        1,
+        recordCount * storagePlugin.getConfig().getAverageRowSizeBytes());
+  }
+
+  @Override
+  public void applyAssignments(List<CoordinationProtos.DrillbitEndpoint> endpoints)
{
+    assignments = AssignmentCreator.getMappings(endpoints, druidWorkList);
+  }
+
+  @Override
+  public DruidSubScan getSpecificScan(int minorFragmentId) {
+
+    List<DruidWork> workList = assignments.get(minorFragmentId);
+
+    List<DruidSubScan.DruidSubScanSpec> scanSpecList = Lists.newArrayList();
+    for (DruidWork druidWork : workList) {
+      scanSpecList
+        .add(
+          new DruidSubScan.DruidSubScanSpec(
+            druidWork.getDruidSubScanSpec().getDataSourceName(),
+            druidWork.getDruidSubScanSpec().getFilter()
+          )
+        );
+    }
+
+    return new DruidSubScan(getUserName(), storagePlugin, scanSpecList, this.columns);
+  }
+
+  @JsonIgnore
+  public String getTableName() {
+    return getScanSpec().getDataSourceName();
+  }
+
+  @Override
+  public int getMaxParallelizationWidth() {
+    return druidWorkList.size();
+  }
+

Review comment:
       I added support for limit push down earlier, could you please check if you are reviewing
the latest on this file.




----------------------------------------------------------------
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:
users@infra.apache.org



Mime
View raw message