emkornfield commented on code in PR #3390: URL: https://github.com/apache/parquet-java/pull/3390#discussion_r2719770156
########## parquet-column/src/main/java/org/apache/parquet/column/values/alp/AlpValuesWriter.java: ########## @@ -0,0 +1,525 @@ +/* + * 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.alp; + +import static org.apache.parquet.column.values.alp.AlpConstants.*; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; +import org.apache.parquet.bytes.ByteBufferAllocator; +import org.apache.parquet.bytes.BytesInput; +import org.apache.parquet.bytes.CapacityByteArrayOutputStream; +import org.apache.parquet.column.Encoding; +import org.apache.parquet.column.values.ValuesWriter; + +/** + * ALP (Adaptive Lossless floating-Point) values writer. + * + * <p>ALP encoding converts floating-point values to integers using decimal scaling, + * then applies Frame of Reference (FOR) encoding and bit-packing. + * Values that cannot be losslessly converted are stored as exceptions. + * + * <p>Page Layout: + * <pre> + * ┌─────────┬────────────────┬────────────────┬─────────────┐ + * │ Header │ AlpInfo Array │ ForInfo Array │ Data Array │ + * │ 8 bytes │ 4B × N vectors │ 5B/9B × N │ Variable │ + * └─────────┴────────────────┴────────────────┴─────────────┘ + * </pre> + */ +public abstract class AlpValuesWriter extends ValuesWriter { + + protected final int initialCapacity; + protected final int pageSize; + protected final ByteBufferAllocator allocator; + protected CapacityByteArrayOutputStream outputStream; + + public AlpValuesWriter(int initialCapacity, int pageSize, ByteBufferAllocator allocator) { + this.initialCapacity = initialCapacity; + this.pageSize = pageSize; + this.allocator = allocator; + this.outputStream = new CapacityByteArrayOutputStream(initialCapacity, pageSize, allocator); + } + + @Override + public Encoding getEncoding() { + return Encoding.ALP; + } + + @Override + public void close() { + outputStream.close(); + } + + /** + * Float-specific ALP values writer. + */ + public static class FloatAlpValuesWriter extends AlpValuesWriter { + private float[] buffer; + private int count; + + public FloatAlpValuesWriter(int initialCapacity, int pageSize, ByteBufferAllocator allocator) { + super(initialCapacity, pageSize, allocator); + // Initial buffer size - will grow as needed + this.buffer = new float[Math.max(ALP_VECTOR_SIZE, initialCapacity / Float.BYTES)]; Review Comment: This should just be pageSize? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
