You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/05/28 02:38:38 UTC

[GitHub] [incubator-pinot] Jackie-Jiang commented on a change in pull request #6997: Add genericRow file reader and writer

Jackie-Jiang commented on a change in pull request #6997:
URL: https://github.com/apache/incubator-pinot/pull/6997#discussion_r641166681



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/processing/genericrow/GenericRowFileReader.java
##########
@@ -0,0 +1,85 @@
+/**
+ * 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.pinot.core.segment.processing.genericrow;
+
+import java.io.Closeable;
+import java.io.File;
+import java.io.IOException;
+import java.nio.ByteOrder;
+import java.util.List;
+import org.apache.pinot.segment.spi.memory.PinotDataBuffer;
+import org.apache.pinot.spi.data.FieldSpec;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+
+/**
+ * File reader for {@link GenericRow}. The input files should be generated by the {@link GenericRowFileWriter}.
+ */
+public class GenericRowFileReader implements Closeable {
+  private final int _numRows;
+  private final PinotDataBuffer _offsetBuffer;
+  private final PinotDataBuffer _dataBuffer;
+  private final GenericRowDeserializer _deserializer;
+
+  public GenericRowFileReader(File offsetFile, File dataFile, List<FieldSpec> fieldSpecs, boolean includeNullFields)
+      throws IOException {
+    long offsetFileLength = offsetFile.length();
+    _numRows = (int) (offsetFileLength >>> 3);
+    _offsetBuffer = PinotDataBuffer
+        .mapFile(offsetFile, true, 0L, offsetFileLength, ByteOrder.BIG_ENDIAN, "GenericRow offset buffer");
+    _dataBuffer = PinotDataBuffer
+        .mapFile(dataFile, true, 0L, dataFile.length(), PinotDataBuffer.NATIVE_ORDER, "GenericRow data buffer");
+    _deserializer = new GenericRowDeserializer(_dataBuffer, fieldSpecs, includeNullFields);
+  }
+
+  /**
+   * Returns the number of rows within the files.
+   */
+  public int getNumRows() {
+    return _numRows;
+  }
+
+  /**
+   * Reads the data of the given row id into the given reusable row.
+   */
+  public GenericRow read(int rowId, GenericRow reuse) {
+    long offset = _offsetBuffer.getLong((long) rowId << 3);
+    try {
+      _deserializer.deserialize(offset, reuse);
+    } catch (Exception e) {
+      System.out.println();

Review comment:
       Good catch! Forgot it while debugging :-(




-- 
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org