You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by parthchandra <gi...@git.apache.org> on 2017/11/10 17:46:13 UTC

[GitHub] drill pull request #914: DRILL-5657: Size-aware vector writer structure

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

    https://github.com/apache/drill/pull/914#discussion_r149759147
  
    --- Diff: exec/vector/src/main/codegen/templates/ColumnAccessors.java ---
    @@ -191,141 +180,268 @@ public void bind(RowIndex vectorIndex, ValueVector vector) {
         <#if accessorType=="BigDecimal">
           <#assign label="Decimal">
         </#if>
    +    <#if drillType == "VarChar" || drillType == "Var16Char">
    +      <#assign accessorType = "byte[]">
    +      <#assign label = "Bytes">
    +    </#if>
         <#if ! notyet>
       //------------------------------------------------------------------------
       // ${drillType} readers and writers
     
    -  public static class ${drillType}ColumnReader extends AbstractColumnReader {
    +  public static class ${drillType}ColumnReader extends BaseScalarReader {
     
    -    <@bindReader "" drillType />
    +    <@bindReader "" drillType false />
     
    -    <@getType label />
    +    <@getType drillType label />
     
         <@get drillType accessorType label false/>
       }
     
    -  public static class Nullable${drillType}ColumnReader extends AbstractColumnReader {
    +  public static class Nullable${drillType}ColumnReader extends BaseScalarReader {
     
    -    <@bindReader "Nullable" drillType />
    +    <@bindReader "Nullable" drillType false />
     
    -    <@getType label />
    +    <@getType drillType label />
     
         @Override
         public boolean isNull() {
    -      return accessor().isNull(vectorIndex.index());
    -    }
    -
    -    <@get drillType accessorType label false/>
    -  }
    -
    -  public static class Repeated${drillType}ColumnReader extends AbstractArrayReader {
    -
    -    <@bindReader "Repeated" drillType />
    -
    -    <@getType label />
    -
    -    @Override
    -    public int size() {
    -      return accessor().getInnerValueCountAt(vectorIndex.index());
    +      return accessor().isNull(vectorIndex.vectorIndex());
         }
     
    -    <@get drillType accessorType label true/>
    +    <@get drillType accessorType label false />
       }
     
    -  public static class ${drillType}ColumnWriter extends AbstractColumnWriter {
    +  public static class Repeated${drillType}ColumnReader extends BaseElementReader {
     
    -    <@bindWriter "" drillType />
    +    <@bindReader "" drillType true />
     
    -    <@getType label />
    +    <@getType drillType label />
     
    -    <@set drillType accessorType label false "set" />
    +    <@get drillType accessorType label true />
       }
     
    -  public static class Nullable${drillType}ColumnWriter extends AbstractColumnWriter {
    -
    -    <@bindWriter "Nullable" drillType />
    +      <#assign varWidth = drillType == "VarChar" || drillType == "Var16Char" || drillType == "VarBinary" />
    +      <#if varWidth>
    +  public static class ${drillType}ColumnWriter extends BaseVarWidthWriter {
    +      <#else>
    +  public static class ${drillType}ColumnWriter extends BaseFixedWidthWriter {
    +        <#if drillType = "Decimal9" || drillType == "Decimal18" ||
    +             drillType == "Decimal28Sparse" || drillType == "Decimal38Sparse">
    +    private MajorType type;
    +        </#if>
    +    private static final int VALUE_WIDTH = ${drillType}Vector.VALUE_WIDTH;
    +      </#if>
    +    private final ${drillType}Vector vector;
    +
    +    public ${drillType}ColumnWriter(final ValueVector vector) {
    +      <#if varWidth>
    +      super(((${drillType}Vector) vector).getOffsetVector());
    +      <#else>
    +        <#if drillType = "Decimal9" || drillType == "Decimal18" ||
    +             drillType == "Decimal28Sparse" || drillType == "Decimal38Sparse">
    +      type = vector.getField().getType();
    +        </#if>
    +      </#if>
    +      this.vector = (${drillType}Vector) vector;
    +    }
     
    -    <@getType label />
    +    @Override public ValueVector vector() { return vector; }
     
    +        <#-- All change of buffer comes through this function to allow capturing
    +             the buffer address and capacity. Only two ways to set the buffer:
    +             by binding to a vector in bindVector(), or by resizing the vector
    +             in writeIndex(). -->
         @Override
    -    public void setNull() {
    -      mutator.setNull(vectorIndex.index());
    +    protected final void setAddr() {
    +      final DrillBuf buf = vector.getBuffer();
    +      bufAddr = buf.addr();
    +          <#if varWidth>
    +      capacity = buf.capacity();
    +          <#else>
    +          <#-- Turns out that keeping track of capacity as the count of
    +               values simplifies the per-value code path. -->
    +      capacity = buf.capacity() / VALUE_WIDTH;
    +          </#if>
         }
     
    -    <@set drillType accessorType label true "set" />
    -  }
    -
    -  public static class Repeated${drillType}ColumnWriter extends AbstractArrayWriter {
    -
    -    <@bindWriter "Repeated" drillType />
    +        <#-- reallocRaw() is type specific. -->
    +    @Override
    +    protected void realloc(int size) {
    +      vector.reallocRaw(size);
    +      setAddr();
    +    }
     
    -    <@getType label />
    +       <#if ! varWidth>
    +    @Override public int width() { return VALUE_WIDTH; }
    +
    +      </#if>
    +    <@getType drillType label />
    +
    +      <#if accessorType == "byte[]">
    +        <#assign args = ", int len">
    +      <#else>
    +        <#assign args = "">
    +      </#if>
    +      <#if javaType == "char">
    +        <#assign putType = "short" />
    +        <#assign doCast = true />
    +      <#else>
    +        <#assign putType = javaType />
    +        <#assign doCast = (cast == "set") />
    +      </#if>
    +      <#if ! varWidth>
    +    @Override
    +    protected final void fillEmpties(final int writeIndex) {
    +      <#-- Fill empties. This is required because the allocated memory is not
    +           zero-filled. -->
    +      while (lastWriteIndex < writeIndex - 1) {
    --- End diff --
    
    Can this be done without a for loop using PlatformDependent.copyMemory? 


---