zeppelin/docs/interpreter/groovy.md
dlukyanov 53a28a3a91 Groovy Interpreter for Apazhe Zeppelin [ZEPPELIN-2176]
### What is this PR for?
Groovy Interpreter

### What type of PR is it?
Feature

### Todos
* [ Tests ] - Task
* [ Documentation ] - Task

### What is the Jira issue?
[ZEPPELIN-2176]

### How should this be tested?
Follow the groovy interpreter documentation samples

### Questions:
* Does the licenses files need update? YES
* Is there breaking changes for older versions? NO
* Does this needs documentation? YES

Author: dlukyanov <dlukyanov@ukr.net>
Author: dm <dm>

Closes #2135 from dlukyanov/master and squashes the following commits:

faf213f [dlukyanov] ZEPPELIN-2176 comments from @AhyoungRyu - remove @author - remove commented code
89c3ed5 [dlukyanov] retry
ca65947 [dlukyanov] deprecated
3dd53e2 [dlukyanov] ZEPPELIN-2176 comments from @AhyoungRyu - Zeppelin follows Google Java code - interpreter alphabetical order in _navigation.html - direct link to MarkupBuilder in groovy help
fe08159 [dlukyanov] retry
ca8bea6 [dlukyanov] Update groovy.md
a5b37a1 [dlukyanov] ZEPPELIN-2176 https://github.com/apache/zeppelin/pull/2135#issuecomment-289308850 - Inside of docs directory, groovy.md will need some header to be compiled with Jekyll - Menu in docs also need link to groovy - .travis.yml we need add !groovy
4abf649 [dm] Merge branch 'master' of https://github.com/apache/zeppelin
41a1702 [dlukyanov] ZEPPELIN-2176 https://github.com/apache/zeppelin/pull/2135#issuecomment-288829494 - implement shared script variables - move docs - implement run methods
dd388b3 [dlukyanov] retry
b34b42a [dlukyanov] retry
0d7732a [dlukyanov] retry
2646fa8 [dlukyanov] ZEPPELIN-2176 groovy interpreter, fix unchecked, add to configs, move HTTP.groovy to resources to simplify build, add default z-properties
5fa26e0 [dlukyanov] ZEPPELIN-2176 groovy interpreter, fix unchecked, add to configs, move HTTP.groovy to resources to simplify build, add default z-properties
aa427cd [dlukyanov] retry
addf167 [dlukyanov] retry
db4c35b [dlukyanov] Update README.md
fa779ea [dlukyanov] groovy interpreter
2017-04-04 14:59:35 +09:00

3.3 KiB

layout title description group
page Apache Groovy Interpreter for Apache Zeppelin Apache Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax. interpreter

{% include JB/setup %}

Groovy Interpreter for Apache Zeppelin

Samples

%groovy
//get a parameter defined as z.angularBind('ngSearchParam', value, 'paragraph_id')
//g is a context object for groovy to avoid mix with z object
def param = g.angular('ngSearchParam')
//send request https://www.googleapis.com/customsearch/v1?q=ngSearchParam_value
def r = HTTP.get(
  //assume you defined the groovy interpreter property
  //   `search_baseurl`='https://www.googleapis.com/customsearch/v1'
  //in groovy object o.getProperty('A') == o.'A' == o.A == o['A']
  url : g.search_baseurl,
  query: [ q: param ],
  headers: [
    'Accept':'application/json',
    //'Authorization:' : g.getProperty('search_auth'),
  ] 
)
//check response code
if( r.response.code==200 ) {
  g.html().with{ 
    //g.html() renders %angular to output and returns groovy.xml.MarkupBuilder
    h2("the response ${r.response.code}")
    span( r.response.body )
    h2("headers")
    pre( r.response.headers.join('\n') )
  }
} else {
  //just to show that it's possible to use println with multiline groovy string to render output
  println("""%angular
    <script> alert ("code=${r.response.code} \n msg=${r.response.message}") </script>
  """)
}
%groovy

//renders a table with headers a, b, c  and two rows
g.table(
  [
    ['a','b','c'],
    ['a1','b1','c1'],
    ['a2','b2','c2'],
  ]
)

the g object

  • g.angular(String name)

Returns angular object by name. Look up notebook scope first and then global scope.

  • g.angularBind(String name, Object value)

Assign a new value into angular object name

  • java.util.Properties g.getProperties()

returns all properties defined for this interpreter

  • String g.getProperty('PROPERTY_NAME')
g.PROPERTY_NAME
g.'PROPERTY_NAME'
g['PROPERTY_NAME']
g.getProperties().getProperty('PROPERTY_NAME')

All above the accessor to named property defined in groovy interpreter. In this case with name PROPERTY_NAME

  • groovy.xml.MarkupBuilder g.html()

Starts or continues rendering of %angular to output and returns groovy.xml.MarkupBuilder MarkupBuilder is usefull to generate html (xml)

  • void g.table(obj)

starts or continues rendering table rows.

obj: List(rows) of List(columns) where first line is a header