Created 07-19-2018 12:58 PM
Hi everyone, now I am trying to submit a code from a textarea,
I succeded to send a simple code of operations, for example 5+7, 8-7,789/0, 47*7. The problem is when the user wants to submit a huge code with many strings, how can we get that automatically and send it to the apache livy server? In other words, how can I change this line : "data":"{\"code\": \"1 + 1\"}"?
This is what I did "data": "{\"code\": \""+code+"\"}", but i works only for operations!
Thank you very much!
Created 07-19-2018 01:19 PM
Please try the encodeURI or encodeURIComponent function as described here and let me know how that goes:
HTH
*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.
Created 07-19-2018 09:33 PM
Ok, what about this one?
var settings = { "async": true, "crossDomain": true, "url": "http://c24-node2:8999/sessions/<session_id>/statements", "method": "POST", "headers": { "Content-Type": "application/json", "X-Requested-By": "user", "Cache-Control": "no-cache", "Postman-Token": "aece2722-cbdd-48a2-ae9a-821aba97a2b6" }, "processData": false, "data": {code: $("#txt1").val()} } <br>
The above is using the val of the element id #txt1 you can change this to whatever id your input text box has.
Try with simple code first, once that is working you can try with the most complex cases.
HTH
Created 07-19-2018 11:19 PM
Hi @Felix Albani, it doesn't work.
And I would like to tell you that I am using a variable for getting the textarea value. The problem is, in my opinion, the kind of string I can send to the apache livy. I don't if there is an equivalent of this function textwrap.dedent() in javascript like this code
from this link : https://livy.incubator.apache.org/examples/. Thank you
data = { 'code': textwrap.dedent(""" val NUM_SAMPLES = 100000; val count = sc.parallelize(1 to NUM_SAMPLES).map { i => val x = Math.random(); val y = Math.random(); if (x*x + y*y < 1) 1 else 0 }.reduce(_ + _); println(\"Pi is roughly \" + 4.0 * count / NUM_SAMPLES)
""")}
Created 07-20-2018 06:45 PM
@Melchicédec NDUWAYO what about this funciton:
https://gist.github.com/malthe/02350255c759d5478e89
HTH
Created 07-20-2018 06:52 PM
Thank you @Felix Albani, I will test it and let you know.
Created 07-21-2018 06:08 PM
Hi @Felix Albani, I tried that function but it doesn't work also.
Thank you!
Created 07-19-2018 08:12 PM
Created 07-24-2018 10:40 AM
Hi everyone. By trying many examples, I saw that I can not send also many lines. It is not only the problem of quotes.
Thank you
Created 07-31-2018 04:26 PM
Hi. Do you have any example using apache livy with servlet in java? How to create a session and how to send a code to apache livy by java? Thank you