Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/805#discussion_r112660688
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/ParquetReaderUtility.java
 ---
    @@ -181,6 +185,71 @@ else if (parquetTableMetadata instanceof 
Metadata.ParquetTableMetadata_v2 &&
       }
     
       /**
    +   * Checks that the metadata file was created by drill with version less 
that
    +   * the version where was changed the serialization of BINARY values
    +   * and assigns byte arrays to min/max values obtained from the 
deserialized string.
    +   *
    +   * @param parquetTableMetadata table metadata that should be corrected
    +   */
    +  public static void 
correctBinaryInMetadataCache(Metadata.ParquetTableMetadataBase 
parquetTableMetadata) {
    +    if (hasOldBinarySerialization(parquetTableMetadata)) {
    +      Set<List<String>> names = Sets.newHashSet();
    +      if (parquetTableMetadata instanceof 
Metadata.ParquetTableMetadata_v2) {
    +        for (Metadata.ColumnTypeMetadata_v2 columnTypeMetadata :
    +            ((Metadata.ParquetTableMetadata_v2) 
parquetTableMetadata).columnTypeInfo.values()) {
    +          if (columnTypeMetadata.primitiveType == 
PrimitiveTypeName.BINARY) {
    +            names.add(Arrays.asList(columnTypeMetadata.name));
    +          }
    +        }
    +      }
    +      for (Metadata.ParquetFileMetadata file : 
parquetTableMetadata.getFiles()) {
    +        // Drill has only ever written a single row group per file, only 
need to correct the statistics
    +        // on the first row group
    +        Metadata.RowGroupMetadata rowGroupMetadata = 
file.getRowGroups().get(0);
    +        for (Metadata.ColumnMetadata columnMetadata : 
rowGroupMetadata.getColumns()) {
    +          // Setting Min/Max values for ParquetTableMetadata_v1
    +          if (parquetTableMetadata instanceof 
Metadata.ParquetTableMetadata_v1
    +                || parquetTableMetadata instanceof 
Metadata.ParquetTableMetadata_v3) {
    +            PrimitiveTypeName primitiveType = 
columnMetadata.getPrimitiveType();
    +            if (primitiveType == PrimitiveTypeName.BINARY && 
columnMetadata.hasSingleValue()) {
    +              Object minValue = columnMetadata.getMinValue();
    +              if (minValue != null && minValue instanceof String) {
    +                byte[] bytes = ((String) minValue).getBytes();
    +                columnMetadata.setMax(bytes);
    +                columnMetadata.setMin(bytes);
    +              }
    +            }
    +          }
    +          // Setting Max values for ParquetTableMetadata_v2
    +          else if (parquetTableMetadata instanceof 
Metadata.ParquetTableMetadata_v2
    +                    && columnMetadata.hasSingleValue()
    +                    && 
names.contains(Arrays.asList(columnMetadata.getName()))) {
    +            Object maxValue = columnMetadata.getMaxValue();
    +            if (maxValue != null && maxValue instanceof String) {
    +              byte[] bytes = ((String) maxValue).getBytes();
    +              columnMetadata.setMax(bytes);
    +            }
    +          }
    +        }
    +      }
    +    }
    +  }
    +
    +  /**
    +   * Checks that the metadata file was created by drill with version less 
that
    +   * the version where was changed the serialization of BINARY values.
    +   *
    +   * @param parquetTableMetadata the source of drill version
    +   * @return true if metadata file was created by drill with version less 
that
    +   * the version where was changed the serialization of BINARY values
    +   */
    +  public static boolean 
hasOldBinarySerialization(Metadata.ParquetTableMetadataBase 
parquetTableMetadata) {
    +    String drillVersion = parquetTableMetadata.getDrillVersion();
    +    return drillVersion == null
    +            || new ComparableVersion(drillVersion).compareTo(new 
ComparableVersion("1.11.0-SNAPSHOT")) < 0;
    --- End diff --
    
    I am not sure that using version with SNAPSHOT is correct.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to