drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben-Zvi <...@git.apache.org>
Subject [GitHub] drill pull request #860: DRILL-5601: Rollup of external sort fixes and impro...
Date Thu, 13 Jul 2017 22:21:17 GMT
Github user Ben-Zvi commented on a diff in the pull request:

    https://github.com/apache/drill/pull/860#discussion_r127071648
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/record/SmartAllocationHelper.java
---
    @@ -0,0 +1,156 @@
    +/*
    + * 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.record;
    +
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +
    +import org.apache.drill.exec.vector.AllocationHelper;
    +import org.apache.drill.exec.vector.ValueVector;
    +import org.apache.drill.exec.vector.complex.AbstractMapVector;
    +import org.apache.drill.exec.vector.complex.RepeatedMapVector;
    +
    +/**
    + * Prototype mechanism to allocate vectors based on expected
    + * data sizes. This version uses a name-based map of fields
    + * to sizes. Better to represent the batch structurally and
    + * simply iterate over the schema rather than doing a per-field
    + * lookup. But, the mechanisms needed to do the efficient solution
    + * don't exist yet.
    + */
    +
    +public class SmartAllocationHelper {
    +
    +  public static class AllocationHint {
    +    public final int entryWidth;
    +    public final int elementCount;
    +
    +    private AllocationHint(int width, int elements) {
    +      entryWidth = width;
    +      elementCount = elements;
    +    }
    +
    +    @Override
    +    public String toString() {
    +      StringBuilder buf = new StringBuilder()
    +          .append("{");
    +      boolean comma = false;
    +      if (entryWidth > 0) {
    +        buf.append("width=")
    +           .append(entryWidth);
    +        comma = true;
    +      }
    +      if (elementCount > 0) {
    +        if (comma) {
    +          buf.append(", ");
    +        }
    +        buf.append("elements=")
    +        .append(elementCount);
    +      }
    +      buf.append("}");
    +      return buf.toString();
    +    }
    +  }
    +
    +  private Map<String, AllocationHint> hints = new HashMap<>();
    +
    +  public void variableWidth(String name, int width) {
    +    hints.put(name, new AllocationHint(width, 1));
    +  }
    +
    +  public void fixedWidthArray(String name, int elements) {
    +    hints.put(name, new AllocationHint(0, elements));
    +  }
    +
    +  public void variableWidthArray(String name, int width, int elements) {
    +    hints.put(name, new AllocationHint(width, elements));
    +  }
    +
    +  public void allocateBatch(VectorAccessible va, int recordCount) {
    +    for (VectorWrapper<?> w: va) {
    +      allocateVector(w.getValueVector(), "", recordCount);
    +    }
    +  }
    +
    +  private void allocateVector(ValueVector vector, String prefix, int recordCount) {
    --- End diff --
    
    Can this method be renamed to **allocateVectorOrMap()** ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message