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_r293640912
 
 

 ##########
 File path: 
flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/typeutils/BaseArraySerializer.java
 ##########
 @@ -0,0 +1,280 @@
+/*
+ * 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.BaseArray;
+import org.apache.flink.table.dataformat.BinaryArray;
+import org.apache.flink.table.dataformat.BinaryArrayWriter;
+import org.apache.flink.table.dataformat.BinaryWriter;
+import org.apache.flink.table.dataformat.GenericArray;
+import org.apache.flink.table.dataformat.TypeGetterSetters;
+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.lang.reflect.Array;
+import java.util.Arrays;
+
+import static 
org.apache.flink.table.types.ClassLogicalTypeConverter.getInternalClassForType;
+
+/**
+ * Serializer for {@link BaseArray}.
+ */
+public class BaseArraySerializer extends TypeSerializer<BaseArray> {
+
+       private final LogicalType eleType;
+       private final TypeSerializer eleSer;
+
+       private transient BinaryArray reuseArray;
+       private transient BinaryArrayWriter reuseWriter;
+
+       public BaseArraySerializer(LogicalType eleType, ExecutionConfig conf) {
+               this.eleType = eleType;
+               this.eleSer = InternalSerializers.create(eleType, conf);
+       }
+
+       private BaseArraySerializer(LogicalType eleType, TypeSerializer eleSer) 
{
+               this.eleType = eleType;
+               this.eleSer = eleSer;
+       }
+
+       @Override
+       public boolean isImmutableType() {
+               return false;
+       }
+
+       @Override
+       public TypeSerializer<BaseArray> duplicate() {
+               return new BaseArraySerializer(eleType, eleSer.duplicate());
+       }
+
+       @Override
+       public BaseArray createInstance() {
+               return new BinaryArray();
+       }
+
+       @Override
+       public BaseArray copy(BaseArray from) {
+               return from instanceof GenericArray ?
+                               copyGenericArray((GenericArray) from) :
+                               ((BinaryArray) from).copy();
+       }
+
+       @Override
+       public BaseArray copy(BaseArray from, BaseArray reuse) {
+               return copy(from);
+       }
+
+       private GenericArray copyGenericArray(GenericArray array) {
+               Object arr;
+               if (array.isPrimitiveArray()) {
+                       switch (eleType.getTypeRoot()) {
+                               case BOOLEAN:
+                                       arr = Arrays.copyOf((boolean[]) 
array.getArray(), array.numElements());
+                                       break;
+                               case TINYINT:
+                                       arr = Arrays.copyOf((byte[]) 
array.getArray(), array.numElements());
+                                       break;
+                               case SMALLINT:
 
 Review comment:
   we don't support logicalType char now.

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