You are viewing a plain text version of this content. The canonical link for it is here.
Posted to devnull@infra.apache.org by "wgtmac (via GitHub)" <gi...@apache.org> on 2023/01/28 07:30:21 UTC

[GitHub] [parquet-mr] wgtmac commented on a diff in pull request #1011: PARQUET-2159: java17 vector parquet bit-packing decode optimization

wgtmac commented on code in PR #1011:
URL: https://github.com/apache/parquet-mr/pull/1011#discussion_r1089666125


##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).

Review Comment:
   ```suggestion
    * Utility class for big data applications (such as Apache Spark and Apache Flink).
   ```



##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).
+ * For Intel CPU, Flags containing avx512vbmi and avx512_vbmi2 can have better performance gains.
+ */
+public class ParquetReadRouter {
+  private static final Logger LOG = LoggerFactory.getLogger(ParquetReadRouter.class);
+
+  private static volatile Boolean vector;
+
+  public static void read(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    if (supportVector()) {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    } else {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);

Review Comment:
   ```suggestion
         readBatch(bitWidth, in, currentCount, currentBuffer);
   ```



##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).
+ * For Intel CPU, Flags containing avx512vbmi and avx512_vbmi2 can have better performance gains.
+ */
+public class ParquetReadRouter {
+  private static final Logger LOG = LoggerFactory.getLogger(ParquetReadRouter.class);
+
+  private static volatile Boolean vector;
+
+  public static void read(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    if (supportVector()) {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    } else {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    }
+  }
+
+  public static void readBatchVector(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    BytePacker packerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);
+    int valueIndex = 0;
+    int byteIndex = 0;
+    int unpackCount = packerVector.getUnpackCount();
+    int inputByteCountPerVector = packerVector.getUnpackCount() / 8 * bitWidth;
+    int totalByteCount = currentCount * bitWidth / 8;
+
+    // register of avx512 are 512 bits, and can load up to 64 bytes
+    int totalByteCountVector = totalByteCount - 64;
+    ByteBuffer buffer = in.slice(totalByteCount);
+    if (buffer.hasArray()) {
+      for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += unpackCount) {
+        packerVector.unpackValuesVector(buffer.array(), buffer.arrayOffset() + buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+      // If the remaining bytes size <= 64, the remaining bytes are unpacked by packer
+      for (; byteIndex < totalByteCount; byteIndex += bitWidth, valueIndex += 8) {
+        packer.unpack8Values(buffer.array(), buffer.arrayOffset() + buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+    } else {
+      for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += unpackCount) {
+        packerVector.unpackValuesVector(buffer, buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+      for (; byteIndex < totalByteCount; byteIndex += bitWidth, valueIndex += 8) {
+        packer.unpack8Values(buffer, buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+    }
+  }
+  public static void readBatch(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws EOFException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    int valueIndex = 0;
+    while (valueIndex < currentCount) {
+      // values are bit packed 8 at a time, so reading bitWidth will always work
+      ByteBuffer buffer = in.slice(bitWidth);
+      packer.unpack8Values(buffer, buffer.position(), currentBuffer, valueIndex);
+      valueIndex += 8;
+    }
+  }
+
+  public static Boolean supportVector() {
+    if (vector != null) {
+      return vector;
+    }
+    synchronized (ParquetReadRouter.class) {
+      if (vector == null) {
+        synchronized (ParquetReadRouter.class) {
+          vector = avx512Flag();

Review Comment:
   I assume the java vector api is agnostic to specific instruction set. So this function name is a little bit misleading to me since it binds the vector to AVX-512. Better to organize the code to be more extensible for other instruction sets.



##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).
+ * For Intel CPU, Flags containing avx512vbmi and avx512_vbmi2 can have better performance gains.
+ */
+public class ParquetReadRouter {
+  private static final Logger LOG = LoggerFactory.getLogger(ParquetReadRouter.class);
+
+  private static volatile Boolean vector;
+
+  public static void read(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    if (supportVector()) {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    } else {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    }
+  }
+
+  public static void readBatchVector(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    BytePacker packerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);
+    int valueIndex = 0;
+    int byteIndex = 0;
+    int unpackCount = packerVector.getUnpackCount();
+    int inputByteCountPerVector = packerVector.getUnpackCount() / 8 * bitWidth;
+    int totalByteCount = currentCount * bitWidth / 8;
+
+    // register of avx512 are 512 bits, and can load up to 64 bytes
+    int totalByteCountVector = totalByteCount - 64;
+    ByteBuffer buffer = in.slice(totalByteCount);
+    if (buffer.hasArray()) {
+      for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += unpackCount) {
+        packerVector.unpackValuesVector(buffer.array(), buffer.arrayOffset() + buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+      // If the remaining bytes size <= 64, the remaining bytes are unpacked by packer
+      for (; byteIndex < totalByteCount; byteIndex += bitWidth, valueIndex += 8) {
+        packer.unpack8Values(buffer.array(), buffer.arrayOffset() + buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+    } else {
+      for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += unpackCount) {
+        packerVector.unpackValuesVector(buffer, buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+      for (; byteIndex < totalByteCount; byteIndex += bitWidth, valueIndex += 8) {
+        packer.unpack8Values(buffer, buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+    }
+  }
+  public static void readBatch(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws EOFException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    int valueIndex = 0;
+    while (valueIndex < currentCount) {
+      // values are bit packed 8 at a time, so reading bitWidth will always work
+      ByteBuffer buffer = in.slice(bitWidth);
+      packer.unpack8Values(buffer, buffer.position(), currentBuffer, valueIndex);
+      valueIndex += 8;
+    }
+  }
+
+  public static Boolean supportVector() {
+    if (vector != null) {
+      return vector;
+    }
+    synchronized (ParquetReadRouter.class) {
+      if (vector == null) {
+        synchronized (ParquetReadRouter.class) {
+          vector = avx512Flag();
+        }
+      }
+    }
+    return vector;
+  }
+
+  private static boolean avx512Flag() {

Review Comment:
   Looks like these routines will be executed every time once `supportVector()` is called.



##########
parquet-encoding/src/main/java/org/apache/parquet/column/values/bitpacking/BytePacker.java:
##########
@@ -105,4 +116,26 @@ public void unpack8Values(final byte[] input, final int inPos, final int[] outpu
   public void unpack32Values(byte[] input, int inPos, int[] output, int outPos) {
     unpack32Values(ByteBuffer.wrap(input), inPos, output, outPos);
   }
+
+  /**
+   * unpack bitWidth bytes from input at inPos into {unpackCount} values in output at outPos using Java Vector API.
+   * @param input the input bytes
+   * @param inPos where to read from in input
+   * @param output the output values
+   * @param outPos where to write to in output
+   */
+  public void unpackValuesVector(final byte[] input, final int inPos, final int[] output, final int outPos) {
+
+  }
+
+  /**
+   * unpack bitWidth bytes from input at inPos into {unpackCount} values in output at outPos using Java Vector API.
+   * @param input the input bytes
+   * @param inPos where to read from in input
+   * @param output the output values
+   * @param outPos where to write to in output
+   */
+  public void unpackValuesVector(final ByteBuffer input, final int inPos, final int[] output, final int outPos) {
+

Review Comment:
   It is better to throw here and above?



##########
parquet-encoding/src/main/java/org/apache/parquet/column/values/bitpacking/BytePacker.java:
##########
@@ -105,4 +116,26 @@ public void unpack8Values(final byte[] input, final int inPos, final int[] outpu
   public void unpack32Values(byte[] input, int inPos, int[] output, int outPos) {
     unpack32Values(ByteBuffer.wrap(input), inPos, output, outPos);
   }
+
+  /**
+   * unpack bitWidth bytes from input at inPos into {unpackCount} values in output at outPos using Java Vector API.
+   * @param input the input bytes
+   * @param inPos where to read from in input
+   * @param output the output values
+   * @param outPos where to write to in output
+   */
+  public void unpackValuesVector(final byte[] input, final int inPos, final int[] output, final int outPos) {

Review Comment:
   Do we have a standard norm to define a function when it leverages the Vector API? Does it sound good to rename it to `unpackValuesUsingVector` or `vectorUnpackValues`? The current name is misleading.



##########
parquet-generator/src/main/java/org/apache/parquet/encoding/vectorbitpacking/BitPackingGeneratorVector.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.encoding.vectorbitpacking;
+
+import java.io.*;

Review Comment:
   Please do not use `*` in the import.



##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).
+ * For Intel CPU, Flags containing avx512vbmi and avx512_vbmi2 can have better performance gains.
+ */
+public class ParquetReadRouter {
+  private static final Logger LOG = LoggerFactory.getLogger(ParquetReadRouter.class);
+
+  private static volatile Boolean vector;
+
+  public static void read(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    if (supportVector()) {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    } else {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    }
+  }
+
+  public static void readBatchVector(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    BytePacker packerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);
+    int valueIndex = 0;
+    int byteIndex = 0;
+    int unpackCount = packerVector.getUnpackCount();
+    int inputByteCountPerVector = packerVector.getUnpackCount() / 8 * bitWidth;
+    int totalByteCount = currentCount * bitWidth / 8;
+
+    // register of avx512 are 512 bits, and can load up to 64 bytes

Review Comment:
   Can we make 64 bytes to be an input parameter? My intention is not to fix it so we can support other instruction sets as well. In my experience, sometimes AVX2 outperforms AVX512 in certain workloads, especially for bitpacking.



##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).
+ * For Intel CPU, Flags containing avx512vbmi and avx512_vbmi2 can have better performance gains.
+ */
+public class ParquetReadRouter {
+  private static final Logger LOG = LoggerFactory.getLogger(ParquetReadRouter.class);
+
+  private static volatile Boolean vector;
+
+  public static void read(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    if (supportVector()) {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    } else {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    }
+  }
+
+  public static void readBatchVector(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    BytePacker packerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);
+    int valueIndex = 0;
+    int byteIndex = 0;
+    int unpackCount = packerVector.getUnpackCount();
+    int inputByteCountPerVector = packerVector.getUnpackCount() / 8 * bitWidth;
+    int totalByteCount = currentCount * bitWidth / 8;
+
+    // register of avx512 are 512 bits, and can load up to 64 bytes
+    int totalByteCountVector = totalByteCount - 64;
+    ByteBuffer buffer = in.slice(totalByteCount);
+    if (buffer.hasArray()) {
+      for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += unpackCount) {
+        packerVector.unpackValuesVector(buffer.array(), buffer.arrayOffset() + buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+      // If the remaining bytes size <= 64, the remaining bytes are unpacked by packer
+      for (; byteIndex < totalByteCount; byteIndex += bitWidth, valueIndex += 8) {
+        packer.unpack8Values(buffer.array(), buffer.arrayOffset() + buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+    } else {
+      for (; byteIndex < totalByteCountVector; byteIndex += inputByteCountPerVector, valueIndex += unpackCount) {
+        packerVector.unpackValuesVector(buffer, buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+      for (; byteIndex < totalByteCount; byteIndex += bitWidth, valueIndex += 8) {
+        packer.unpack8Values(buffer, buffer.position() + byteIndex, currentBuffer, valueIndex);
+      }
+    }
+  }
+  public static void readBatch(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws EOFException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    int valueIndex = 0;
+    while (valueIndex < currentCount) {
+      // values are bit packed 8 at a time, so reading bitWidth will always work
+      ByteBuffer buffer = in.slice(bitWidth);
+      packer.unpack8Values(buffer, buffer.position(), currentBuffer, valueIndex);
+      valueIndex += 8;
+    }
+  }
+
+  public static Boolean supportVector() {
+    if (vector != null) {
+      return vector;
+    }
+    synchronized (ParquetReadRouter.class) {
+      if (vector == null) {
+        synchronized (ParquetReadRouter.class) {
+          vector = avx512Flag();
+        }
+      }
+    }
+    return vector;
+  }
+
+  private static boolean avx512Flag() {
+    try {
+      String os = System.getProperty("os.name");
+      if (os == null || !os.toLowerCase().startsWith("linux")) {
+        return false;
+      }
+      List<String> allLines = Files.readAllLines(Paths.get("/proc/cpuinfo"), StandardCharsets.UTF_8);
+      for (String line : allLines) {
+        if (line != null && line.startsWith("flags")) {
+          int index = line.indexOf(":");
+          if (index < 0) {
+            continue;
+          }
+          line = line.substring(index + 1);
+          Set<String> flagsSet = Arrays.stream(line.split(" ")).collect(Collectors.toSet());
+          if (flagsSet.contains("avx512vbmi") && flagsSet.contains("avx512_vbmi2")) {
+            return true;
+          }
+        }
+      }
+    } catch (Exception ex) {
+      LOG.warn("Not getting CPU info error");

Review Comment:
   ```suggestion
         LOG.warn("Failed to gett CPU info");
   ```



##########
parquet-column/src/main/java/org/apache/parquet/column/values/bitpacking/ParquetReadRouter.java:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.column.values.bitpacking;
+
+import org.apache.parquet.bytes.ByteBufferInputStream;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * This is a utils class which is used for big data applications(such as Spark Flink).
+ * For Intel CPU, Flags containing avx512vbmi and avx512_vbmi2 can have better performance gains.
+ */
+public class ParquetReadRouter {
+  private static final Logger LOG = LoggerFactory.getLogger(ParquetReadRouter.class);
+
+  private static volatile Boolean vector;
+
+  public static void read(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    if (supportVector()) {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    } else {
+      readBatchVector(bitWidth, in, currentCount, currentBuffer);
+    }
+  }
+
+  public static void readBatchVector(int bitWidth, ByteBufferInputStream in, int currentCount, int[] currentBuffer) throws IOException {
+    BytePacker packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth);
+    BytePacker packerVector = Packer.LITTLE_ENDIAN.newBytePackerVector(bitWidth);
+    int valueIndex = 0;
+    int byteIndex = 0;
+    int unpackCount = packerVector.getUnpackCount();
+    int inputByteCountPerVector = packerVector.getUnpackCount() / 8 * bitWidth;

Review Comment:
   Avoid magic numbers like 8 and 64 and declare them as constants.



##########
parquet-encoding/src/main/java/org/apache/parquet/column/values/bitpacking/BytePacker.java:
##########
@@ -31,6 +31,13 @@ public abstract class BytePacker {
 
   private final int bitWidth;
 
+  /**
+   * unpack the output int values at a time.

Review Comment:
   ```suggestion
      * Number of integer values to be unpacked at a time.
   ```



##########
parquet-encoding/src/main/java/org/apache/parquet/column/values/bitpacking/Packer.java:
##########
@@ -101,6 +121,10 @@ private static Object getStaticField(String className, String fieldName) {
    */
   public abstract BytePacker newBytePacker(int width);
 
+  public BytePacker newBytePackerVector(int width) {
+    throw new RuntimeException("This function must be implemented by subclasses!");

Review Comment:
   ```suggestion
       throw new RuntimeException("newBytePackerVector must be implemented by subclasses!");
   ```



##########
parquet-generator/src/main/java/org/apache/parquet/encoding/vectorbitpacking/BitPackingGeneratorVector.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.encoding.vectorbitpacking;
+
+import java.io.*;
+
+/**
+ * This class generates vector bit packers that pack the most significant bit first.
+ * The result of the generation is checked in. To regenerate the code run this class and check in the result.
+ */
+public class BitPackingGeneratorVector {
+  private static final String CLASS_NAME_PREFIX_FOR_INT = "ByteBitPackingVector";
+  private static final String CLASS_NAME_PREFIX_FOR_LONG = "ByteBitPackingVectorForLong";
+
+  public static void main(String[] args) throws Exception {
+    String basePath = args[0];
+    //TODO: Int for Big Endian

Review Comment:
   Would you mind opening the JIRAs to break down the work for better tracking?



##########
pom.xml:
##########
@@ -659,5 +666,74 @@
         </plugins>
       </build>
     </profile>
+
+    <profile>
+      <id>java17-target</id>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <configuration>
+              <release>17</release>
+              <compilerArgs combine.children="append">
+                <compilerArg>${extraJavaVectorTestArgs}</compilerArg>
+              </compilerArgs>
+            </configuration>
+          </plugin>
+
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <argLine>${surefire.argLine} ${extraJavaTestArgs} ${extraJavaVectorTestArgs}</argLine>
+              <systemPropertyVariables>

Review Comment:
   Why are these needed?



-- 
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: devnull-unsubscribe@infra.apache.org

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