jiayuasu commented on code in PR #3211: URL: https://github.com/apache/sedona/pull/3211#discussion_r3714872024
########## flink/src/main/java/org/apache/sedona/flink/AccGeometryCollectionTypeSerializer.java: ########## @@ -0,0 +1,186 @@ +/* + * 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.sedona.flink; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.api.common.typeutils.TypeSerializerSchemaCompatibility; +import org.apache.flink.api.common.typeutils.TypeSerializerSnapshot; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.sedona.flink.expressions.Accumulators.AccGeometryCollection; + +public class AccGeometryCollectionTypeSerializer extends TypeSerializer<AccGeometryCollection> { + + private static final long serialVersionUID = 1L; + + public static final AccGeometryCollectionTypeSerializer INSTANCE = + new AccGeometryCollectionTypeSerializer(); + + public AccGeometryCollectionTypeSerializer() {} + + @Override + public boolean isImmutableType() { + return false; + } + + @Override + public TypeSerializer<AccGeometryCollection> duplicate() { + return this; + } + + @Override + public AccGeometryCollection createInstance() { + return new AccGeometryCollection(); + } + + @Override + public AccGeometryCollection copy(AccGeometryCollection from) { + if (from == null) { + return null; + } + AccGeometryCollection copy = new AccGeometryCollection(); + copy.values = new ArrayList<>(from.values); Review Comment: `copy()` needs to clone the byte arrays as well. This only copies the list, so both accumulators still point at the same mutable `byte[]` values. Mutating one copy changes the other, which violates the deep-copy contract of `TypeSerializer.copy()`. ```suggestion copy.values = new ArrayList<>(from.values.size()); for (byte[] value : from.values) { copy.values.add(value.clone()); } ``` Could you add a small copy-isolation test too? -- 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]
