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:35:52 GMT

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



##########
File path: contrib/storage-druid/src/main/java/org/apache/drill/exec/store/druid/DruidRecordReader.java
##########
@@ -0,0 +1,193 @@
+/*
+ * 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.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.ops.FragmentContext;
+import org.apache.drill.exec.ops.OperatorContext;
+import org.apache.drill.exec.physical.impl.OutputMutator;
+import org.apache.drill.exec.store.AbstractRecordReader;
+import org.apache.drill.exec.store.druid.common.DruidFilter;
+import org.apache.drill.exec.store.druid.druid.DruidSelectResponse;
+import org.apache.drill.exec.store.druid.druid.PagingIdentifier;
+import org.apache.drill.exec.store.druid.druid.PagingSpec;
+import org.apache.drill.exec.store.druid.druid.SelectQuery;
+import org.apache.drill.exec.store.druid.druid.SelectQueryBuilder;
+import org.apache.drill.exec.store.druid.rest.DruidQueryClient;
+import org.apache.drill.exec.vector.BaseValueVector;
+import org.apache.drill.exec.vector.complex.fn.JsonReader;
+import org.apache.drill.exec.vector.complex.impl.VectorContainerWriter;
+import org.apache.drill.shaded.guava.com.google.common.base.Stopwatch;
+import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableList;
+import org.apache.drill.shaded.guava.com.google.common.collect.Sets;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+public class DruidRecordReader extends AbstractRecordReader {
+
+  private static final Logger logger = LoggerFactory.getLogger(DruidRecordReader.class);
+  private static final ObjectMapper objectMapper = new ObjectMapper();
+  private final DruidStoragePlugin plugin;
+  private final DruidSubScan.DruidSubScanSpec scanSpec;
+  private final List<String> dimensions;
+  private final DruidFilter filter;
+  private ArrayList<PagingIdentifier> pagingIdentifiers = new ArrayList<>();
+  private int maxRecordsToRead = -1;
+
+  private JsonReader jsonReader;
+  private VectorContainerWriter writer;
+
+  private final FragmentContext fragmentContext;
+
+  public DruidRecordReader(DruidSubScan.DruidSubScanSpec subScanSpec,
+                           List<SchemaPath> projectedColumns,
+                           int maxRecordsToRead,
+                           FragmentContext context,
+                           DruidStoragePlugin plugin) {
+    dimensions = new ArrayList<>();
+    setColumns(projectedColumns);
+    this.maxRecordsToRead = maxRecordsToRead;
+    this.plugin = plugin;
+    scanSpec = subScanSpec;
+    fragmentContext = context;
+    this.filter = subScanSpec.getFilter();
+  }
+
+  @Override
+  protected Collection<SchemaPath> transformColumns(Collection<SchemaPath> projectedColumns)
{
+    Set<SchemaPath> transformed = Sets.newLinkedHashSet();
+    if (isStarQuery()) {
+      transformed.add(SchemaPath.STAR_COLUMN);
+    } else {
+      for (SchemaPath column : projectedColumns) {
+        String fieldName = column.getRootSegment().getPath();
+        transformed.add(column);
+        this.dimensions.add(fieldName);
+      }
+    }
+    return transformed;
+  }
+
+  @Override
+  public void setup(OperatorContext context, OutputMutator output) {
+    this.writer = new VectorContainerWriter(output);
+
+    this.jsonReader =
+      new JsonReader.Builder(fragmentContext.getManagedBuffer())
+        .schemaPathColumns(ImmutableList.copyOf(getColumns()))
+        .skipOuterList(true)
+        .build();
+  }
+
+  @Override
+  public int next() {
+    writer.allocate();
+    writer.reset();
+    DruidQueryClient druidQueryClient = plugin.getDruidQueryClient();

Review comment:
       Fixed.




----------------------------------------------------------------
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