unical1988 commented on code in PR #728: URL: https://github.com/apache/incubator-xtable/pull/728#discussion_r2193417896
########## xtable-core/src/main/java/org/apache/xtable/parquet/ParquetPartitionValueExtractor.java: ########## @@ -0,0 +1,232 @@ +/* + * 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.xtable.parquet; + +import java.time.Instant; +import java.time.OffsetDateTime; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.apache.parquet.schema.MessageType; +import org.apache.xtable.model.schema.InternalField; +import org.apache.xtable.model.schema.InternalPartitionField; +import org.apache.xtable.model.schema.InternalSchema; +import org.apache.xtable.model.schema.InternalType; +import org.apache.xtable.model.stat.PartitionValue; +import org.apache.parquet.hadoop.metadata.ParquetMetadata; +import org.apache.xtable.model.stat.Range; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.Map; +import java.util.regex.Pattern; + +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; + +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.Value; + +import org.apache.xtable.exception.PartitionValuesExtractorException; +import org.apache.xtable.model.schema.InternalPartitionField; +import org.apache.xtable.model.schema.InternalType; +import org.apache.xtable.model.stat.PartitionValue; +import org.apache.xtable.model.stat.Range; + + +/** Partition value extractor for Parquet. */ +// Extracts the partitionFields and values and create InputParitionFields object (fields and types) +//then convert those to InternalPartitionField for the ConversionSource +//@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class ParquetPartitionValueExtractor { + private static final OffsetDateTime EPOCH = Instant.ofEpochSecond(0).atOffset(ZoneOffset.UTC); + private static final ParquetPartitionValueExtractor INSTANCE = + new ParquetPartitionValueExtractor(); + private static final ParquetSchemaExtractor schemaExtractor = + ParquetSchemaExtractor.getInstance(); + private static final ParquetMetadataExtractor parquetMetadataExtractor = + ParquetMetadataExtractor.getInstance(); + + private static final ParquetPartitionSpecExtractor partitionsSpecExtractor = + ParquetPartitionSpecExtractor.getInstance(); + + public static ParquetPartitionValueExtractor getInstance() { + return INSTANCE; + } + private static final String HIVE_DEFAULT_PARTITION = "__HIVE_DEFAULT_PARTITION__"; + private final Map<String, String> pathToPartitionFieldFormat = null; + + + public List<InternalPartitionField> extractParquertPartitions( + ParquetMetadata footer, String path) { + MessageType parquetSchema = parquetMetadataExtractor.getSchema(footer); + InternalSchema internalSchema = schemaExtractor.toInternalSchema(parquetSchema, path); + List<InternalPartitionField> partitions = partitionsSpecExtractor.spec(internalSchema); + return partitions; + } + + + + public List<PartitionValue> extractPartitionValues( Review Comment: there are not exactly the same, I did refactor the class ########## xtable-core/src/main/java/org/apache/xtable/parquet/ParquetSourcePartitionSpecExtractor.java: ########## @@ -0,0 +1,31 @@ +/* + * 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.xtable.parquet; + +import java.util.Map; + +import org.apache.xtable.spi.extractor.SourcePartitionSpecExtractor; + +/** + * Partition spec extractor interface specifically designed for Parquet to parse partition values + * appropriately. + */ +public interface ParquetSourcePartitionSpecExtractor extends SourcePartitionSpecExtractor { Review Comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@xtable.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org