Last active
November 5, 2018 12:22
-
-
Save shatestest/fdeaba767d78e171bb6c08b359fbd1bf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object { | |
@throws(classOf[Exception]) | |
def process(ymlFilename:String):Option[QueryEntities] = { | |
val ymlFilePath = URLDecoder.decode(ymlFilename, "UTF-8") | |
Try(Source.fromFile(ymlFilePath).mkString.parseYaml) match { | |
case Success(yml) => { | |
println("Parsed") | |
import CustomYamlProtocol._ | |
try{ //some logic | |
println( " Input yml :: \n " + yml.prettyPrint) | |
val eties:QueryEntities = yml.convertTo[QueryEntities] | |
/* for (e: Entity <- eties.entities) { | |
println(" columnFamily : " + e.columnFamily) | |
println(" fromDate : " + e.fromDate) | |
println(f" toDate : " + e.toDate) | |
}*/ | |
println("done") | |
Some(eties) | |
//Some(yml.convertTo[QueryEntities]) | |
}catch{ | |
case e:Exception => e.printStackTrace() | |
//throw e | |
None | |
} | |
//evalYml(yml); | |
} | |
case Failure(error) => { | |
error.printStackTrace() | |
println("Unable to parse YAML") | |
None | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class QueryEntity(columnFamily: String, fromDate: Option[String], toDate: Option[String]) | |
case class QueryEntities(entities: List[QueryEntity]) | |
object Tester{ | |
def main(args:Array[String]) { | |
val ymlFilename ="some.yml"; | |
val entities: Option[QueryEntities] = InputYamlProcessor.process(ymlFilename) | |
for( e: QueryEntities <- entities ){ | |
/// this is not working | |
//How to access the columnFamily, fromData and toDate ? | |
} | |
} | |
} |
If I say like below
val entities:QueryEntities = InputYamlProcessor.process(ymlFilename)
//ERROR type mismatch; found : Option[com.snp.helpers.Model.QueryEntities] required: com.snp.helpers.Model.QueryEntities
for( e: QueryEntity <- entities ){ //error value filter is not a member of com.snp.helpers.Model.QueryEntities
e.columnFamily
}
Try it:
def main(args:Array[String]) {
val ymlFilename ="some.yml";
InputYamlProcessor.process(ymlFilename) match {
case Some(entities) => println(entities.columnFamily)
case None => println("error")
}
}
try remove the type on e
scala> case class Foo(s: String)
defined class Foo
scala> val a: Option[Foo] = Option(Foo("Hello"))
a: Option[Foo] = Some(Foo(Hello))
scala> for (x <- a) { println(x) }
Foo(Hello)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to call below snippet , How to access the columnFamily, fromData and toDate ?
val entities: Option[QueryEntities] = InputYamlProcessor.process(ymlFilename)
}