rdblue commented on code in PR #3117:
URL: https://github.com/apache/parquet-java/pull/3117#discussion_r1968570703


##########
parquet-variant/src/main/java/org/apache/parquet/variant/VariantUtil.java:
##########
@@ -0,0 +1,718 @@
+/*
+ * 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.parquet.variant;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Arrays;
+
+/**
+ * This class defines constants related to the Variant format and provides 
functions for
+ * manipulating Variant binaries.
+ *
+ * A Variant is made up of 2 binaries: value and metadata. A Variant value 
consists of a one-byte
+ * header and a number of content bytes (can be zero). The header byte is 
divided into upper 6 bits
+ * (called "type info") and lower 2 bits (called "basic type"). The content 
format is explained in
+ * the below constants for all possible basic type and type info values.
+ *
+ * The Variant metadata includes a version id and a dictionary of distinct 
strings (case-sensitive).
+ * Its binary format is:
+ * - Version: 1-byte unsigned integer. The only acceptable value is 1 
currently.
+ * - Dictionary size: 4-byte little-endian unsigned integer. The number of 
keys in the
+ *                    dictionary.
+ * - Offsets: (size + 1) * 4-byte little-endian unsigned integers. 
`offsets[i]` represents the
+ * starting position of string i, counting starting from the address of 
`offsets[0]`. Strings
+ * must be stored contiguously, so we don’t need to store the string size, 
instead, we compute it
+ * with `offset[i + 1] - offset[i]`.
+ * - UTF-8 string data.
+ */
+public class VariantUtil {
+  public static final int BASIC_TYPE_BITS = 2;
+  public static final int BASIC_TYPE_MASK = 0x3;
+  public static final int PRIMITIVE_TYPE_MASK = 0x3F;
+  /** The inclusive maximum value of the type info value. It is the size limit 
of `SHORT_STR`. */
+  public static final int MAX_SHORT_STR_SIZE = 0x3F;
+
+  // The basic types
+
+  /**
+   * Primitive value.
+   * The type info value must be one of the values in the "Primitive" section 
below.
+   */
+  public static final int PRIMITIVE = 0;
+  /**
+   * Short string value.
+   * The type info value is the string size, which must be in `[0, 
MAX_SHORT_STR_SIZE]`.
+   * The string content bytes directly follow the header byte.
+   */
+  public static final int SHORT_STR = 1;
+  /**
+   * Object value.
+   * The content contains a size, a list of field ids, a list of field 
offsets, and
+   * the actual field values. The list of field ids has `size` ids, while the 
list of field offsets
+   * has `size + 1` offsets, where the last offset represents the total size 
of the field values
+   * data. The list of fields ids must be sorted by the field name in 
alphabetical order.
+   * Duplicate field names within one object are not allowed.
+   * 5 bits in the type info are used to specify the integer type of the 
object header. It is
+   * 0_b4_b3b2_b1b0 (MSB is 0), where:
+   *   - b4: the integer type of size. When it is 0/1, `size` is a 
little-endian 1/4-byte
+   *         unsigned integer.
+   *   - b3b2: the integer type of ids. When the 2 bits are 0/1/2, the id list 
contains
+   *           1/2/3-byte little-endian unsigned integers.
+   *   - b1b0: the integer type of offset. When the 2 bits are 0/1/2, the 
offset list contains
+   *           1/2/3-byte little-endian unsigned integers.
+   */
+  public static final int OBJECT = 2;
+  /**
+   * Array value.
+   * The content contains a size, a list of field offsets, and the actual 
element values.
+   * It is similar to an object without the id list. The length of the offset 
list
+   * is `size + 1`, where the last offset represent the total size of the 
element data.
+   * Its type info is: 000_b2_b1b0:
+   *   - b2: the type of size.
+   *   - b1b0: the integer type of offset.
+   */
+  public static final int ARRAY = 3;
+
+  // The primitive types
+
+  /** JSON Null value. Empty content. */
+  public static final int NULL = 0;
+  /** True value. Empty content. */
+  public static final int TRUE = 1;
+  /** False value. Empty content. */
+  public static final int FALSE = 2;
+  /** 1-byte little-endian signed integer. */
+  public static final int INT1 = 3;

Review Comment:
   Minor: In the spec these are `INT8`, `INT16`, `INT32`, etc that match the 
Parquet physical types.



-- 
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...@parquet.apache.org

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


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

Reply via email to