Skip to content

Commit

Permalink
Failed attempt at creating new metadata instance
Browse files Browse the repository at this point in the history
  • Loading branch information
adeet1 committed Mar 21, 2024
1 parent 8630eed commit 38c35e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.locationtech.geomesa.fs.storage.parquet.io.SimpleFeatureParquetSchema
import org.locationtech.geomesa.utils.geotools.ObjectType.ObjectType
import org.locationtech.geomesa.utils.geotools.{ObjectType, SimpleFeatureTypes}
import org.locationtech.geomesa.utils.text.StringSerialization
import org.locationtech.jts.geom.Envelope

/**
* A paired simple feature type and parquet schema
Expand All @@ -39,13 +40,26 @@ case class SimpleFeatureParquetSchema(sft: SimpleFeatureType, schema: MessageTyp
/**
* Parquet file metadata
*/
lazy val metadata: java.util.Map[String, String] = scala.collection.mutable.HashMap(
lazy val metadata: java.util.Map[String, String] = Map(
StorageConfiguration.SftNameKey -> sft.getTypeName,
StorageConfiguration.SftSpecKey -> SimpleFeatureTypes.encodeType(sft, includeUserData = true),
SchemaVersionKey -> version.toString,
GeoParquetSchemaKey -> SimpleFeatureParquetSchema.geoParquetMetadata(sft)
SchemaVersionKey -> version.toString
).asJava

def addBoundingBoxMetadata(bbox: Envelope): java.util.Map[String, String] = {
val bboxString = s"[${bbox.getMinX}, ${bbox.getMaxX}, ${bbox.getMinY}, ${bbox.getMaxY}]"
val result = SimpleFeatureParquetSchema.geoParquetMetadata(sft) + s""","bbox":${bboxString}}}]}""""

val newMetadata: java.util.Map[String, String] = Map[String, String]().asJava
val keys = metadata.keySet().toArray()
for (key <- keys) {
newMetadata.put(key.asInstanceOf[String], metadata.get(key))
}
newMetadata.put(SimpleFeatureParquetSchema.GeoParquetSchemaKey, result)

newMetadata
}

/**
* Gets the name of the parquet field for the given simple feature type attribute
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,10 @@ class SimpleFeatureWriteSupport(observer: BoundsObserver) extends WriteSupport[S
case _ => None
}
val bbox = envelope.getOrElse(throw new RuntimeException("Unable to get bounding box from observer"))
val bboxString = s"[${bbox.getMinX}, ${bbox.getMaxX}, ${bbox.getMinY}, ${bbox.getMaxY}]"

val currentMetadata = schema.metadata.get(SimpleFeatureParquetSchema.GeoParquetSchemaKey)
val newMetadata = currentMetadata + s""","bbox":${bboxString}}}]}""""
schema.metadata.put(SimpleFeatureParquetSchema.GeoParquetSchemaKey, newMetadata)
val newMetadata = schema.addBoundingBoxMetadata(bbox)

new FinalizedWriteContext(schema.metadata)
new FinalizedWriteContext(newMetadata)
}

// called per block
Expand Down

0 comments on commit 38c35e4

Please sign in to comment.