Github user gengliangwang commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22878#discussion_r230041592
  
    --- Diff: 
external/avro/src/main/scala/org/apache/spark/sql/avro/AvroEncoder.scala ---
    @@ -0,0 +1,533 @@
    +/*
    + * 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.spark.sql.avro
    +
    +import java.io._
    +import java.util.{Map => JMap}
    +
    +import scala.collection.JavaConverters._
    +import scala.language.existentials
    +import scala.reflect.ClassTag
    +
    +import org.apache.avro.Schema
    +import org.apache.avro.Schema.Parser
    +import org.apache.avro.Schema.Type._
    +import org.apache.avro.generic.{GenericData, IndexedRecord}
    +import org.apache.avro.reflect.ReflectData
    +import org.apache.avro.specific.SpecificRecord
    +
    +import org.apache.spark.sql.Encoder
    +import org.apache.spark.sql.avro.SchemaConverters._
    +import org.apache.spark.sql.catalyst.InternalRow
    +import org.apache.spark.sql.catalyst.analysis.{GetColumnByOrdinal, 
UnresolvedExtractValue}
    +import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
    +import org.apache.spark.sql.catalyst.expressions._
    +import org.apache.spark.sql.catalyst.expressions.codegen._
    +import org.apache.spark.sql.catalyst.expressions.codegen.Block._
    +import org.apache.spark.sql.catalyst.expressions.objects.{LambdaVariable 
=> _, _}
    +import org.apache.spark.sql.catalyst.util.{ArrayBasedMapData, 
GenericArrayData}
    +import org.apache.spark.sql.types._
    +import org.apache.spark.unsafe.types.UTF8String
    +
    +/**
    + * A Spark-SQL Encoder for Avro objects
    + */
    +object AvroEncoder {
    +  /**
    +   * Provides an Encoder for Avro objects of the given class
    +   *
    +   * @param avroClass the class of the Avro object for which to generate 
the Encoder
    +   * @tparam T the type of the Avro class, must implement SpecificRecord
    +   * @return an Encoder for the given Avro class
    +   */
    +  def of[T <: SpecificRecord](avroClass: Class[T]): Encoder[T] = {
    +    AvroExpressionEncoder.of(avroClass)
    +  }
    +  /**
    +   * Provides an Encoder for Avro objects implementing the given schema
    +   *
    +   * @param avroSchema the Schema of the Avro object for which to generate 
the Encoder
    +   * @tparam T the type of the Avro class that implements the Schema, must 
implement IndexedRecord
    +   * @return an Encoder for the given Avro Schema
    +   */
    +  def of[T <: IndexedRecord](avroSchema: Schema): Encoder[T] = {
    --- End diff --
    
    In `from_avro`, we are using avro schema in json format string, should we 
consider change to that?


---

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

Reply via email to