Search in sources :

Example 1 with PrimitiveTypeName

use of org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName in project drill by apache.

the class ParquetGroupScan method checkForPartitionColumn.

/**
   * When reading the very first footer, any column is a potential partition column. So for the first footer, we check
   * every column to see if it is single valued, and if so, add it to the list of potential partition columns. For the
   * remaining footers, we will not find any new partition columns, but we may discover that what was previously a
   * potential partition column now no longer qualifies, so it needs to be removed from the list.
   * @return whether column is a potential partition column
   */
private boolean checkForPartitionColumn(ColumnMetadata columnMetadata, boolean first) {
    SchemaPath schemaPath = SchemaPath.getCompoundPath(columnMetadata.getName());
    final PrimitiveTypeName primitiveType;
    final OriginalType originalType;
    if (this.parquetTableMetadata.hasColumnMetadata()) {
        primitiveType = this.parquetTableMetadata.getPrimitiveType(columnMetadata.getName());
        originalType = this.parquetTableMetadata.getOriginalType(columnMetadata.getName());
    } else {
        primitiveType = columnMetadata.getPrimitiveType();
        originalType = columnMetadata.getOriginalType();
    }
    if (first) {
        if (hasSingleValue(columnMetadata)) {
            partitionColTypeMap.put(schemaPath, getType(primitiveType, originalType));
            return true;
        } else {
            return false;
        }
    } else {
        if (!partitionColTypeMap.keySet().contains(schemaPath)) {
            return false;
        } else {
            if (!hasSingleValue(columnMetadata)) {
                partitionColTypeMap.remove(schemaPath);
                return false;
            }
            if (!getType(primitiveType, originalType).equals(partitionColTypeMap.get(schemaPath))) {
                partitionColTypeMap.remove(schemaPath);
                return false;
            }
        }
    }
    return true;
}
Also used : OriginalType(org.apache.parquet.schema.OriginalType) SchemaPath(org.apache.drill.common.expression.SchemaPath) PrimitiveTypeName(org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName)

Example 2 with PrimitiveTypeName

use of org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName in project drill by apache.

the class ParquetRecordWriter method getPrimitiveType.

private PrimitiveType getPrimitiveType(MaterializedField field) {
    MinorType minorType = field.getType().getMinorType();
    String name = field.getLastName();
    PrimitiveTypeName primitiveTypeName = ParquetTypeHelper.getPrimitiveTypeNameForMinorType(minorType);
    Repetition repetition = ParquetTypeHelper.getRepetitionForDataMode(field.getDataMode());
    OriginalType originalType = ParquetTypeHelper.getOriginalTypeForMinorType(minorType);
    DecimalMetadata decimalMetadata = ParquetTypeHelper.getDecimalMetadataForField(field);
    int length = ParquetTypeHelper.getLengthForMinorType(minorType);
    return new PrimitiveType(repetition, primitiveTypeName, length, name, originalType, decimalMetadata, null);
}
Also used : OriginalType(org.apache.parquet.schema.OriginalType) MinorType(org.apache.drill.common.types.TypeProtos.MinorType) PrimitiveType(org.apache.parquet.schema.PrimitiveType) DecimalMetadata(org.apache.parquet.schema.DecimalMetadata) Repetition(org.apache.parquet.schema.Type.Repetition) PrimitiveTypeName(org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName)

Aggregations

OriginalType (org.apache.parquet.schema.OriginalType)2 PrimitiveTypeName (org.apache.parquet.schema.PrimitiveType.PrimitiveTypeName)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 MinorType (org.apache.drill.common.types.TypeProtos.MinorType)1 DecimalMetadata (org.apache.parquet.schema.DecimalMetadata)1 PrimitiveType (org.apache.parquet.schema.PrimitiveType)1 Repetition (org.apache.parquet.schema.Type.Repetition)1