JingsongLi commented on a change in pull request #9168:  
[FLINK-13286][table-api] Port connector related validators to api-java-bridge
URL: https://github.com/apache/flink/pull/9168#discussion_r305192167
 
 

 ##########
 File path: 
flink-table/flink-table-api-java-bridge/src/main/java/org/apache/flink/table/descriptors/SchemaValidator.java
 ##########
 @@ -0,0 +1,287 @@
+/*
+ * 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.descriptors;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeutils.CompositeType;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.table.api.TableException;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.factories.TableFormatFactory;
+import org.apache.flink.table.sources.RowtimeAttributeDescriptor;
+import org.apache.flink.table.sources.tsextractors.TimestampExtractor;
+import org.apache.flink.table.sources.wmstrategies.WatermarkStrategy;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import static java.lang.String.format;
+import static org.apache.flink.table.descriptors.Rowtime.ROWTIME;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_CLASS;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_FROM;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_SERIALIZED;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_TYPE;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_TIMESTAMPS_TYPE_VALUE_FROM_FIELD;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_CLASS;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_DELAY;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_SERIALIZED;
+import static 
org.apache.flink.table.descriptors.Rowtime.ROWTIME_WATERMARKS_TYPE;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_FROM;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_NAME;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_PROCTIME;
+import static org.apache.flink.table.descriptors.Schema.SCHEMA_TYPE;
+
+/**
+ * Validator for {@link Schema}.
+ */
+@PublicEvolving
+public class SchemaValidator implements DescriptorValidator {
+
+       private final boolean isStreamEnvironment;
+       private final boolean supportsSourceTimestamps;
+       private final boolean supportsSourceWatermarks;
+
+       public SchemaValidator(boolean isStreamEnvironment, boolean 
supportsSourceTimestamps,
+                       boolean supportsSourceWatermarks) {
+               this.isStreamEnvironment = isStreamEnvironment;
+               this.supportsSourceTimestamps = supportsSourceTimestamps;
+               this.supportsSourceWatermarks = supportsSourceWatermarks;
+       }
+
+       @Override
+       public void validate(DescriptorProperties properties) {
+               Map<String, String> names = 
properties.getIndexedProperty(SCHEMA, SCHEMA_NAME);
+               Map<String, String> types = 
properties.getIndexedProperty(SCHEMA, SCHEMA_TYPE);
+
+               if (names.isEmpty() && types.isEmpty()) {
+                       throw new ValidationException(
+                                       format("Could not find the required 
schema in property '%s'.", SCHEMA));
+               }
+
+               boolean proctimeFound = false;
+
+               for (int i = 0; i < Math.max(names.size(), types.size()); i++) {
+                       properties.validateString(SCHEMA + "." + i + "." + 
SCHEMA_NAME, false, 1);
+                       properties.validateType(SCHEMA + "." + i + "." + 
SCHEMA_TYPE, false, false);
+                       properties.validateString(SCHEMA + "." + i + "." + 
SCHEMA_FROM, true, 1);
+                       // either proctime or rowtime
+                       String proctime = SCHEMA + "." + i + "." + 
SCHEMA_PROCTIME;
+                       String rowtime = SCHEMA + "." + i + "." + ROWTIME;
+                       if (properties.containsKey(proctime)) {
+                               // check the environment
+                               if (!isStreamEnvironment) {
+                                       throw new ValidationException(
+                                                       format("Property %s' is 
not allowed in a batch environment.", proctime));
 
 Review comment:
   nice catch

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