godfreyhe commented on a change in pull request #14878: URL: https://github.com/apache/flink/pull/14878#discussion_r584522069
########## File path: flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/serde/EnumTypes.java ########## @@ -0,0 +1,93 @@ +/* + * 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.planner.plan.nodes.exec.serde; + +import org.apache.flink.table.functions.FunctionKind; +import org.apache.flink.table.types.logical.TimestampKind; + +import org.apache.calcite.avatica.util.TimeUnitRange; +import org.apache.calcite.rel.type.StructKind; +import org.apache.calcite.sql.fun.SqlTrimFunction; + +import java.util.HashMap; +import java.util.Map; + +/** + * Registry of {@link Enum} classes that can be serialized to JSON. + * + * <p>Suppose you want to serialize the value {@link SqlTrimFunction.Flag#LEADING} to JSON. First, + * make sure that {@link SqlTrimFunction.Flag} is registered. The type will be serialized as + * "SYMBOL". The value will be serialized as the string "LEADING". + * + * <p>When we deserialize, we rely on the fact that the registered {@code enum} classes have + * distinct values. Therefore, knowing that {@code (type="SYMBOL", value="LEADING")} we can convert + * the string "LEADING" to the enum {@code Flag.LEADING}. + */ +@SuppressWarnings({"rawtypes", "unchecked"}) +public abstract class EnumTypes { + private EnumTypes() {} + + private static final Map<String, Enum<?>> ENUM_BY_NAME; Review comment: the shortcoming of the above approach is the registered enums' names must be unique. ---------------------------------------------------------------- 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: [email protected]
