[ 
https://issues.apache.org/jira/browse/DRILL-3232?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14983212#comment-14983212
 ] 

ASF GitHub Bot commented on DRILL-3232:
---------------------------------------

Github user StevenMPhillips commented on a diff in the pull request:

    https://github.com/apache/drill/pull/207#discussion_r43546612
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/ListVector.java
 ---
    @@ -0,0 +1,390 @@
    
+/*******************************************************************************
    +
    + * 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.vector.complex;
    +
    +import com.google.common.collect.ObjectArrays;
    +import io.netty.buffer.DrillBuf;
    +import org.apache.drill.common.expression.FieldReference;
    +import org.apache.drill.common.expression.PathSegment;
    +import org.apache.drill.common.types.TypeProtos.DataMode;
    +import org.apache.drill.common.types.TypeProtos.MinorType;
    +import org.apache.drill.common.types.Types;
    +import org.apache.drill.exec.memory.BufferAllocator;
    +import org.apache.drill.exec.memory.OutOfMemoryRuntimeException;
    +import org.apache.drill.exec.proto.UserBitShared;
    +import org.apache.drill.exec.record.MaterializedField;
    +import org.apache.drill.exec.record.TransferPair;
    +import org.apache.drill.exec.record.TypedFieldId;
    +import org.apache.drill.exec.util.CallBack;
    +import org.apache.drill.exec.util.JsonStringArrayList;
    +import org.apache.drill.exec.vector.AddOrGetResult;
    +import org.apache.drill.exec.vector.BaseValueVector;
    +import org.apache.drill.exec.vector.UInt1Vector;
    +import org.apache.drill.exec.vector.UInt4Vector;
    +import org.apache.drill.exec.vector.ValueVector;
    +import org.apache.drill.exec.vector.VectorDescriptor;
    +import org.apache.drill.exec.vector.ZeroVector;
    +import org.apache.drill.exec.vector.complex.impl.ComplexCopier;
    +import org.apache.drill.exec.vector.complex.impl.UnionListReader;
    +import org.apache.drill.exec.vector.complex.impl.UnionListWriter;
    +import org.apache.drill.exec.vector.complex.impl.UnionVector;
    +import org.apache.drill.exec.vector.complex.reader.FieldReader;
    +import org.apache.drill.exec.vector.complex.writer.FieldWriter;
    +
    +import java.util.List;
    +
    +public class ListVector extends BaseRepeatedValueVector {
    +
    +  private UInt4Vector offsets;
    +  private final UInt1Vector bits;
    +  private Mutator mutator = new Mutator();
    +  private Accessor accessor = new Accessor();
    +  private UnionListWriter writer;
    +  private UnionListReader reader;
    +  private CallBack callBack;
    +
    +  public ListVector(MaterializedField field, BufferAllocator allocator, 
CallBack callBack) {
    +    super(field, allocator);
    +    this.bits = new UInt1Vector(MaterializedField.create("$bits$", 
Types.required(MinorType.UINT1)), allocator);
    +    offsets = getOffsetVector();
    +    this.field.addChild(getDataVector().getField());
    +    this.writer = new UnionListWriter(this);
    +    this.reader = new UnionListReader(this);
    +    this.callBack = callBack;
    +  }
    +
    +  public UnionListWriter getWriter() {
    +    return writer;
    +  }
    +
    +  @Override
    +  public void allocateNew() throws OutOfMemoryRuntimeException {
    +    super.allocateNewSafe();
    +  }
    +
    +  public void transferTo(ListVector target) {
    +    offsets.makeTransferPair(target.offsets).transfer();
    +    bits.makeTransferPair(target.bits).transfer();
    +    if (target.getDataVector() instanceof ZeroVector) {
    +      target.addOrGetVector(new 
VectorDescriptor(vector.getField().getType()));
    +    }
    +    getDataVector().makeTransferPair(target.getDataVector()).transfer();
    +  }
    +
    +  public void copyFromSafe(int inIndex, int outIndex, ListVector from) {
    +    copyFrom(inIndex, outIndex, from);
    +  }
    +
    +  public void copyFrom(int inIndex, int outIndex, ListVector from) {
    +    FieldReader in = from.getReader();
    +    in.setPosition(inIndex);
    +    FieldWriter out = getWriter();
    +    out.setPosition(outIndex);
    +    ComplexCopier copier = new ComplexCopier(in, out);
    +    copier.write();
    +  }
    +
    +  @Override
    +  public ValueVector getDataVector() {
    +    return vector;
    +  }
    +
    +  @Override
    +  public TransferPair getTransferPair(FieldReference ref) {
    +    return new TransferImpl(field.withPath(ref));
    +  }
    +
    +  @Override
    +  public TransferPair makeTransferPair(ValueVector target) {
    +    return new TransferImpl((ListVector) target);
    +  }
    +
    +  private class TransferImpl implements TransferPair {
    +
    +    ListVector to;
    +
    +    public TransferImpl(MaterializedField field) {
    +      to = new ListVector(field, allocator, null);
    +      to.addOrGetVector(new VectorDescriptor(vector.getField().getType()));
    +    }
    +
    +    public TransferImpl(ListVector to) {
    +      this.to = to;
    +      to.addOrGetVector(new VectorDescriptor(vector.getField().getType()));
    +    }
    +
    +    @Override
    +    public void transfer() {
    +      transferTo(to);
    +    }
    +
    +    @Override
    +    public void splitAndTransfer(int startIndex, int length) {
    +
    +    }
    +
    +    @Override
    +    public ValueVector getTo() {
    +      return to;
    +    }
    +
    +    @Override
    +    public void copyValueSafe(int from, int to) {
    +      this.to.copyFrom(from, to, ListVector.this);
    +    }
    +  }
    +
    +  @Override
    +  public Accessor getAccessor() {
    +    return accessor;
    +  }
    +
    +  @Override
    +  public Mutator getMutator() {
    +    return mutator;
    +  }
    +
    +  @Override
    +  public FieldReader getReader() {
    +    return reader;
    +  }
    +
    +  @Override
    +  public boolean allocateNewSafe() {
    +    /* boolean to keep track if all the memory allocation were successful
    +     * Used in the case of composite vectors when we need to allocate 
multiple
    +     * buffers for multiple vectors. If one of the allocations failed we 
need to
    +     * clear all the memory that we allocated
    +     */
    +    boolean success = false;
    +    try {
    +      if (!offsets.allocateNewSafe()) {
    +        return false;
    +      }
    +      success = vector.allocateNewSafe();
    +      success = success && bits.allocateNewSafe();
    +    } finally {
    +      if (!success) {
    +        clear();
    +      }
    +    }
    +    offsets.zeroVector();
    --- End diff --
    
    Do you mean we should NOT call these if we fail to allocate?


> Modify existing vectors to allow type promotion
> -----------------------------------------------
>
>                 Key: DRILL-3232
>                 URL: https://issues.apache.org/jira/browse/DRILL-3232
>             Project: Apache Drill
>          Issue Type: Sub-task
>          Components: Execution - Codegen, Execution - Data Types, Execution - 
> Relational Operators, Functions - Drill
>            Reporter: Steven Phillips
>            Assignee: Hanifi Gunes
>             Fix For: 1.3.0
>
>
> Support the ability for existing vectors to be promoted similar to supported 
> implicit casting rules.
> For example:
> INT > DOUBLE > STRING > EMBEDDED



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to