drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #805: Drill-4139: Exception while trying to prune partiti...
Date Tue, 11 Jul 2017 00:16:55 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/805#discussion_r126565179
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetGroupScan.java
---
    @@ -444,123 +478,235 @@ public MajorType getTypeForColumn(SchemaPath schemaPath) {
     
       public void populatePruningVector(ValueVector v, int index, SchemaPath column, String
file) {
         String f = Path.getPathWithoutSchemeAndAuthority(new Path(file)).toString();
    -    MinorType type = getTypeForColumn(column).getMinorType();
    +    MajorType majorType = getTypeForColumn(column);
    +    MinorType type = majorType.getMinorType();
         switch (type) {
    +      case BIT: {
    +        NullableBitVector bitVector = (NullableBitVector) v;
    +        Boolean value = (Boolean) partitionValueMap.get(f).get(column);
    +        if (value == null) {
    +          bitVector.getMutator().setNull(index);
    +        } else {
    +          bitVector.getMutator().setSafe(index, value ? 1 : 0);
    +        }
    +        return;
    +      }
           case INT: {
             NullableIntVector intVector = (NullableIntVector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        intVector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          intVector.getMutator().setNull(index);
    +        } else {
    +          intVector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case SMALLINT: {
             NullableSmallIntVector smallIntVector = (NullableSmallIntVector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        smallIntVector.getMutator().setSafe(index, value.shortValue());
    +        if (value == null) {
    +          smallIntVector.getMutator().setNull(index);
    +        } else {
    +          smallIntVector.getMutator().setSafe(index, value.shortValue());
    +        }
             return;
           }
           case TINYINT: {
             NullableTinyIntVector tinyIntVector = (NullableTinyIntVector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        tinyIntVector.getMutator().setSafe(index, value.byteValue());
    +        if (value == null) {
    +          tinyIntVector.getMutator().setNull(index);
    +        } else {
    +          tinyIntVector.getMutator().setSafe(index, value.byteValue());
    +        }
             return;
           }
           case UINT1: {
             NullableUInt1Vector intVector = (NullableUInt1Vector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        intVector.getMutator().setSafe(index, value.byteValue());
    +        if (value == null) {
    +          intVector.getMutator().setNull(index);
    +        } else {
    +          intVector.getMutator().setSafe(index, value.byteValue());
    +        }
             return;
           }
           case UINT2: {
             NullableUInt2Vector intVector = (NullableUInt2Vector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        intVector.getMutator().setSafe(index, (char) value.shortValue());
    +        if (value == null) {
    +          intVector.getMutator().setNull(index);
    +        } else {
    +          intVector.getMutator().setSafe(index, (char) value.shortValue());
    +        }
             return;
           }
           case UINT4: {
             NullableUInt4Vector intVector = (NullableUInt4Vector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        intVector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          intVector.getMutator().setNull(index);
    +        } else {
    +          intVector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case BIGINT: {
             NullableBigIntVector bigIntVector = (NullableBigIntVector) v;
             Long value = (Long) partitionValueMap.get(f).get(column);
    -        bigIntVector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          bigIntVector.getMutator().setNull(index);
    +        } else {
    +          bigIntVector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case FLOAT4: {
             NullableFloat4Vector float4Vector = (NullableFloat4Vector) v;
             Float value = (Float) partitionValueMap.get(f).get(column);
    -        float4Vector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          float4Vector.getMutator().setNull(index);
    +        } else {
    +          float4Vector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case FLOAT8: {
             NullableFloat8Vector float8Vector = (NullableFloat8Vector) v;
             Double value = (Double) partitionValueMap.get(f).get(column);
    -        float8Vector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          float8Vector.getMutator().setNull(index);
    +        } else {
    +          float8Vector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case VARBINARY: {
             NullableVarBinaryVector varBinaryVector = (NullableVarBinaryVector) v;
             Object s = partitionValueMap.get(f).get(column);
             byte[] bytes;
    -        if (s instanceof Binary) {
    -          bytes = ((Binary) s).getBytes();
    -        } else if (s instanceof String) {
    -          bytes = ((String) s).getBytes();
    -        } else if (s instanceof byte[]) {
    -          bytes = (byte[]) s;
    +        if (s == null) {
    +          varBinaryVector.getMutator().setNull(index);
    +          return;
             } else {
    -          throw new UnsupportedOperationException("Unable to create column data for type:
" + type);
    +          bytes = getBytes(type, s);
             }
             varBinaryVector.getMutator().setSafe(index, bytes, 0, bytes.length);
             return;
           }
           case DECIMAL18: {
             NullableDecimal18Vector decimalVector = (NullableDecimal18Vector) v;
    -        Long value = (Long) partitionValueMap.get(f).get(column);
    +        Object s = partitionValueMap.get(f).get(column);
    +        byte[] bytes;
    +        if (s == null) {
    +          decimalVector.getMutator().setNull(index);
    +          return;
    +        } else if (s instanceof Integer) {
    +          long value = DecimalUtility.getBigDecimalFromPrimitiveTypes(
    +                          (Integer) s,
    +                          majorType.getScale(),
    +                          majorType.getPrecision()).longValue();
    +          decimalVector.getMutator().setSafe(index, value);
    +          return;
    +        } else if (s instanceof Long) {
    +          long value = DecimalUtility.getBigDecimalFromPrimitiveTypes(
    +                          (Long) s,
    +                          majorType.getScale(),
    +                          majorType.getPrecision()).longValue();
    +          decimalVector.getMutator().setSafe(index, value);
    +          return;
    +        } else {
    +          bytes = getBytes(type, s);
    +        }
    +        long value = DecimalUtility.getBigDecimalFromByteArray(bytes, 0, bytes.length,
majorType.getScale()).longValue();
             decimalVector.getMutator().setSafe(index, value);
             return;
           }
           case DATE: {
             NullableDateVector dateVector = (NullableDateVector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        dateVector.getMutator().setSafe(index, value * (long) DateTimeConstants.MILLIS_PER_DAY);
    +        if (value == null) {
    +          dateVector.getMutator().setNull(index);
    +        } else {
    +          dateVector.getMutator().setSafe(index, value * (long) DateTimeConstants.MILLIS_PER_DAY);
    +        }
             return;
           }
           case TIME: {
             NullableTimeVector timeVector = (NullableTimeVector) v;
             Integer value = (Integer) partitionValueMap.get(f).get(column);
    -        timeVector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          timeVector.getMutator().setNull(index);
    +        } else {
    +          timeVector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case TIMESTAMP: {
             NullableTimeStampVector timeStampVector = (NullableTimeStampVector) v;
             Long value = (Long) partitionValueMap.get(f).get(column);
    -        timeStampVector.getMutator().setSafe(index, value);
    +        if (value == null) {
    +          timeStampVector.getMutator().setNull(index);
    +        } else {
    +          timeStampVector.getMutator().setSafe(index, value);
    +        }
             return;
           }
           case VARCHAR: {
             NullableVarCharVector varCharVector = (NullableVarCharVector) v;
             Object s = partitionValueMap.get(f).get(column);
             byte[] bytes;
    -        if (s instanceof String) { // if the metadata was read from a JSON cache file
it maybe a string type
    -          bytes = ((String) s).getBytes();
    -        } else if (s instanceof Binary) {
    -          bytes = ((Binary) s).getBytes();
    -        } else if (s instanceof byte[]) {
    -          bytes = (byte[]) s;
    +        if (s == null) {
    +          varCharVector.getMutator().setNull(index);
    +          return;
             } else {
    -          throw new UnsupportedOperationException("Unable to create column data for type:
" + type);
    +          bytes = getBytes(type, s);
             }
             varCharVector.getMutator().setSafe(index, bytes, 0, bytes.length);
             return;
           }
    +      case INTERVAL: {
    +        NullableIntervalVector intervalVector = (NullableIntervalVector) v;
    +        Object s = partitionValueMap.get(f).get(column);
    +        byte[] bytes;
    +        if (s == null) {
    +          intervalVector.getMutator().setNull(index);
    +          return;
    +        } else {
    +          bytes = getBytes(type, s);
    +        }
    +        intervalVector.getMutator().setSafe(index, 1,
    +          ParquetReaderUtility.getIntFromLEBytes(bytes, 0),
    +          ParquetReaderUtility.getIntFromLEBytes(bytes, 4),
    +          ParquetReaderUtility.getIntFromLEBytes(bytes, 8));
    --- End diff --
    
    This seems a very unstable implementation. Is the data here in Parquet format or Drill
format? If in Drill format, then we should simply store the interval as an array of bytes
passed into the {{public void set(int index, DrillBuf value)}} method. We may want to add
a new method {{public void set(int index, byte[] value, int length)}} to work with a byte
array (and avoid copying into a DrillBuf.)
    
    However, if this is supposed to be in Parquet format, should we serialize this as a map
(or array) of integers and use the JSON integer format rather than encoding internal representations
in JSON data.


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