rdblue commented on code in PR #3212:
URL: https://github.com/apache/parquet-java/pull/3212#discussion_r2085656868
##########
parquet-variant/src/main/java/org/apache/parquet/variant/VariantBuilder.java:
##########
@@ -53,10 +62,35 @@ public class VariantBuilder {
*/
public VariantBuilder() {}
+ /**
+ * Set the metadata. May only be called if the builder has not yet added
anything to the metadata.
+ * If set, it is invalid to call build() on the builder. Only
valueWithoutMetadata() may be called
+ * to obtain the result.
+ *
+ * @param metadata
+ */
+ public void setFixedMetadata(HashMap<String, Integer> metadata) {
+ if (!this.dictionary.isEmpty()) {
+ throw new IllegalStateException("Cannot fix metadata once values have
been added to it");
+ }
+ this.dictionary = metadata;
+ this.fixedMetadata = true;
+ // We don't need the dictionaryKeys list when metadata is fixed, and
setting to null ensures that we'll
+ // fail if we accidentally try to use it. However, uses should be guarded
by a cleaner exception.
+ this.dictionaryKeys = null;
+ }
+
+ public void setFixedMetadata(ByteBuffer metadata) {
+ setFixedMetadata(VariantUtil.getMetadataMap(metadata));
+ }
+
/**
* @return the Variant value
*/
public Variant build() {
+ if (fixedMetadata) {
+ throw new IllegalStateException("Cannot reconstruct metadata when using
fixed metadata");
Review Comment:
If you passed in metadata, then this would not be needed. And it would
separate the concerns of building metadata and building values.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]