rdblue commented on code in PR #12496:
URL: https://github.com/apache/iceberg/pull/12496#discussion_r2004398000


##########
core/src/main/java/org/apache/iceberg/variants/Variants.java:
##########
@@ -33,6 +37,66 @@ public static VariantMetadata metadata(ByteBuffer metadata) {
     return SerializedMetadata.from(metadata);
   }
 
+  public static VariantMetadata metadata(String... fieldNames) {
+    return metadata(Arrays.asList(fieldNames));
+  }
+
+  public static VariantMetadata metadata(Collection<String> fieldNames) {
+    if (fieldNames.isEmpty()) {
+      return emptyMetadata();
+    }
+
+    int numElements = fieldNames.size();
+    ByteBuffer[] nameBuffers = new ByteBuffer[numElements];
+    boolean sorted = true;
+    String last = null;
+    int pos = 0;
+    for (String name : fieldNames) {
+      nameBuffers[pos] = 
ByteBuffer.wrap(name.getBytes(StandardCharsets.UTF_8));
+      if (last != null && last.compareTo(name) >= 0) {
+        sorted = false;
+      }
+
+      last = name;
+      pos += 1;
+    }
+
+    int dataSize = 0;
+    for (ByteBuffer nameBuffer : nameBuffers) {
+      dataSize += nameBuffer.remaining();
+    }

Review Comment:
   Good call. Updated.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to