Using GrovePi with Raspberry Pi and MiNiFi Agents for Data Ingest to Parquet, Kudu, ORC, Kafka, Hive and Impala
Tags: agent, apachekafka, apachenifi, apachenifi19
Published: 2019-12-02 19:21:27

---
title: Using GrovePi with Raspberry Pi and MiNiFi Agents for Data Ingest to Parquet, Kudu, ORC, Kafka, Hive and Impala
published: true
date: 2019-10-10 21:06:00 UTC
tags: agent,apache-kafka,apache-nifi,apache-nifi-1.9
canonical_url: 
---

### Using GrovePi with Raspberry Pi and MiNiFi Agents for Data Ingest
  
**Source Code: **  [https://github.com/tspannhw/minifi-grove-sensors](https://github.com/tspannhw/minifi-grove-sensors)  
  
Acquiring sensor data from Grove sensors is easy using a GrovePi Hat and some compatible sensors.  
  

[![](https://1.bp.blogspot.com/-UlZXk8zKscA/XZ-ZZm2AWCI/AAAAAAAAYkI/d0izUGWqoH4c5oZ1DFLdy33DtpigYBDPQCLcBGAsYHQ/s640/IMG-4829.jpg)](https://1.bp.blogspot.com/-UlZXk8zKscA/XZ-ZZm2AWCI/AAAAAAAAYkI/d0izUGWqoH4c5oZ1DFLdy33DtpigYBDPQCLcBGAsYHQ/s1600/IMG-4829.jpg)

  

Just before my talk at the Future of Data Meetup @ Bell Works in Holmdel, NJ, I thought I should ingest some data from a grove sensor interface.

  

It's so easy a sleeping cat could do it.
  

[![](https://1.bp.blogspot.com/-xyoyCZYrI64/XZ-ZZq03zPI/AAAAAAAAYkM/ZC40YoLCIUotPGKiz2hCKsg5MCAFih2qgCLcBGAsYHQ/s640/IMG-4837.jpg)](https://1.bp.blogspot.com/-xyoyCZYrI64/XZ-ZZq03zPI/AAAAAAAAYkM/ZC40YoLCIUotPGKiz2hCKsg5MCAFih2qgCLcBGAsYHQ/s1600/IMG-4837.jpg)
  

[![](https://1.bp.blogspot.com/-EUYnUrbnsxA/XZ-ZZjprtoI/AAAAAAAAYkE/a7YOp0lb3Vk5N5MZSM_Qy6EZ4E-590kqQCLcBGAsYHQ/s320/IMG-4839.jpg)](https://1.bp.blogspot.com/-EUYnUrbnsxA/XZ-ZZjprtoI/AAAAAAAAYkE/a7YOp0lb3Vk5N5MZSM_Qy6EZ4E-590kqQCLcBGAsYHQ/s1600/IMG-4839.jpg)

  

  

### So what does this device look like?  
  

[![](https://1.bp.blogspot.com/-i-I6WEphT7U/XZ-Zh7BFHXI/AAAAAAAAYkQ/lYqtgYDL6K4hv8NhRKgAow-5tmHF73ZyACLcBGAsYHQ/s640/IMG-4889.jpg)](https://1.bp.blogspot.com/-i-I6WEphT7U/XZ-Zh7BFHXI/AAAAAAAAYkQ/lYqtgYDL6K4hv8NhRKgAow-5tmHF73ZyACLcBGAsYHQ/s1600/IMG-4889.jpg)

  

### I have a temperature and humidity sensor on there.
  

[![](https://1.bp.blogspot.com/-T2nh1Aq71Pc/XZ-Zh1ShVdI/AAAAAAAAYkU/8DBWQtstuFwB2sr7nFc0cXaN18tG1xfXQCLcBGAsYHQ/s640/IMG-4890.jpg)](https://1.bp.blogspot.com/-T2nh1Aq71Pc/XZ-Zh1ShVdI/AAAAAAAAYkU/8DBWQtstuFwB2sr7nFc0cXaN18tG1xfXQCLcBGAsYHQ/s1600/IMG-4890.jpg)

  

  

### The distance sonic sensor is in there too, that's for the next article.
  

[![](https://1.bp.blogspot.com/-lg6R784wjtI/XZ-ZhxOorII/AAAAAAAAYkY/J2j2zbMNSvgjfa_sNYCbZN5iK63ZcK3TACLcBGAsYHQ/s640/IMG-4891.jpg)](https://1.bp.blogspot.com/-lg6R784wjtI/XZ-ZhxOorII/AAAAAAAAYkY/J2j2zbMNSvgjfa_sNYCbZN5iK63ZcK3TACLcBGAsYHQ/s1600/IMG-4891.jpg)
  

[![](https://1.bp.blogspot.com/-IYghWtRnWE4/XZ-ZiQ3FIEI/AAAAAAAAYkc/CCoZbOCKSlsEoivC4R9K1P7ECx9sMgT_wCLcBGAsYHQ/s640/IMG-4892.jpg)](https://1.bp.blogspot.com/-IYghWtRnWE4/XZ-ZiQ3FIEI/AAAAAAAAYkc/CCoZbOCKSlsEoivC4R9K1P7ECx9sMgT_wCLcBGAsYHQ/s1600/IMG-4892.jpg)

  

### Let's do this with minimal RAM.
  

[![](https://1.bp.blogspot.com/-txJ2swRqlQQ/XZ-Zip_cUDI/AAAAAAAAYkg/g5ZhIiax3qQY6r88X1PuU7jrSDy3WeshQCLcBGAsYHQ/s640/IMG-4893.jpg)](https://1.bp.blogspot.com/-txJ2swRqlQQ/XZ-Zip_cUDI/AAAAAAAAYkg/g5ZhIiax3qQY6r88X1PuU7jrSDy3WeshQCLcBGAsYHQ/s1600/IMG-4893.jpg)

  

  

### That's a 64GB hard drive underneath in the white case with the RPI.
  
  

[![](https://1.bp.blogspot.com/-8zmyt4xYylo/XZ-Zi1OyGjI/AAAAAAAAYkk/N8EAZUEBBRQI1XlDScJGYAR5TOpZjM9twCLcBGAsYHQ/s640/IMG-4894.jpg)](https://1.bp.blogspot.com/-8zmyt4xYylo/XZ-Zi1OyGjI/AAAAAAAAYkk/N8EAZUEBBRQI1XlDScJGYAR5TOpZjM9twCLcBGAsYHQ/s1600/IMG-4894.jpg)
  

###   
I need more data and BACON.
  

[![](https://1.bp.blogspot.com/-5UIxbd5LmN4/XZ-Zi4KX-uI/AAAAAAAAYko/l2nUgDOAUyog4DI8oB8H3KtfJABpwM7zACLcBGAsYHQ/s640/IMG-4896.jpg)](https://1.bp.blogspot.com/-5UIxbd5LmN4/XZ-Zi4KX-uI/AAAAAAAAYko/l2nUgDOAUyog4DI8oB8H3KtfJABpwM7zACLcBGAsYHQ/s1600/IMG-4896.jpg)
  

### We design our MiNiFi Agent Flow in CEM/EFM.   Grab JSON data stream and run sensors.
[![](https://1.bp.blogspot.com/-X3RNf01vmR0/XZ-WVZrEVCI/AAAAAAAAYjM/f8p5ai0K4DEfPQGYLgu445-scgXNhdFEACLcBGAsYHQ/s640/grovepijavaefmflow.png)](https://1.bp.blogspot.com/-X3RNf01vmR0/XZ-WVZrEVCI/AAAAAAAAYjM/f8p5ai0K4DEfPQGYLgu445-scgXNhdFEACLcBGAsYHQ/s1600/grovepijavaefmflow.png)  

### Apache NiFi 1.9.2 / CFM 1.0 Received HTTPS S2S Events From MiNiFi Agent
  
[![](https://1.bp.blogspot.com/-w36MEjlJgKw/XZ-WT9eB2gI/AAAAAAAAYi4/LwVCRVgyu4cnjaiQvM1Kv5C7NMRQbFeKQCLcBGAsYHQ/s640/groveinput.png)](https://1.bp.blogspot.com/-w36MEjlJgKw/XZ-WT9eB2gI/AAAAAAAAYi4/LwVCRVgyu4cnjaiQvM1Kv5C7NMRQbFeKQCLcBGAsYHQ/s1600/groveinput.png)  
  

### A simple flow to query and convert our JSON data, then store it to Kudu and HDFS (ORC) as well as push it to Kafka with a schema.
  

[![](https://1.bp.blogspot.com/-j9ZX41KoDJM/XZ-WTz3JKgI/AAAAAAAAYi0/hZrgfVYR7nsAH_YplmqbhOWEHHoFgpqUgCLcBGAsYHQ/s640/groveToKafkaKuduOrc.png)](https://1.bp.blogspot.com/-j9ZX41KoDJM/XZ-WTz3JKgI/AAAAAAAAYi0/hZrgfVYR7nsAH_YplmqbhOWEHHoFgpqUgCLcBGAsYHQ/s1600/groveToKafkaKuduOrc.png)

  

  

### Let's read that Kafka message and store to Parquet, we will push to MQTT and JMS in the next article.   This is our universal proxy/gateway.
  

[![](https://1.bp.blogspot.com/-_0XBjefBda0/XZ-WV8K9ieI/AAAAAAAAYjU/JM84_P7nN_IH7sARD_Tub3CY1Agk9CcUQCLcBGAsYHQ/s640/kafkaToParquetGrove.png)](https://1.bp.blogspot.com/-_0XBjefBda0/XZ-WV8K9ieI/AAAAAAAAYjU/JM84_P7nN_IH7sARD_Tub3CY1Agk9CcUQCLcBGAsYHQ/s1600/kafkaToParquetGrove.png)

###   
We could infer a schema and not save it.   But by saving a schema to the schema registry it makes SMM, Kafka, NiFi and others schema aware and easy to automagically query and convert between CSV/JSON/XML/AVRO/Parquet and more.

### [![](https://1.bp.blogspot.com/-iq1mECT0L6E/XZ-WViV8-xI/AAAAAAAAYjQ/KIIj_mLCI88W4C75fCSdN6iFkDi5YswFwCLcBGAsYHQ/s640/groveschema.png)](https://1.bp.blogspot.com/-iq1mECT0L6E/XZ-WViV8-xI/AAAAAAAAYjQ/KIIj_mLCI88W4C75fCSdN6iFkDi5YswFwCLcBGAsYHQ/s1600/groveschema.png)

### Let's store the data in Parquet files on HDFS with an Impala table.   In Apache [NiFi 1.10 there is a ParquetWriter](https://www.linkedin.com/pulse/apache-nifi-110-sneak-peak-timothy-spann/). 
  

[![](https://1.bp.blogspot.com/-VN095CNuuFg/XZ-WWBhMiLI/AAAAAAAAYjY/FLA0vXUxFJM4YW7K9l8SUJNtaGLtpKG_gCLcBGAsYHQ/s640/putParquetGrove.png)](https://1.bp.blogspot.com/-VN095CNuuFg/XZ-WWBhMiLI/AAAAAAAAYjY/FLA0vXUxFJM4YW7K9l8SUJNtaGLtpKG_gCLcBGAsYHQ/s1600/putParquetGrove.png)

  

### Before we push to Kafka, let's create a topic for it with Cloudera SMM
  

[![](https://1.bp.blogspot.com/-aHsCaEoxubs/XZ-WTBDe_JI/AAAAAAAAYio/uKmu-wJ0iUYLGacregs4V10qKDb6ySfXQCLcBGAsYHQ/s640/creategrovekafkatopic.png)](https://1.bp.blogspot.com/-aHsCaEoxubs/XZ-WTBDe_JI/AAAAAAAAYio/uKmu-wJ0iUYLGacregs4V10qKDb6ySfXQCLcBGAsYHQ/s1600/creategrovekafkatopic.png)

  

### Let's build an impala table for that Kudu data.
  

[![](https://1.bp.blogspot.com/-9AzkeSlegfE/XZ-WTMKdRqI/AAAAAAAAYis/QHLbCj7mBRYOJhD4Rj1u16evCkfNzVw8QCLcBGAsYHQ/s640/creategrovesensorskudu.png)](https://1.bp.blogspot.com/-9AzkeSlegfE/XZ-WTMKdRqI/AAAAAAAAYis/QHLbCj7mBRYOJhD4Rj1u16evCkfNzVw8QCLcBGAsYHQ/s1600/creategrovesensorskudu.png)

  

### We can query our tables with ease as data rapidly is added.
  

  

[![](https://1.bp.blogspot.com/-xBrn48UxB0U/XZ-WUQcK7sI/AAAAAAAAYi8/oKuwWxUkB2QQSEWtMP5uw2J1ssjNFFc3wCLcBGAsYHQ/s640/grovekuduhue.png)](https://1.bp.blogspot.com/-xBrn48UxB0U/XZ-WUQcK7sI/AAAAAAAAYi8/oKuwWxUkB2QQSEWtMP5uw2J1ssjNFFc3wCLcBGAsYHQ/s1600/grovekuduhue.png)

  

  

### Let's Examine the Parquet Files that NiFi Generated
  

[![](https://1.bp.blogspot.com/-kwxhgrbOzbc/XZ-WUzRFYVI/AAAAAAAAYjI/lATiDtZDPyc_zJZslaCaJn6ErRVMS72swCLcBGAsYHQ/s640/groveparquet2.png)](https://1.bp.blogspot.com/-kwxhgrbOzbc/XZ-WUzRFYVI/AAAAAAAAYjI/lATiDtZDPyc_zJZslaCaJn6ErRVMS72swCLcBGAsYHQ/s1600/groveparquet2.png)
  

[![](https://1.bp.blogspot.com/-hnevaiGSH3M/XZ-WUp9olOI/AAAAAAAAYjA/ivfLnotqUCkfZeDPW3-1D3rBrvHtak0yQCLcBGAsYHQ/s640/groveparquet.png)](https://1.bp.blogspot.com/-hnevaiGSH3M/XZ-WUp9olOI/AAAAAAAAYjA/ivfLnotqUCkfZeDPW3-1D3rBrvHtak0yQCLcBGAsYHQ/s1600/groveparquet.png)
  

  

###  Let's query that parquet data with Impala in Hue
[![](https://1.bp.blogspot.com/-o9Whggdjl48/XZ-WU7XUiDI/AAAAAAAAYjE/KtdaZnZQNgcN-yrWDrr4jifpMjos4LoKQCLcBGAsYHQ/s640/groveparquethue2.png)](https://1.bp.blogspot.com/-o9Whggdjl48/XZ-WU7XUiDI/AAAAAAAAYjE/KtdaZnZQNgcN-yrWDrr4jifpMjos4LoKQCLcBGAsYHQ/s1600/groveparquethue2.png)  

  

###  Let's monitor that data in Kafka with Cloudera SMM
  
[![](https://1.bp.blogspot.com/-zD06gfaZq_U/XZ-WTUaBi1I/AAAAAAAAYiw/m5el1b9DEcg0XR_O8aIwZa_W0gOmDTjEwCLcBGAsYHQ/s640/groveKafkaMetrics.png)](https://1.bp.blogspot.com/-zD06gfaZq_U/XZ-WTUaBi1I/AAAAAAAAYiw/m5el1b9DEcg0XR_O8aIwZa_W0gOmDTjEwCLcBGAsYHQ/s1600/groveKafkaMetrics.png)  

  

[![](https://1.bp.blogspot.com/-UZPjrBCRo6s/XZ-WWZEZPEI/AAAAAAAAYjg/4sJhQ5zCUuIg-UKlGhir5lGLo7Y29VX9gCLcBGAsYHQ/s640/smmeventsschema.png)](https://1.bp.blogspot.com/-UZPjrBCRo6s/XZ-WWZEZPEI/AAAAAAAAYjg/4sJhQ5zCUuIg-UKlGhir5lGLo7Y29VX9gCLcBGAsYHQ/s1600/smmeventsschema.png)

  

  

That was easy from device to enterprise cloud data store(s) with enterprise messages, security, governance, lineage, data catalog, SDX, monitoring and more.   How easy can you ingest IoT data, query it mid stream and store it in multiple data stores.   It took longer to write the article then to do the project and code.   All graphical, Single Sign On, multiple schemas/verisons/data types/engines, multiple OSs, edge, cloud and laptop.   Easy.

  

### Table DDL

  

CREATE EXTERNAL TABLE IF NOT EXISTS grovesensors2 

(humidity STRING, uuid STRING, systemtime STRING, runtime STRING, cpu DOUBLE, id STRING, te STRING, host STRING, `end` STRING, 

macaddress STRING, temperature STRING, diskusage STRING, memory DOUBLE, ipaddress STRING, host\_name STRING) 

STORED AS ORC

LOCATION '/tmp/grovesensors'

  

CREATE TABLE grovesensors ( uuid STRING,  `end` STRING,humidity STRING, systemtime STRING, runtime STRING, cpu DOUBLE, id STRING, te STRING, 

host STRING,

macaddress STRING, temperature STRING, diskusage STRING, memory DOUBLE, ipaddress STRING, host\_name STRING,

PRIMARY KEY (uuid, `end`)

)

PARTITION BY HASH PARTITIONS 16

STORED AS KUDU

TBLPROPERTIES ('kudu.num\_tablet\_replicas' = '1')

  

hdfs dfs -mkdir -p /tmp/grovesensors

hdfs dfs -mkdir -p /tmp/groveparquet

  

CREATE  EXTERNAL TABLE grove\_parquet 

 (

 diskusage STRING, 

  memory DOUBLE,  host\_name STRING,

  systemtime STRING,

  macaddress STRING,

  temperature STRING,

  humidity STRING,

  cpu DOUBLE,

  uuid STRING,  ipaddress STRING,

  host STRING,

  `end` STRING,  te STRING,

  runtime STRING,

  id STRING

)

STORED AS PARQUET

LOCATION '/tmp/groveparquet/'

  

### **Parquet Format**
  
  

message org.apache.nifi.grove {

  optional binary diskusage (STRING);

  optional double memory;

  optional binary host\_name (STRING);

  optional binary systemtime (STRING);

  optional binary macaddress (STRING);

  optional binary temperature (STRING);

  optional binary humidity (STRING);

  optional double cpu;

  optional binary uuid (STRING);

  optional binary ipaddress (STRING);

  optional binary host (STRING);

  optional binary end (STRING);

  optional binary te (STRING);

  optional binary runtime (STRING);

  optional binary id (STRING);

}

  

### References

  

- [https://github.com/apache/parquet-format](https://github.com/apache/parquet-format)
- [https://docs.cloudera.com/documentation/enterprise/5-8-x/topics/impala\_create\_table.html](https://docs.cloudera.com/documentation/enterprise/5-8-x/topics/impala_create_table.html)
- [https://docs.cloudera.com/documentation/enterprise/5-8-x/topics/impala\_parquet.html](https://docs.cloudera.com/documentation/enterprise/5-8-x/topics/impala_parquet.html)
- [https://github.com/tspannhw/minifi-grove-sensors](https://github.com/tspannhw/minifi-grove-sensors)
- [https://github.com/tspannhw/GrovePi](https://github.com/tspannhw/GrovePi)
- [https://github.com/tspannhw/grove.py](https://github.com/tspannhw/grove.py)
- [https://github.com/tspannhw/Grove-RaspberryPi](https://github.com/tspannhw/Grove-RaspberryPi)
- [https://seeeddoc.github.io/Grove-Ultrasonic\_Ranger/](https://seeeddoc.github.io/Grove-Ultrasonic_Ranger/)
- [http://wiki.seeedstudio.com/Grove-Ultrasonic\_Ranger/](http://wiki.seeedstudio.com/Grove-Ultrasonic_Ranger/)