leaves12138 commented on code in PR #7917:
URL: https://github.com/apache/paimon/pull/7917#discussion_r3278404020


##########
paimon-mosaic/src/main/java/org/apache/paimon/format/mosaic/MosaicRecordsWriter.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.paimon.format.mosaic;
+
+import org.apache.paimon.arrow.ArrowBundleRecords;
+import org.apache.paimon.arrow.vector.ArrowFormatWriter;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.format.BundleFormatWriter;
+import org.apache.paimon.format.FileFormatFactory;
+import org.apache.paimon.io.BundleRecords;
+import org.apache.paimon.mosaic.ColumnStatistics;
+import org.apache.paimon.mosaic.MosaicWriter;
+import org.apache.paimon.mosaic.WriterOptions;
+import org.apache.paimon.types.RowType;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.types.pojo.Schema;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/** Mosaic records writer. */
+public class MosaicRecordsWriter implements BundleFormatWriter {
+
+    private final ArrowFormatWriter arrowFormatWriter;
+    private final MosaicWriter nativeWriter;
+    private final BufferAllocator allocator;
+    private final List<String> statsColumnNames;
+    @Nullable private MosaicWriterMetadata metadata;
+
+    public MosaicRecordsWriter(
+            OutputStream outputStream,
+            RowType rowType,
+            FileFormatFactory.FormatContext formatContext,
+            List<String> statsColumnNames,
+            int numBuckets,
+            String compression) {
+        this.statsColumnNames = statsColumnNames;
+        this.allocator = new RootAllocator();
+
+        int writeBatchSize = formatContext.writeBatchSize();
+        long writeBatchMemory = formatContext.writeBatchMemory().getBytes();
+
+        this.arrowFormatWriter =
+                new ArrowFormatWriter(rowType, writeBatchSize, true, 
allocator, writeBatchMemory);
+
+        Schema arrowSchema = 
arrowFormatWriter.getVectorSchemaRoot().getSchema();
+        WriterOptions options =
+                new WriterOptions()
+                        .compression(resolveCompression(compression))
+                        .zstdLevel(formatContext.zstdLevel())
+                        .numBuckets(numBuckets)
+                        .rowGroupMaxSize(writeBatchMemory);

Review Comment:
   `rowGroupMaxSize` is currently derived from `write.batch-memory`. That 
option controls the Arrow writer buffer memory, while Paimon exposes 
`file.block-size` through `FormatContext.blockSize()` for format block / 
row-group sizing. As a result, Mosaic ignores `file.block-size`, and tuning 
`write.batch-memory` unexpectedly changes the Mosaic row-group layout. Please 
wire `formatContext.blockSize()` when it is configured, and otherwise leave 
Mosaic's own default (or document the intended default explicitly).



##########
paimon-mosaic/src/main/java/org/apache/paimon/format/mosaic/MosaicRecordsWriter.java:
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.paimon.format.mosaic;
+
+import org.apache.paimon.arrow.ArrowBundleRecords;
+import org.apache.paimon.arrow.vector.ArrowFormatWriter;
+import org.apache.paimon.data.InternalRow;
+import org.apache.paimon.format.BundleFormatWriter;
+import org.apache.paimon.format.FileFormatFactory;
+import org.apache.paimon.io.BundleRecords;
+import org.apache.paimon.mosaic.ColumnStatistics;
+import org.apache.paimon.mosaic.MosaicWriter;
+import org.apache.paimon.mosaic.WriterOptions;
+import org.apache.paimon.types.RowType;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.VectorSchemaRoot;
+import org.apache.arrow.vector.types.pojo.Schema;
+
+import javax.annotation.Nullable;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/** Mosaic records writer. */
+public class MosaicRecordsWriter implements BundleFormatWriter {
+
+    private final ArrowFormatWriter arrowFormatWriter;
+    private final MosaicWriter nativeWriter;
+    private final BufferAllocator allocator;
+    private final List<String> statsColumnNames;
+    @Nullable private MosaicWriterMetadata metadata;
+
+    public MosaicRecordsWriter(
+            OutputStream outputStream,
+            RowType rowType,
+            FileFormatFactory.FormatContext formatContext,
+            List<String> statsColumnNames,
+            int numBuckets,
+            String compression) {
+        this.statsColumnNames = statsColumnNames;
+        this.allocator = new RootAllocator();
+
+        int writeBatchSize = formatContext.writeBatchSize();
+        long writeBatchMemory = formatContext.writeBatchMemory().getBytes();
+
+        this.arrowFormatWriter =
+                new ArrowFormatWriter(rowType, writeBatchSize, true, 
allocator, writeBatchMemory);
+
+        Schema arrowSchema = 
arrowFormatWriter.getVectorSchemaRoot().getSchema();
+        WriterOptions options =
+                new WriterOptions()
+                        .compression(resolveCompression(compression))
+                        .zstdLevel(formatContext.zstdLevel())
+                        .numBuckets(numBuckets)
+                        .rowGroupMaxSize(writeBatchMemory);
+        if (!statsColumnNames.isEmpty()) {
+            options.statsColumns(statsColumnNames.toArray(new String[0]));
+        }
+
+        this.nativeWriter = new MosaicWriter(outputStream, arrowSchema, 
options, allocator);
+    }
+
+    private static int resolveCompression(String compression) {
+        if (compression == null) {
+            return WriterOptions.COMPRESSION_ZSTD;
+        }
+        switch (compression) {
+            case "none":
+                // return WriterOptions.COMPRESSION_NONE;
+                return 0;
+            case "zstd":
+            default:

Review Comment:
   Thanks for wiring the compression argument. This still silently maps every 
value other than exact lower-case `none` and `zstd` to ZSTD. Paimon accepts 
values such as `lz4`, `snappy`, `gzip`, and options are generally 
case-insensitive; with `file.suffix.include.compression = true`, this can even 
create a `.lz4.mosaic` file whose Mosaic footer says ZSTD. Please normalize the 
value and fail fast for unsupported compressions instead of falling through to 
ZSTD, and add coverage for `none` plus an unsupported value. It would also be 
better for the Mosaic Java API to expose `COMPRESSION_NONE` instead of relying 
on magic `0`.



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

Reply via email to