You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by it...@itri.org.tw on 2018/01/12 06:34:32 UTC
Use SQL to query IgniteRDD with scala at Zeppelin
Hi,
Below is my code and result where I am trying to query IgniteRDD through SQL statement with scala at Zeppelin.
First I use restful API to put a pair of data(key=10, val=45) into Ignite cache.
%python
import requests
requests.put("http://127.0.0.1:8080/ignite?cmd=put&key=10&val=45&cacheName=zeppelincache")
Result:
<Response [200]>
Then I execute the code below.
%spark
import org.apache.ignite.configuration._
import org.apache.ignite.spark._
val ic = new IgniteContext(sc,()=>new IgniteConfiguration())
val sharedRDD2 = ic.fromCache[Integer,Integer]("zeppelincache")
sharedRDD2.savePairs(sc.parallelize(1 to 3, 3).map(i => (i, i*2)))
sharedRDD2.collect
sharedRDD2.sql("select * from Integer").show()
Result:
import org.apache.ignite.configuration._
import org.apache.ignite.spark._
ic: org.apache.ignite.spark.IgniteContext = org.apache.ignite.spark.IgniteContext@7a017337
sharedRDD2: org.apache.ignite.spark.IgniteRDD[Int,Int] = IgniteRDD[136] at RDD at IgniteAbstractRDD.scala:32
res129: Array[(Int, Int)] = Array((1,2), (2,4), (3,6), (10,45))
+----+----+
|_KEY|_VAL|
+----+----+
| 1| 2|
| 2| 4|
| 3| 6|
+----+----+
1. Why can the collect command get the pair (10,45) but SQL statement can’t?
2. How to get the pair (10,45) through SQL statement?
Thanks.
--
本信件可能包含工研院機密資訊,非指定之收件者,請勿使用或揭露本信件內容,並請銷毀此信件。 This email may contain confidential information. Please do not use or disclose it in any way and delete it if you are not the intended recipient.
Re: Use SQL to query IgniteRDD with scala at Zeppelin
Posted by Alexey Popov <ta...@gmail.com>.
Hi,
Please note that REST protocol puts keys as String. So you have 3 Integer
keys and 1 String key in a cache.
That is the reason for your results.
You can find details in topic [1]
[1]
http://apache-ignite-users.70518.x6.nabble.com/Rest-API-PUT-command-syntax-tc19158.html
Thank you,
Alexey
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/