You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/02/14 07:07:12 UTC

[GitHub] [spark] dongjoon-hyun commented on a change in pull request #31543: [SPARK-34416] Adding support for user provided schema url in Avro

dongjoon-hyun commented on a change in pull request #31543:
URL: https://github.com/apache/spark/pull/31543#discussion_r575764801



##########
File path: external/avro/src/main/scala/org/apache/spark/sql/avro/AvroOptions.scala
##########
@@ -47,7 +51,25 @@ private[sql] class AvroOptions(
    * schema converted by Spark. For example, the expected schema of one column is of "enum" type,
    * instead of "string" type in the default converted schema.
    */
-  val schema: Option[String] = parameters.get("avroSchema")
+  val schema: Option[Schema] = {
+

Review comment:
       Could you remove this empty line?

##########
File path: external/avro/src/main/scala/org/apache/spark/sql/avro/AvroOptions.scala
##########
@@ -47,7 +51,25 @@ private[sql] class AvroOptions(
    * schema converted by Spark. For example, the expected schema of one column is of "enum" type,
    * instead of "string" type in the default converted schema.
    */
-  val schema: Option[String] = parameters.get("avroSchema")
+  val schema: Option[Schema] = {
+
+    parameters.get("avroSchema").map(new Schema.Parser().parse).orElse({
+

Review comment:
       ditto.

##########
File path: external/avro/src/main/scala/org/apache/spark/sql/avro/AvroOptions.scala
##########
@@ -47,7 +51,25 @@ private[sql] class AvroOptions(
    * schema converted by Spark. For example, the expected schema of one column is of "enum" type,
    * instead of "string" type in the default converted schema.
    */
-  val schema: Option[String] = parameters.get("avroSchema")
+  val schema: Option[Schema] = {
+
+    parameters.get("avroSchema").map(new Schema.Parser().parse).orElse({
+
+      val avroUrlSchema = parameters.get("avroSchemaUrl").map(schemaFSUrl => {
+        log.info("loading avro schema from url: " + schemaFSUrl)
+        val fs = FileSystem.get(new URI(schemaFSUrl), conf)
+        val in = fs.open(new Path(schemaFSUrl))
+        try {
+          new Schema.Parser().parse(in)
+        } finally {
+          in.close()
+        }
+      })
+

Review comment:
       ditto.

##########
File path: external/avro/src/main/scala/org/apache/spark/sql/avro/AvroOptions.scala
##########
@@ -47,7 +51,25 @@ private[sql] class AvroOptions(
    * schema converted by Spark. For example, the expected schema of one column is of "enum" type,
    * instead of "string" type in the default converted schema.
    */
-  val schema: Option[String] = parameters.get("avroSchema")
+  val schema: Option[Schema] = {
+
+    parameters.get("avroSchema").map(new Schema.Parser().parse).orElse({
+
+      val avroUrlSchema = parameters.get("avroSchemaUrl").map(schemaFSUrl => {
+        log.info("loading avro schema from url: " + schemaFSUrl)
+        val fs = FileSystem.get(new URI(schemaFSUrl), conf)
+        val in = fs.open(new Path(schemaFSUrl))
+        try {
+          new Schema.Parser().parse(in)
+        } finally {
+          in.close()
+        }
+      })
+
+      avroUrlSchema
+    })
+

Review comment:
       ditto.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org