Getting the first value from spark.sql.Row -
i have following json format :
{"request": {"tranchelist": {"tranche": [{"trancheid": "500192163","ownedamt": "26500000", "curr": "usd" }, { "trancheid": "500213369", "ownedamt": "41000000","curr": "usd"}]},"fxrateslist": {"fxratescontract": [{"currency": "chf","fxrate": "0.97919983706115"},{"currency": "aud", "fxrate": "1.2966804979253"},{ "currency": "usd","fxrate": "1"},{"currency": "sek","fxrate": "8.1561012531034"},{"currency": "nok", "fxrate": "8.2454981641398"},{"currency": "jpy","fxrate": "111.79999785344"},{"currency": "hkd","fxrate": "7.7568025218916"},{"currency": "gbp","fxrate": "0.69425159677867"}, {"currency": "eur","fxrate": "0.88991723769689"},{"currency": "dkk", "fxrate": "6.629598372301"}]},"isexcludedeals": "true","basecurrency": "usd"}}
the json read hdfs :
val hdfsrequest = spark.read.json("hdfs://localhost/user/request.json") val basecurrency = hdfsrequest.select("request.basecurrency").map(_.getstring(0)).collect.headoption var fxrates = hdfsrequest.select("request.fxrateslist.fxratescontract") val fxratesdf = fxrates.select(explode(fxrates("fxratescontract"))).todf("fxratescontract").select("fxratescontract.currency", "fxratescontract.fxrate").filter($"currency"===basecurrency.get) fxratesdf.show()
the output getting fxratesdf :
fxratesdf: org.apache.spark.sql.dataset[org.apache.spark.sql.row] = [currency: string, fxrate: string] +--------+------+ |currency|fxrate| +--------+------+ | usd| 1|
how can grab value of first row of fxrate column ?
Comments
Post a Comment