NiFi can interface directly with Hive, HDFS, HBase, Flume and Phoenix. And I can also trigger Spark and Flink through Kafka and Site-To-Site. Sometimes I need to run some Pig scripts. Apache Pig is very stable and has a lot of functions and tools that make for some smart processing. You can easily augment and add this piece to a larger pipeline or part of the process.
I like to use Ambari to install the HDP 2.5 clients on my NiFi box to have access to all the tools I may need.
Then I can just do:
$ yum install pig
We call a shell script that wraps the Pig script.
Output of script is stored to HDFS: hdfs dfs -ls /nifi-logs
$ export JAVA_HOME=/opt/jdk1.8.0_101/
$ pig –x local –l /tmp/pig.log –f /opt/demo/pigscripts/test.pig
You can run in different Pig modes like local, mapreduce and tez. You can also pass in parameters or the script.
messages = LOAD ‘/opt/demo/HDF/centos7/tars/nifi/nifi-18.104.22.168.0.0.0-579/logs/nifi-app.log’;
warns = FILTER messages BY $0 MATCHES ‘.*WARN+.*’;
store warns into ‘warns.out’
This is a basic example from the internet, with the NIFI 1.0 log used as the source.
As an aside, I run a daily script with the schedule 1 * * * * ? to clean up my logs.
Simply: /bin/rm -rf /opt/demo/HDF/centos7/tars/nifi/nifi-22.214.171.124.0.0.0-579/logs/*2016*
Hadoop Configuration: /etc/hadoop/conf/core-site.xml
Pick a directory and store away.
126.96.36.199.5.0.0–124188.8.131.52.5.0.0–1245root2016–11–03 19:53:572016–11–03 19:53:59FILTER
Job Stats (time in seconds):
Successfully read 30469 records from: “/opt/demo/HDF/centos7/tars/nifi/nifi-184.108.40.206.0.0.0-579/logs/nifi-app.log”
Successfully stored 1347 records in: “file:/tmp/temp1540654561/tmp-600070101”
Total records written : 1347
Total bytes written : 0
Spillable Memory Manager spill count : 0
Total bags proactively spilled: 0
Total records proactively spilled: 0
ref : https://community.hortonworks.com/articles/64844/running-apache-pig-scripts-from-apache-nifi-and-st.html