github-advanced-security[bot] commented on code in PR #855:
URL: 
https://github.com/apache/incubator-baremaps/pull/855#discussion_r1611079446


##########
baremaps-geoparquet/src/main/java/org/apache/baremaps/geoparquet/data/GeoParquetGroupImpl.java:
##########
@@ -0,0 +1,284 @@
+/*
+ * 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.data;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.parquet.io.api.Binary;
+import org.apache.parquet.io.api.RecordConsumer;
+import org.apache.parquet.schema.GroupType;
+import org.apache.parquet.schema.Type;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.ParseException;
+import org.locationtech.jts.io.WKBReader;
+import org.locationtech.jts.io.WKBWriter;
+
+public class GeoParquetGroupImpl {
+
+  private final GroupType schema;
+
+  private final GeoParquetMetadata metadata;
+
+  private final List<Object>[] data;
+
+  @SuppressWarnings("unchecked")
+  public GeoParquetGroupImpl(GroupType schema, GeoParquetMetadata metadata) {
+    this.schema = schema;
+    this.metadata = metadata;
+    this.data = new List[schema.getFields().size()];
+    for (int i = 0; i < schema.getFieldCount(); i++) {
+      this.data[i] = new ArrayList<>();
+    }
+  }
+
+  public GroupType getSchema() {
+    return schema;
+  }
+
+  public GeoParquetGroupImpl addGroup(int fieldIndex) {
+    GeoParquetGroupImpl g =
+        new GeoParquetGroupImpl(schema.getType(fieldIndex).asGroupType(), 
metadata);
+    add(fieldIndex, g);
+    return g;
+  }
+
+  public GeoParquetGroupImpl addGroup(String field) {
+    return addGroup(getSchema().getFieldIndex(field));
+  }
+
+  public GeoParquetGroupImpl getGroup(int fieldIndex, int index) {
+    return (GeoParquetGroupImpl) getValue(fieldIndex, index);
+  }
+
+  public GeoParquetGroupImpl getGroup(String field, int index) {
+    return getGroup(getSchema().getFieldIndex(field), index);
+  }
+
+  public int getFieldRepetitionCount(int fieldIndex) {
+    List<Object> list = data[fieldIndex];
+    return list == null ? 0 : list.size();
+  }
+
+  public String getValueToString(int fieldIndex, int index) {
+    return String.valueOf(getValue(fieldIndex, index));
+  }
+
+  public String getString(int fieldIndex, int index) {
+    return ((BinaryValue) getValue(fieldIndex, index)).getString();
+  }
+
+  public int getInteger(int fieldIndex, int index) {
+    return ((IntegerValue) getValue(fieldIndex, index)).getInteger();
+  }
+
+  public long getLong(int fieldIndex, int index) {
+    return ((LongValue) getValue(fieldIndex, index)).getLong();
+  }
+
+  public double getDouble(int fieldIndex, int index) {
+    return ((DoubleValue) getValue(fieldIndex, index)).getDouble();
+  }
+
+  public float getFloat(int fieldIndex, int index) {
+    return ((FloatValue) getValue(fieldIndex, index)).getFloat();
+  }
+
+  public boolean getBoolean(int fieldIndex, int index) {
+    return ((BooleanValue) getValue(fieldIndex, index)).getBoolean();
+  }
+
+  public Binary getBinary(int fieldIndex, int index) {
+    return ((BinaryValue) getValue(fieldIndex, index)).getBinary();
+  }
+
+  public NanoTimeValue getTimeNanos(int fieldIndex, int index) {
+    return NanoTimeValue.fromInt96((Int96Value) getValue(fieldIndex, index));
+  }
+
+  public Binary getInt96(int fieldIndex, int index) {
+    return ((Int96Value) getValue(fieldIndex, index)).getInt96();
+  }
+
+  public Geometry getGeometry(int fieldIndex, int index) {
+    byte[] bytes = ((BinaryValue) getValue(fieldIndex, 
index)).getBinary().getBytes();
+    try {
+      return new WKBReader().read(bytes);
+    } catch (ParseException e) {
+      throw new RuntimeException(e);
+    }
+  }
+
+  private Object getValue(int fieldIndex, int index) {
+    List<Object> list;
+    try {
+      list = data[fieldIndex];
+    } catch (IndexOutOfBoundsException e) {
+      throw new RuntimeException(
+          "not found " + fieldIndex + "(" + schema.getFieldName(fieldIndex)
+              + ") in group:\n" + this);
+    }
+    try {
+      return list.get(index);
+    } catch (IndexOutOfBoundsException e) {
+      throw new RuntimeException(
+          "not found " + fieldIndex + "(" + schema.getFieldName(fieldIndex)
+              + ") element number " + index + " in group:\n" + this);
+    }
+  }
+
+  private void add(int fieldIndex, Primitive value) {
+    Type type = schema.getType(fieldIndex);
+    List<Object> list = data[fieldIndex];
+    if (!type.isRepetition(Type.Repetition.REPEATED)
+        && !list.isEmpty()) {
+      throw new IllegalStateException("field " + fieldIndex + " (" + 
type.getName()
+          + ") can not have more than one value: " + list);
+    }
+    list.add(value);
+  }
+
+  public void add(int fieldIndex, int value) {
+    add(fieldIndex, new IntegerValue(value));
+  }
+
+  public void add(int fieldIndex, long value) {
+    add(fieldIndex, new LongValue(value));
+  }
+
+  public void add(int fieldIndex, String value) {
+    add(fieldIndex, new BinaryValue(Binary.fromString(value)));
+  }
+
+  public void add(int fieldIndex, NanoTimeValue value) {

Review Comment:
   ## Confusing overloading of methods
   
   Method GeoParquetGroupImpl.add(..) could be confused with overloaded method 
[add](1), since dispatch depends on static types.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1414)



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