the-other-tim-brown commented on code in PR #669:
URL: https://github.com/apache/incubator-xtable/pull/669#discussion_r2052547092


##########
xtable-api/src/main/java/org/apache/xtable/model/storage/InternalDataFile.java:
##########
@@ -52,4 +52,21 @@ public class InternalDataFile extends InternalFile {
   @Builder.Default @NonNull List<ColumnStat> columnStats = 
Collections.emptyList();
   // last modified time in millis since epoch
   long lastModified;
+  public static InternalDataFileBuilder builderFrom(InternalDataFile dataFile) 
{
+    return dataFile.toBuilder();

Review Comment:
   Why do you need this wrapper instead of just using the `toBuilder` directly?



##########
xtable-api/src/main/java/org/apache/xtable/model/storage/InternalDataFile.java:
##########
@@ -52,4 +52,21 @@ public class InternalDataFile extends InternalFile {
   @Builder.Default @NonNull List<ColumnStat> columnStats = 
Collections.emptyList();
   // last modified time in millis since epoch
   long lastModified;
+  public static InternalDataFileBuilder builderFrom(InternalDataFile dataFile) 
{
+    return dataFile.toBuilder();
+  }
+
+  public boolean equals(InternalDataFile obj2) {

Review Comment:
   Let's just use the generated equals



##########
xtable-core/src/main/java/org/apache/xtable/parquet/ParquetStatsExtractor.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Value;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.*;
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ParquetMetadata;
+import org.apache.parquet.schema.MessageType;
+
+import org.apache.xtable.model.config.InputPartitionFields;
+import org.apache.xtable.model.schema.InternalField;
+import org.apache.xtable.model.stat.ColumnStat;
+import org.apache.xtable.model.stat.PartitionValue;
+import org.apache.xtable.model.stat.Range;
+import org.apache.xtable.model.storage.FileFormat;
+import org.apache.xtable.model.storage.InternalDataFile;
+
+@Value
+@Builder
+public class ParquetStatsExtractor {
+
+    private static final ParquetStatsExtractor INSTANCE = null; // new 
ParquetStatsExtractor();
+
+
+    private static final ParquetPartitionValueExtractor partitionExtractor =
+            ParquetPartitionValueExtractor.getInstance();
+
+
+    private static final ParquetSchemaExtractor schemaExtractor =
+            ParquetSchemaExtractor.getInstance();
+
+
+    private static final ParquetMetadataExtractor parquetMetadataExtractor =
+            ParquetMetadataExtractor.getInstance();

Review Comment:
   It will be easier for testing if you define these as instance variables so 
we can create an instance with mocks of these dependencies



##########
xtable-core/src/main/java/org/apache/xtable/parquet/ParquetStatsExtractor.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Value;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.*;
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ParquetMetadata;
+import org.apache.parquet.schema.MessageType;
+
+import org.apache.xtable.model.config.InputPartitionFields;
+import org.apache.xtable.model.schema.InternalField;
+import org.apache.xtable.model.stat.ColumnStat;
+import org.apache.xtable.model.stat.PartitionValue;
+import org.apache.xtable.model.stat.Range;
+import org.apache.xtable.model.storage.FileFormat;
+import org.apache.xtable.model.storage.InternalDataFile;
+
+@Value
+@Builder
+public class ParquetStatsExtractor {
+
+    private static final ParquetStatsExtractor INSTANCE = null; // new 
ParquetStatsExtractor();
+
+
+    private static final ParquetPartitionValueExtractor partitionExtractor =
+            ParquetPartitionValueExtractor.getInstance();
+
+
+    private static final ParquetSchemaExtractor schemaExtractor =
+            ParquetSchemaExtractor.getInstance();
+
+
+    private static final ParquetMetadataExtractor parquetMetadataExtractor =
+            ParquetMetadataExtractor.getInstance();
+
+    private static final InputPartitionFields partitions = null;
+
+    public static ParquetStatsExtractor getInstance() {
+        return INSTANCE;
+    }
+
+    public static List<ColumnStat> getColumnStatsForaFile(ParquetMetadata 
footer) {
+        return getStatsForFile(footer).values().stream()
+                .flatMap(List::stream)
+                .collect(Collectors.toList());
+    }
+
+    private static Optional<Long> getMaxFromColumnStats(List<ColumnStat> 
columnStats) {
+        return columnStats.stream()
+                .filter(entry -> entry.getField().getParentPath() == null)
+                .map(ColumnStat::getNumValues)
+                .filter(numValues -> numValues > 0)
+                .max(Long::compareTo);
+    }
+
+    public static Map<ColumnDescriptor, List<ColumnStat>> 
getStatsForFile(ParquetMetadata footer) {
+        Map<ColumnDescriptor, List<ColumnStat>> columnDescStats = new 
HashMap<>();
+        MessageType schema = parquetMetadataExtractor.getSchema(footer);
+        List<ColumnChunkMetaData> columns = new ArrayList<>();
+        columns =
+                footer.getBlocks().stream()
+                        .flatMap(blockMetaData -> 
blockMetaData.getColumns().stream())
+                        .collect(Collectors.toList());
+        columnDescStats =
+                columns.stream()
+                        .collect(
+                                Collectors.groupingBy(
+                                        columnMetaData ->
+                                                
schema.getColumnDescription(columnMetaData.getPath().toArray()),
+                                        Collectors.mapping(
+                                                columnMetaData ->
+                                                        ColumnStat.builder()
+                                                                .field(
+                                                                        
InternalField.builder()
+                                                                               
 .name(columnMetaData.getPrimitiveType().getName())
+                                                                               
 .fieldId(
+                                                                               
         columnMetaData.getPrimitiveType().getId() == null
+                                                                               
                 ? null
+                                                                               
                 : columnMetaData
+                                                                               
                 .getPrimitiveType()
+                                                                               
                 .getId()
+                                                                               
                 .intValue())
+                                                                               
 .parentPath(null)
+                                                                               
 .schema(
+                                                                               
         schemaExtractor.toInternalSchema(
+                                                                               
                 columnMetaData.getPrimitiveType(),
+                                                                               
                 columnMetaData.getPath().toDotString()))
+                                                                               
 .build())
+                                                                
.numValues(columnMetaData.getValueCount())
+                                                                
.totalSize(columnMetaData.getTotalSize())
+                                                                .range(
+                                                                        
Range.vector(
+                                                                               
 columnMetaData.getStatistics().getMinBytes(),

Review Comment:
   A byte array should not be used for non byte array types, where does the 
conversion happen? The types must align with the XTable expectations



##########
xtable-api/src/main/java/org/apache/xtable/model/stat/ColumnStat.java:
##########
@@ -31,9 +33,20 @@
 @Value
 @Builder(toBuilder = true)
 public class ColumnStat {
-  InternalField field;
-  Range range;
-  long numNulls;
-  long numValues;
-  long totalSize;
+    InternalField field;
+    Range range;
+    long numNulls;
+    long numValues;
+    long totalSize;
+
+    public boolean equals(ColumnStat colStat) {

Review Comment:
   Let's use the generated equals here, if the range has issues on byte arrays 
then the equals method should be updated for the range class



##########
xtable-core/src/main/java/org/apache/xtable/parquet/ParquetStatsExtractor.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import lombok.Builder;
+import lombok.Value;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.*;
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ParquetMetadata;
+import org.apache.parquet.schema.MessageType;
+
+import org.apache.xtable.model.config.InputPartitionFields;
+import org.apache.xtable.model.schema.InternalField;
+import org.apache.xtable.model.stat.ColumnStat;
+import org.apache.xtable.model.stat.PartitionValue;
+import org.apache.xtable.model.stat.Range;
+import org.apache.xtable.model.storage.FileFormat;
+import org.apache.xtable.model.storage.InternalDataFile;
+
+@Value
+@Builder
+public class ParquetStatsExtractor {
+
+    private static final ParquetStatsExtractor INSTANCE = null; // new 
ParquetStatsExtractor();
+
+
+    private static final ParquetPartitionValueExtractor partitionExtractor =
+            ParquetPartitionValueExtractor.getInstance();
+
+
+    private static final ParquetSchemaExtractor schemaExtractor =
+            ParquetSchemaExtractor.getInstance();
+
+
+    private static final ParquetMetadataExtractor parquetMetadataExtractor =
+            ParquetMetadataExtractor.getInstance();
+
+    private static final InputPartitionFields partitions = null;
+
+    public static ParquetStatsExtractor getInstance() {
+        return INSTANCE;
+    }

Review Comment:
   I see there is a builder for this class. Typically we don't use this 
singleton pattern when the class has dependencies it requires.



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

Reply via email to