ahmedabu98 commented on code in PR #25927:
URL: https://github.com/apache/beam/pull/25927#discussion_r1170339956


##########
sdks/java/io/file-schema-transform/src/main/java/org/apache/beam/sdk/io/fileschematransform/FileReadSchemaTransformConfiguration.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.beam.sdk.io.fileschematransform;
+
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import com.google.auto.value.AutoValue;
+import java.util.Set;
+import javax.annotation.Nullable;
+import org.apache.beam.sdk.schemas.AutoValueSchema;
+import org.apache.beam.sdk.schemas.annotations.DefaultSchema;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Strings;
+import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Sets;
+
+@SuppressWarnings({
+  "nullness" // TODO(https://github.com/apache/beam/issues/20497)
+})
+@DefaultSchema(AutoValueSchema.class)
+@AutoValue
+public abstract class FileReadSchemaTransformConfiguration {
+  static final Set<String> VALID_FORMATS = Sets.newHashSet("avro", "parquet", 
"json", "line");
+
+  public void validate() {
+    checkArgument(
+        !Strings.isNullOrEmpty(this.getFormat()) && 
VALID_FORMATS.contains(this.getFormat()),
+        "A valid file format must be specified. Please specify one of: "
+            + VALID_FORMATS.toString());
+
+    if (!this.getFormat().equals("line")) {
+      checkArgument(
+          !Strings.isNullOrEmpty(this.getSchema()),
+          String.format(
+              "A schema must be specified when reading files with %s format. 
You may provide a schema string or a path to a file containing the schema.",
+              this.getFormat()));
+    }

Review Comment:
   Thanks for the analysis Damon! How would it look like for Python to send a 
Schema object? I'd prefer using a String for now to keep the cross-language 
use-case simple. 
   
   > I'm struggling with the need for someone to look into this code to 
determine that schema is required for all of the formats except for line
   
   Would it help to improve the error message? I can include all the formats 
that do require a schema.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to