dawidwys commented on a change in pull request #10342: [FLINK-14967][table] Add a utility for creating data types via reflection URL: https://github.com/apache/flink/pull/10342#discussion_r351650028
########## File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/annotation/DataTypeHint.java ########## @@ -0,0 +1,241 @@ +/* + * 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.annotation; + +import org.apache.flink.annotation.PublicEvolving; +import org.apache.flink.api.common.typeutils.TypeSerializer; +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.types.DataType; +import org.apache.flink.table.types.inference.TypeInference; +import org.apache.flink.table.types.logical.LogicalType; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A hint that influences the reflection-based extraction of a {@link DataType}. + * + * <p>Data type hints can parameterize or replace the default extraction logic of individual function parameters + * and return types, structured classes, or fields of structured classes. An implementer can choose to + * what extent the default extraction logic should be modified. + * + * <p>The following examples show how to explicitly specify data types, how to parameterize the extraction + * logic, or how to accept any data type as an input data type: + * + * <p>{@code @DataTypeHint("INT")} defines an INT data type with a default conversion class. + * + * <p>{@code @DataTypeHint(value = "TIMESTAMP(3)", bridgedTo = java.sql.Timestamp.class)} defines a TIMESTAMP + * data type of millisecond precision with an explicit conversion class. + * + * <p>{@code @DataTypeHint(value = "RAW", rawSerializer = MyCustomSerializer.class)} defines a RAW data type + * with a custom serializer class. + * + * <p>{@code @DataTypeHint(version = V1, allowRawGlobally = TRUE)} parameterizes the extraction by requesting + * a extraction logic version of 1 and allowing the RAW data type in this structured type (and possibly + * nested fields). + * + * <p>{@code @DataTypeHint(bridgedTo = MyPojo.class, allowRawGlobally = TRUE)} defines that a type should be + * extracted from the given conversion class but with parameterized extraction for allowing RAW types. + * + * <p>{@code @DataTypeHint(inputGroup = ANY)} defines that the input validation should accept any + * data type. + * + * <p>Note: All hint parameters are optional. Hint parameters defined on top of a structured type are + * inherited by all (deeply) nested fields unless annotated differently. For example, all occurrences of + * {@link java.math.BigDecimal} will be extracted as {@code DECIMAL(12, 2)} if the enclosing structured + * class is annotated with {@code @DataTypeHint(defaultDecimalPrecision = 12, defaultDecimalScale = 2)}. Individual + * field annotations allow to deviate from those default values. + */ +@PublicEvolving +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) +public @interface DataTypeHint { + + // Note to implementers: + // Because "null" is not supported as an annotation value. Every annotation parameter has Review comment: nit: Maybe make it a bit stronger? `Every annotation *must* have some ...` ---------------------------------------------------------------- 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] With regards, Apache Git Services
