yjshen commented on a change in pull request #1782:
URL: https://github.com/apache/arrow-datafusion/pull/1782#discussion_r802429457



##########
File path: datafusion/src/row/mod.rs
##########
@@ -0,0 +1,333 @@
+// 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.
+
+//! An implementation of Row backed by raw bytes
+//!
+//! Each tuple consists of up to three parts: [null bit set] [values] [var 
length data]
+//!
+//! The null bit set is used for null tracking and is aligned to 1-byte. It 
stores
+//! one bit per field.
+//!
+//! In the region of the values, we store the fields in the order they are 
defined in the schema.
+//! - For fixed-length, sequential access fields, we store them directly.
+//!       E.g., 4 bytes for int and 1 byte for bool.
+//! - For fixed-length, update often fields, we store one 8-byte word per 
field.
+//! - For fields of non-primitive or variable-length types,
+//!       we append their actual content to the end of the var length region 
and
+//!       store their offset relative to row base and their length, packed 
into an 8-byte word.
+
+use arrow::datatypes::{DataType, Schema};
+use std::sync::Arc;
+
+mod bitmap;
+mod reader;
+mod writer;
+
+const UTF8_DEFAULT_SIZE: usize = 20;
+const BINARY_DEFAULT_SIZE: usize = 100;
+
+/// Get relative offsets for each field and total width for values
+fn get_offsets(null_width: usize, schema: &Arc<Schema>) -> (Vec<usize>, usize) 
{
+    let mut offsets = vec![];
+    let mut offset = null_width;
+    for f in schema.fields() {
+        offsets.push(offset);
+        offset += type_width(f.data_type());
+    }
+    (offsets, offset - null_width)
+}
+
+fn supported_type(dt: &DataType) -> bool {
+    use DataType::*;
+    matches!(
+        dt,
+        Boolean
+            | UInt8
+            | UInt16
+            | UInt32
+            | UInt64
+            | Int8
+            | Int16
+            | Int32
+            | Int64
+            | Float32
+            | Float64
+            | Date32
+            | Date64
+            | Utf8
+            | Binary
+    )
+}
+
+fn var_length(dt: &DataType) -> bool {
+    use DataType::*;
+    matches!(dt, Utf8 | Binary)
+}
+
+fn type_width(dt: &DataType) -> usize {
+    use DataType::*;
+    if var_length(dt) {
+        return 8;

Review comment:
       Great idea! I temporarily use `size_of::<u64>()`, and I can make it a 
type parameter for `RowWriter` and `RowReader` as we do for StringArray and 
LargeStringArray, for memory-saving purposes.




-- 
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: github-unsubscr...@arrow.apache.org

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


Reply via email to