Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Scala - not able to get schema from Avro class

Scala - not able to get schema from Avro class

Expert Contributor

I have an Avro generated class - com.avro.Person which has a method -> getClassSchema.

I’m passing className to a method, and in the method I need to get the Avro schema.

Here is the code I’m using:

val pr = Class.forName(productCls) // where productCls = classOf[Product].getName 

How do I call the method getClassSchema of this class ?

Additional Info :

Links to Person.java & Person.avsc

Person.java

[https://drive.google.com/open?id=1LOa_muN0tFSEm-VReOBDh3ozU3ufmLZQ]

Person.avsc

[https://drive.google.com/open?id=1evVW9bTy5bOqq6h_oCyhXDFv9Fuz6zUn][1]

In Person.java, there is a method

public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; } 

I'm trying to call this method to get the AVRO schema corresponding to class - Person Code

import com.avro.Person  
val m1 = Map("schema.class" -> classOf[Person].getName) 

This Map is passed onto a function .. say foo, and i'm trying to get the schema based on the class

def foo(m : Map[String, String]){
    val personClass = Map("schema.class")
    val pr = Class.forName(personClass) 
    //TBD - to get the schema of the avro class
} 


Now using this "pr", i need to get the avro schema of the Person avro, hence i'm trying to call method getClassSchema, which returns the schema 

How do i do this  ?
any help on this is really appreciated.


1 REPLY 1
Highlighted

Re: Scala - not able to get schema from Avro class

Expert Contributor

@Timothy Spann - looping you in, any ideas on this ?