Drabble commented on code in PR #855:
URL: 
https://github.com/apache/incubator-baremaps/pull/855#discussion_r1613107467


##########
baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/GeoParquetReader.java:
##########
@@ -0,0 +1,263 @@
+/*
+ * 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.baremaps.geoparquet;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.*;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+import org.apache.baremaps.geoparquet.data.*;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.parquet.avro.AvroReadSupport;
+import org.apache.parquet.column.page.PageReadStore;
+import org.apache.parquet.hadoop.ParquetFileReader;
+import org.apache.parquet.hadoop.metadata.FileMetaData;
+import org.apache.parquet.hadoop.metadata.ParquetMetadata;
+import org.apache.parquet.hadoop.util.HadoopInputFile;
+import org.apache.parquet.io.ColumnIOFactory;
+import org.apache.parquet.io.RecordReader;
+import org.apache.parquet.schema.MessageType;
+
+
+/**
+ * This reader is based on the parquet example code located at: 
org.apache.parquet.example.data.*.
+ */
+public class GeoParquetReader {
+
+  private final URI uri;
+
+  private Configuration configuration;
+
+  private Map<FileStatus, FileInfo> metadata = new LinkedHashMap<>();
+
+  public GeoParquetReader(URI uri) {
+    this.uri = uri;
+    this.initialize();
+  }
+
+  public void initialize() {
+    try {
+      this.configuration = getConfiguration();
+
+      // List all the files that match the glob pattern
+      Path globPath = new Path(uri.getPath());
+      URI rootUri = getRootUri(uri);
+      FileSystem fileSystem = FileSystem.get(rootUri, configuration);
+      List<FileStatus> files = Arrays.asList(fileSystem.globStatus(globPath));
+
+      // Read the metadata of each file
+      for (FileStatus fileStatus : files) {
+
+        // Open the Parquet file
+        try (ParquetFileReader reader = ParquetFileReader
+            .open(HadoopInputFile.fromPath(fileStatus.getPath(), 
configuration))) {
+
+          // Read the number of rows in the Parquet file
+          long rowCount = reader.getRecordCount();
+
+          // Read the metadata of the Parquet file
+          ParquetMetadata parquetMetadata = reader.getFooter();
+          FileMetaData fileMetadata = parquetMetadata.getFileMetaData();
+
+          // Read the GeoParquet metadata of the Parquet file
+          String json = fileMetadata.getKeyValueMetaData().get("geo");
+          GeoParquetMetadata geoParquetMetadata = new ObjectMapper()
+              .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, 
false)
+              .readValue(json, GeoParquetMetadata.class);
+
+          // Store the metadata of the Parquet file
+          FileInfo fileInfo = new FileInfo(rowCount, parquetMetadata, 
geoParquetMetadata);
+          this.metadata.put(fileStatus, fileInfo);
+        }
+      }
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  public Stream<GeoParquetGroupImpl> read() throws IOException {
+    return StreamSupport.stream(
+        Spliterators.spliteratorUnknownSize(new GroupIterator(), 
Spliterator.ORDERED),
+        false);
+  }
+
+  private static Configuration getConfiguration() {
+    Configuration configuration = new Configuration();
+    configuration.set("fs.s3a.aws.credentials.provider",
+        "org.apache.hadoop.fs.s3a.AnonymousAWSCredentialsProvider");
+    configuration.setBoolean("fs.s3a.path.style.access", true);
+    configuration.setBoolean(AvroReadSupport.READ_INT96_AS_FIXED, true);

Review Comment:
   I believe that INT96 is deprecated. 
https://stackoverflow.com/questions/55829202/unable-to-read-date-format-columns-int96-type-from-avro-parquet-schema-in-apac.
 Did you get some INT96 fields in the geoparquet files?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to