liyafan82 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_r293648012
 
 

 ##########
 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:
   "Just wrap user Map, users need to guarantee their logic."
   -> the users just guarantee that their Map works correctly according to the 
Map interface, but it does not mean their Map would work correctly when wrapped 
in a HashMap. Right?
   
   When that is the case, it may cause some weird problem which is hard to 
locate and debug. So this is not a reliable solution. 
   
   At the very least, we should write some comment in the JavaDoc about this 
explicitly.

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

Reply via email to