Skip to content

Instantly share code, notes, and snippets.

<named-native-query name="ObjectType.updateLocation">
<query>
<![CDATA[
update object_type set location = :location where id in (
with recursive tree (child) as (
values(:parent_id)
union
select ot.id from object_type ot, tree where ot.parent_id = child and ot.direct_location = false)
select child from tree)
]]>
# issue movies query
conf = {"es.resource" : "movies/logs", "es.query" : "?q=name:bourne"}
movies = sc.newAPIHadoopRDD("org.elasticsearch.hadoop.mr.EsInputFormat",\
"org.apache.hadoop.io.NullWritable", "org.elasticsearch.hadoop.mr.LinkedMapWritable", conf=conf)
# place results in table
moviesRows = movies.map(lambda p: Row(id=int(p[1]['id']), name=p[1]['name']))
moviesRowsList = moviesRows.collect()
schemaMovies = sqlContext.createDataFrame(moviesRowsList)
schemaMovies.registerTempTable("movies")