Skip to content

Commit

Permalink
Fix issues in group
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Oct 12, 2024
1 parent 8de3f0f commit ffbc74c
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ public List<Object> getValues(int fieldIndex) {
return (List<Object>) data[fieldIndex];
}

private GeoParquetGroup getGroup(int fieldIndex) {
return (GeoParquetGroup) data[fieldIndex];
}

private void addValue(int fieldIndex, Object value) {
Object currentValue = data[fieldIndex];
if (currentValue instanceof List<?>) {
Expand Down Expand Up @@ -225,48 +221,6 @@ private GeoParquetException createGeoParquetException(int fieldIndex, String ele
return new GeoParquetException(msg);
}

public String toString() {
return toString("");
}

public String toString(String indent) {
StringBuilder builder = new StringBuilder();
appendToString(builder, indent);
return builder.toString();
}

private void appendToString(StringBuilder builder, String indent) {
int i = 0;
for (org.apache.parquet.schema.Type field : parquetSchema.getFields()) {
String name = field.getName();
Object object = data[i];
++i;
if (object != null) {
if (object instanceof List<?>values) {
for (Object value : values) {
builder.append(indent).append(name);
if (value == null) {
builder.append(": NULL\n");
} else if (value instanceof GeoParquetGroup group) {
builder.append('\n');
group.appendToString(builder, indent + " ");
} else {
builder.append(": ").append(value).append('\n');
}
}
} else {
builder.append(indent).append(name);
if (object instanceof GeoParquetGroup group) {
builder.append('\n');
group.appendToString(builder, indent + " ");
} else {
builder.append(": ").append(object).append('\n');
}
}
}
}
}

public GeoParquetSchema getGeoParquetSchema() {
return geoParquetSchema;
}
Expand All @@ -280,30 +234,10 @@ public GeoParquetMetadata getGeoParquetMetadata() {
}

// Getter methods for different data types
public String getString(int fieldIndex, int index) {
public String getStringValue(int fieldIndex, int index) {
return getBinaryValue(fieldIndex, index).toStringUsingUTF8();
}

public int getInteger(int fieldIndex, int index) {
return (int) getValue(fieldIndex, index);
}

public long getLong(int fieldIndex, int index) {
return (long) getValue(fieldIndex, index);
}

public double getDouble(int fieldIndex, int index) {
return (double) getValue(fieldIndex, index);
}

public float getFloat(int fieldIndex, int index) {
return (float) getValue(fieldIndex, index);
}

public boolean getBoolean(int fieldIndex, int index) {
return (boolean) getValue(fieldIndex, index);
}

public Binary getBinaryValue(int fieldIndex, int index) {
return (Binary) getValue(fieldIndex, index);
}
Expand Down Expand Up @@ -343,7 +277,7 @@ public Long getLongValue(int fieldIndex) {
}

public String getStringValue(int fieldIndex) {
return getString(fieldIndex, 0);
return getStringValue(fieldIndex, 0);
}

public Geometry getGeometryValue(int fieldIndex) {
Expand Down Expand Up @@ -514,4 +448,55 @@ public List<Envelope> getEnvelopeValues(String fieldName) {
return getEnvelopeValues(parquetSchema.getFieldIndex(fieldName));
}

public String toString() {

Check notice

Code scanning / CodeQL

Missing Override annotation Note

This method overrides
Object.toString
; it is advisable to add an Override annotation.
return toString("");
}

private String toString(String indent) {
StringBuilder builder = new StringBuilder();
int fieldCount = parquetSchema.getFields().size();

for (int i = 0; i < fieldCount; i++) {
String fieldName = parquetSchema.getFieldName(i);
Object fieldValue = data[i];
if (fieldValue != null) {
appendFieldToString(builder, indent, fieldName, fieldValue);
}
}

return builder.toString();
}

private void appendFieldToString(StringBuilder builder, String indent, String fieldName,
Object fieldValue) {
if (fieldValue instanceof List<?>values) {
for (Object value : values) {
appendValueToString(builder, indent, fieldName, value);
}
} else {
appendValueToString(builder, indent, fieldName, fieldValue);
}
}

private void appendValueToString(StringBuilder builder, String indent, String fieldName,
Object value) {
builder.append(indent).append(fieldName);
if (value == null) {
builder.append(": NULL\n");
} else if (value instanceof GeoParquetGroup group) {
builder.append("\n").append(group.toString(indent + " "));
} else {
String valueString = getValueAsString(value);
builder.append(": ").append(valueString).append("\n");
}
}

private String getValueAsString(Object value) {
if (value instanceof Binary binary) {
return binary.toStringUsingUTF8();
} else {
return value.toString();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public record Column(
@JsonProperty("crs") JsonNode crs,
@JsonProperty("orientation") String orientation,
@JsonProperty("edges") String edges,
@JsonProperty("bbox") Double[] bbox) {
@JsonProperty("bbox") List<Double> bbox) {
}

/**
Expand Down Expand Up @@ -94,13 +94,12 @@ public int getSrid(String column) {
String code = idNode.get("code").asText();

// Determine SRID based on authority and code
switch (authority) {
case "OGC":
return getOgcSrid(code); // Handle OGC specific SRIDs
case "EPSG":
return getEpsgCode(code); // Handle EPSG SRIDs
default:
return 4326; // Default SRID if authority is unrecognized
if (authority.equals("EPSG")) {
return getEpsgCode(code);
} else if (authority.equals("OGC")) {
return getOgcSrid(code);
} else {
return 4326; // Default SRID if authority is unrecognized
}
}

Expand All @@ -111,11 +110,10 @@ public int getSrid(String column) {
* @return the SRID, or 0 if the code is unrecognized
*/
private int getOgcSrid(String code) {
switch (code) {
case "CRS84":
return 4326;
default:
return 0; // Unrecognized OGC code
if ("CRS84".equals(code)) {
return 4326;
} else {
return 0; // Unrecognized OGC code
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public enum Cardinality {
* Sealed interfaces were introduced in Java 17 and can be used with pattern matching since Java
* 21.
*/
sealed
public interface Field {
public sealed
interface Field {
String name();

Type type();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GeoParquetReaderTest {
void read() {
URI geoParquet = TestFiles.GEOPARQUET.toUri();
GeoParquetReader geoParquetReader = new GeoParquetReader(geoParquet);
assertEquals(5, geoParquetReader.read().count());
assertEquals(5, geoParquetReader.read().peek(System.out::println).count());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Envelope;

public class OvertureMapsTest {
class OvertureMapsTest {

@Disabled("Requires access to the Internet")
@Test
Expand Down

0 comments on commit ffbc74c

Please sign in to comment.