Hi, you can try this code. Hope that will help.

> <script src="
>> https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
>> "></script>
>
>
>> <!--Text Area for Code-->
>
> <textarea id="codearea">val calls =
>> spark.read.option("header","true").option("sep","|").csv("file:///home/user/Desktop/sample.csv")
>
> import spark.implicits._
>
> calls.createOrReplaceTempView("temp")
>
> val me = spark.sql("select * from temp limit 10") </textarea>
>
>
>> <script type="text/javascript">
>
>
>> var mycode = $("#codearea").val();
>
> $.ajax({
>
>     url: "http://localhost:8998/sessions";, //To create Livy session
>
>     /*beforeSend: function(xhr) {
>
>       xhr.setRequestHeader("Authorization", "Basic " +
>> btoa("username:password"));
>
>     },*/
>
>     type: 'POST',
>
>     dataType: 'json',
>
>     contentType: 'application/json',
>
>     processData: false,
>
>     data: '{"kind": "spark"}',
>
>     success: function (data) {
>
>       var result = JSON.parse(data);
>
>       var sessionid = result['id'];
>
>       $.ajax({
>
>     url: "http://localhost:8998/sessions/"+sessionid+"/statements";, // To
>> run statement
>
>     /*beforeSend: function(xhr) {
>
>       xhr.setRequestHeader("Authorization", "Basic " +
>> btoa("username:password"));
>
>     },*/
>
>     type: 'POST',
>
>     dataType: 'json',
>
>     contentType: 'application/json',
>
>     processData: false,
>
>     data: '{"file": "'+mycode+'", "kind": "spark"}',
>
>     success: function (data) {
>
>       alert(JSON.stringify(data));
>
>     },
>
>     error: function(){
>
>       alert("Cannot get data");
>
>     }
>
> });
>
>     },
>
>     error: function(){
>
>       alert("Cannot get data");
>
>     }
>
> });
>
>
>> </script>
>
>
On Thu, Jul 26, 2018 at 4:16 PM, Melchicédec NDUWAYO <
ndumelchipaul2...@gmail.com> wrote:

> Thank you Jeff Zhang for your response.
> Can you please, explain me step by step, how I can use that code, knowing
> that I have a form in which I have a textarea. In this textarea, users can
> write their codes.
> I want to send that code by Ajax to the apache livy and get response
> after. Can you, please how to do it with that code?
> Thank you very much.
>
> 2018-07-25 16:41 GMT+02:00 Jeff Zhang <zjf...@gmail.com>:
>
>>
>> It doesn't matter whether you send multiple lines, zeppelin also support
>> multiple lines of code. You can refer the code here.
>>
>> https://github.com/apache/zeppelin/blob/master/livy/src/main
>> /java/org/apache/zeppelin/livy/BaseLivyInterpreter.java
>>
>> Melchicédec NDUWAYO <ndumelchipaul2...@gmail.com>于2018年7月25日周三 下午7:53写道:
>>
>>> Hi everyone. I don't want to use zeppelin or jupyter. I have a web app
>>> and I want to allow users to write a spark code(scala) in a textarea and
>>> then submit that code to apache livy REST API and get result executions by
>>> ajax in jquery. Now I can send only small operations. But when it is a code
>>> with two lines or with quotes, I get an error.
>>> Thank you
>>>
>>> Le mer. 25 juil. 2018 à 10:51, Jeff Zhang <zjf...@gmail.com> a écrit :
>>>
>>>>
>>>> Check this for how to use livy in zeppelin
>>>>
>>>> https://zeppelin.apache.org/docs/0.8.0/interpreter/livy.html
>>>>
>>>>
>>>> Harsch, Tim <tim.har...@teradata.com>于2018年7月25日周三 上午8:30写道:
>>>>
>>>>> Indeed.  Both Jupyter notebooks can interface with Livy using spark
>>>>> magic https://github.com/jupyter-incubator/sparkmagic.   Zeppelin can
>>>>> as well, but I am less versed in how to configure it.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>>
>>>>> *Tim Harsch *Principal Software Engineer, Research & Development
>>>>>
>>>>> Teradata <http://www.teradata.com/>
>>>>> 2055 Laurelwood Road, Santa Clara, CA 95054
>>>>> <https://maps.google.com/?q=2055+Laurelwood+Road,+Santa+Clara,+CA+95054&entry=gmail&source=g>
>>>>> +1-925-960-3843 <(925)%20960-3843>
>>>>> tim.har...@teradata.com <your.n...@teradata.com>
>>>>> Teradata.com <http://www.teradata.com/>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> *From: *Melchicédec NDUWAYO <ndumelchipaul2...@gmail.com>
>>>>> *Reply-To: *"user@livy.incubator.apache.org" <
>>>>> user@livy.incubator.apache.org>
>>>>> *Date: *Tuesday, July 24, 2018 at 4:01 AM
>>>>> *To: *"user@livy.incubator.apache.org" <user@livy.incubator.apache.org
>>>>> >
>>>>> *Subject: *Apache livy and ajax
>>>>>
>>>>>
>>>>>
>>>>> Good morning everyone,
>>>>>
>>>>> is there someone who can tell me how I can send spark code from a
>>>>> textarea to the apache livy server by using ajax?
>>>>>
>>>>> Is that possible? Thank you very much.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>>
>>>>> Cordialement
>>>>>
>>>>> NDUWAYO Melchicédec
>>>>>
>>>>> Université Clermont Auvergne(UCA)
>>>>>
>>>>> [image: Image removed by sender.]
>>>>>
>>>>>
>>>>>
>>>>
>
>
> --
> Cordialement
> NDUWAYO Melchicédec
> Université Clermont Auvergne(UCA)
>
>
>

Reply via email to