JingsongLi commented on a change in pull request #8682: [FLINK-12796][table-planner-blink] Introduce BaseArray and BaseMap to reduce conversion overhead to blink URL: https://github.com/apache/flink/pull/8682#discussion_r293650003
########## File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/typeutils/BaseMapSerializer.java ########## @@ -0,0 +1,273 @@ +/* + * 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.flink.table.typeutils; + +import org.apache.flink.api.common.ExecutionConfig; +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.api.java.typeutils.runtime.DataInputViewStream; +import org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream; +import org.apache.flink.core.memory.DataInputView; +import org.apache.flink.core.memory.DataOutputView; +import org.apache.flink.core.memory.MemorySegmentFactory; +import org.apache.flink.table.dataformat.BaseMap; +import org.apache.flink.table.dataformat.BinaryArray; +import org.apache.flink.table.dataformat.BinaryArrayWriter; +import org.apache.flink.table.dataformat.BinaryMap; +import org.apache.flink.table.dataformat.BinaryWriter; +import org.apache.flink.table.dataformat.GenericMap; +import org.apache.flink.table.types.InternalSerializers; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.util.SegmentsUtil; +import org.apache.flink.util.InstantiationUtil; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * Serializer for {@link BaseMap}. + */ +public class BaseMapSerializer extends TypeSerializer<BaseMap> { + + private final LogicalType keyType; + private final LogicalType valueType; + + private final TypeSerializer keySerializer; + private final TypeSerializer valueSerializer; + + private transient BinaryArray reuseKeyArray; + private transient BinaryArray reuseValueArray; + private transient BinaryArrayWriter reuseKeyWriter; + private transient BinaryArrayWriter reuseValueWriter; + + public BaseMapSerializer(LogicalType keyType, LogicalType valueType) { + this.keyType = keyType; + this.valueType = valueType; + + this.keySerializer = InternalSerializers.create(keyType, new ExecutionConfig()); + this.valueSerializer = InternalSerializers.create(valueType, new ExecutionConfig()); + } + + @Override + public boolean isImmutableType() { + return false; + } + + @Override + public TypeSerializer<BaseMap> duplicate() { + return new BaseMapSerializer(keyType, valueType); + } + + @Override + public BaseMap createInstance() { + return new BinaryMap(); + } + + @Override + public BaseMap copy(BaseMap from) { + if (from instanceof GenericMap) { + Map<Object, Object> fromMap = ((GenericMap) from).getMap(); + HashMap<Object, Object> toMap = new HashMap<>(); Review comment: This has nothing to do with `GenericMap`. If the user gives a wrong `Map`, it's wrong to turn it into a `BinaryMap` too. It is totally wrong... ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services