Glue

BigData Workflow Engine for Hadoop, Hbase, Netezza, Pig, Hive, Cascalog ...

SQL Select Example

TOC

Note: In all the examples ctx refer to the GlueContext in Workflow Process.

The SQL Result Objects returned are from the class (GroovyRowResult)[http://groovy.codehaus.org/api/groovy/sql/GroovyRowResult.html]

Select and write out results to a file
def file = ctx.sql.loadSql('mydb', 'select * from tbl')

Select and iterate over results

ctx.sql.eachSqlResult('mydb', 'select name, age from people', 
    { res -> 
        println "Name: ${res.name} age: ${res.age}"
    }
    
    //or in one line:
    
ctx.sql.eachSqlResult('mydb', 'select name, age from people',{ println "Name: ${it.name} age: ${it.age}" }
Select and write out results to a file
(def file (ctx-sql loadSql "mydb" "select * from tbl"))

Select and iterate over results

(def results (map #(get % "name") (ctx-sql eachSqlResult "mydb" "select name, age from people")))
Select and write out results to a file
def file = ctx.sql().loadSql("mydb", "select * from tbl")

Select and iterate over results

for rs in ctx.sql().eachSqlResult("mydb", "select name, age from people"):
    print(str(rs))