wuchong commented on a change in pull request #12725:
URL: https://github.com/apache/flink/pull/12725#discussion_r443291174
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/CatalogTableSchemaResolver.java
##########
@@ -76,16 +78,16 @@ public TableSchema resolve(TableSchema tableSchema) {
for (int i = 0; i < tableSchema.getFieldCount(); ++i) {
TableColumn tableColumn =
tableSchema.getTableColumns().get(i);
DataType fieldType = fieldTypes[i];
- if (tableColumn.isGenerated() &&
isProctimeType(tableColumn.getExpr().get(), tableSchema)) {
+ DataType exprType = null;
+ if (tableColumn.isGenerated()) {
+ exprType =
resolveExpressionDataType(tableColumn.getExpr().get(), tableSchema);
+ }
+
+ if (exprType != null && isProctime(exprType)) {
if (fieldNames[i].equals(rowtime)) {
throw new TableException("Watermark can
not be defined for a processing time attribute column.");
Review comment:
I think we can move this exception check into `if
(tableColumn.isGenerated())` branch, then we don't need a `exprType != null`
check.
##########
File path:
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/catalog/CatalogSchemaTable.java
##########
@@ -183,7 +169,12 @@ private RelDataType getRowType(RelDataTypeFactory
typeFactory,
flinkTypeFactory,
tableSchema,
scala.Option.empty(),
- isStreamingMode);
+ isStreamingMode);
Review comment:
Indent.
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/CatalogTableSchemaResolver.java
##########
@@ -76,16 +78,16 @@ public TableSchema resolve(TableSchema tableSchema) {
for (int i = 0; i < tableSchema.getFieldCount(); ++i) {
TableColumn tableColumn =
tableSchema.getTableColumns().get(i);
DataType fieldType = fieldTypes[i];
- if (tableColumn.isGenerated() &&
isProctimeType(tableColumn.getExpr().get(), tableSchema)) {
+ DataType exprType = null;
+ if (tableColumn.isGenerated()) {
+ exprType =
resolveExpressionDataType(tableColumn.getExpr().get(), tableSchema);
+ }
+
+ if (exprType != null && isProctime(exprType)) {
if (fieldNames[i].equals(rowtime)) {
throw new TableException("Watermark can
not be defined for a processing time attribute column.");
}
- TimestampType originalType = (TimestampType)
fieldType.getLogicalType();
- LogicalType proctimeType = new TimestampType(
- originalType.isNullable(),
- TimestampKind.PROCTIME,
- originalType.getPrecision());
- fieldType =
TypeConversions.fromLogicalToDataType(proctimeType);
+ fieldType = exprType;
Review comment:
I think this should be moved into `if (tableColumn.isGenerated())`
branch, to make all computed columns result type correct.
##########
File path:
flink-table/flink-table-planner-blink/src/test/java/org/apache/flink/table/planner/catalog/JavaCatalogTableITCase.java
##########
@@ -0,0 +1,211 @@
+/*
+ * 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.catalog;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.TableConfig;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.api.Tumble;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.GenericInMemoryCatalog;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.planner.utils.TableTestBase;
+import org.apache.flink.table.planner.utils.TableTestUtil;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static org.apache.flink.table.api.Expressions.$;
+import static org.apache.flink.table.api.Expressions.lit;
+
+/**
+ * Tests for resolving types of computed columns (including time attributes)
of tables from catalog.
+ */
+@RunWith(Parameterized.class)
+public class JavaCatalogTableITCase extends TableTestBase {
Review comment:
`JavaCatalogTableTest`? I think this doesn't involve a whole Flink
cluster?
----------------------------------------------------------------
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]