twalthr commented on a change in pull request #14996: URL: https://github.com/apache/flink/pull/14996#discussion_r582863696
########## File path: flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/SchemaResolutionTest.java ########## @@ -0,0 +1,366 @@ +/* + * 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.catalog; + +import org.apache.flink.core.testutils.FlinkMatchers; +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.api.Schema; +import org.apache.flink.table.api.TableConfig; +import org.apache.flink.table.api.TableSchema; +import org.apache.flink.table.expressions.ResolvedExpression; +import org.apache.flink.table.expressions.resolver.ExpressionResolver; +import org.apache.flink.table.expressions.utils.ResolvedExpressionMock; +import org.apache.flink.table.types.DataType; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.flink.table.types.logical.TimestampKind; +import org.apache.flink.table.types.logical.TimestampType; +import org.apache.flink.table.types.utils.DataTypeFactoryMock; +import org.apache.flink.table.utils.FunctionLookupMock; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.Optional; + +import static org.apache.flink.table.api.Expressions.callSql; +import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isProctimeAttribute; +import static org.apache.flink.table.types.logical.utils.LogicalTypeChecks.isRowtimeAttribute; +import static org.apache.flink.table.types.utils.TypeConversions.fromLogicalToDataType; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** Tests for {@link Schema}, {@link DefaultSchemaResolver}, and {@link ResolvedSchema}. */ +public class SchemaResolutionTest { + + private static final String COMPUTED_COLUMN_SQL = "orig_ts - INTERVAL '60' MINUTE"; + + private static final ResolvedExpression COMPUTED_COLUMN_RESOLVED = + new ResolvedExpressionMock(DataTypes.TIMESTAMP(3), () -> COMPUTED_COLUMN_SQL); + + private static final String WATERMARK_SQL = "ts - INTERVAL '5' SECOND"; + + private static final ResolvedExpression WATERMARK_RESOLVED = + new ResolvedExpressionMock(DataTypes.TIMESTAMP(3), () -> WATERMARK_SQL); + + private static final String PROCTIME_SQL = "PROCTIME()"; + + private static final ResolvedExpression PROCTIME_RESOLVED = + new ResolvedExpressionMock( + fromLogicalToDataType(new TimestampType(false, TimestampKind.PROCTIME, 3)), + () -> PROCTIME_SQL); + + private static final Schema SCHEMA = + Schema.newBuilder() + .primaryKeyNamed("primary_constraint", "id") // out of order + .column("id", DataTypes.INT().notNull()) + .column("counter", DataTypes.INT().notNull()) + .column("payload", "ROW<name STRING, age INT, flag BOOLEAN>") + .columnByMetadata("topic", DataTypes.STRING(), true) + .columnByMetadata("orig_ts", DataTypes.TIMESTAMP(3), "timestamp") + .columnByExpression("ts", callSql(COMPUTED_COLUMN_SQL)) // API expression Review comment: I wasn't aware that we support this. Then also the website docs are wrong. I will fix them. ---------------------------------------------------------------- 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]
