Harnessing the Data Lifecycle for Customer Experience Optimization: Streaming Classifications On Twitter Streams
Tags: apacheatlas, apachekafka, apachenifi, cdp
Published: 2020-04-27 12:42:27

---
title: Harnessing the Data Lifecycle for Customer Experience Optimization: Streaming Classifications On Twitter Streams
published: true
date: 2020-04-21 18:30:00 UTC
tags: apache atlas,apache kafka,apache nifi,cdp
canonical_url: 
---

# Harnessing the Data Lifecycle for Customer Experience Optimization: Streaming Classifications

For a deeper dive see this past webinar: [available here.](https://www.cloudera.com/about/events/webinars/harnessing-the-data-lifecycle-for-customer-experience-optimization.html)

  

In the use case solved for this webinar, I am a Streaming Engineer at an airline, CloudAir.   I need to find, filter and clean Twitter streams then perform sentiment analysis.
  
  

Score Models in the Stream to Act
 ![](https://lh5.googleusercontent.com/hUl8apGpDT50nXQtxNg0pmOUbYxPh6jzSw__MQMmiDLF1eJ1RgkRfJ3B3D4zneFcvNoLUwyFp13u-aOuo9mPIVpN8mNOlVOTLQor_k419R2uu_hAAE410uU_-7yz0P2ipEsHxuXU)  
  

 ![](https://lh4.googleusercontent.com/e1TxvpoUDZDfftPcyYCduY3qNSpKzrhYIDk3KSzggKlrUHHHQMu3adSjmNETFiKRLCw5DfnNLfXhrO5iW_geS9R6oA_hVuM_142SuWwA37NbD6vdIcfqDCwRvnLt0uIPxujX8or_)
  
  

  
  
  
  
  
  
  
As the Streaming Engineer at CloudAIR I am responsible for ingesting data from thousands of sources, operationalizing machine learning models as part of our streams, running real-time ELT/ETL processes and building event processing systems running from devices, servers and edge nodes. For today’s use case, one of our ML engineers had given me a model that was deployed into one of our production Cloudera Machine Learning (CML) environments. I logged into Cloudera Data Platform (CDP), found the model, tested it, and then extracted the information I need to add this model to our streaming ingest flow for the social media team.
  
  

 ![](https://lh4.googleusercontent.com/bY1cT8ka6f_zLuOoGpQuSyiX_UJE1pzP1CgK78vLYuPWhkMWeVWYrgMJgH8wJtJs_T-ILSt1ZAMQ6tsTL43W-_UtApV7796wzoFVMxBP-wCQ5f5aOT7INKuFWSW-8nONZaf9Sjm6)
  
  

I have been given permissions to access the airline-sentiment workshop in CDP Public Cloud.
  
  

 ![](https://lh6.googleusercontent.com/zvBAUytaZriGf1cSfftg2D0MmTnUF9uuRZVGrtD12MLQpgR5HUyIq23Or1hKO3x_bLrJyT4XoVyZVzVkassaXE2-tLRu32coh4d4uY_7rHvUDDRLNGq28AQuS42MPC_FYaL4S_EO)
  
  

I can see all the models deployed in the project I have access to. I see that predict-sentiment is the one I am to use. It is deployed and has 8GB of RAM and 2 vCPU.
  
  

 ![](https://lh6.googleusercontent.com/0c1dLMy370GgFV0kGIGL2XHe9YIZuVFJUd4ywRybK3C-c7Glbsc6YUZyEemgJ09hNWGpUg0kLOQcXTYfc6nsey1uLx00T0LBsmD4UQ0nBO_H8K3cHsHxE3vPhxsuJJ6d1ZQKlI_J)    ![](https://lh6.googleusercontent.com/SVS6cXAOOuRae-QZ6yppgEVDz9jfwWis9AH4k6okgT0DpB5rT291I9djRgxpuw6yGizPnESNd-NX_wMcDIhY5GzhjbxjmZKHK4xeDzJaes1AGzYDES1bcov9Z6J-62uGIAgvY61F)
  
  

I can see that it has been running successfully for a while and I can test it right from the project.
  
  

You can see the URL after the POST and the accessKey is in JSON.
  
  

Using Cloudera Flow Management (CFM) I am ingesting real-time Twitter streams which I filter for only airline specific data. I then clean and transform these records in a few simple steps.   The next pieces I will need are those two critical values from CML: the Access Key and URL for the model. I will add them to an instance of an ExecuteClouderaML processor.
  
  

 ![](https://lh5.googleusercontent.com/Yq4Y92yNW6Q1r1LQwXmwQkHHaej-7ANgw30QZrZB0DITOZHtEfJ_P2irEyrQSzdm6VIi_rIU0gZntQp4Vsz_fAXFeJqDx96QrYXbl_osWA2JP0tS1gHYl9hCPCHMIsZAwjIUJy19)
  
  

 ![](https://lh5.googleusercontent.com/3p-E0x2bf7ZQtlls2KRU8Q_pToRSZHQ_4ePu1PwZcOtk1haDCMi4xdIhWfvXSHKRSYW-gQt6-1ZSqwYz7NEen_WpirPQ1Dey2hjLVhYlAsJBZQjIdQc4nm2O1YFjP9s8O3AWD68S)
  
  

I am also sending the raw tweet (large JSON files) to a Kafka topic for further processing by other teams.
  
  

I also need to store this data to tables for ad-hoc queries. So I quickly spin up a virtual warehouse with Impala for reporting uses. I will put my data into S3 buckets as Parquet files, with an external Impala table on top, for these reports.
  
  

 ![](https://lh5.googleusercontent.com/dWxRm-gkGWr0UPPg-slbTT7_csVqi8YA4R2FcUnVi8E1H6oobCZXY3qNjSCT965l1_jZi-lCyahozXzA8-WrC-weLY7gJV5fiCMByJR7eqPFz8KXxW06PCW-5eCt-68ZVQWsmVXj)
  
  

 ![](https://lh5.googleusercontent.com/abLy3bXWj6urR4e7p7rHIuPfF9c4hMVYUUUxokzjqjdtGCZdxWwucpOwxj5zcxRzGo4ZwM38-qjB2VH7fUQQAC-pWp4ylrWLaYxBa8jI6hC7P26-a0MijlyxkvawXrNj5o2gcRlf)
  
  

Once my environment is ready, which will only take a few minutes, I will launch Hue to create a table.
  
  

 ![](https://lh4.googleusercontent.com/w-4ORuh-r99B1zFYJY_peFKdA4t-2eCdIzaYgcoVAHjnOrPrAkcCk_zk4FVNQwZX4jB96im7qJNXok7Lhd5RXYyN-6LTKW6K1Ax2lhF4sPpdFauYeIbgEHqTTG2HR-dEFPZ5VPAU)
  
  

 ![](https://lh4.googleusercontent.com/BvLbjf0EZtSWPPrANRvSXK0GyvxRtQLVzWEeYmaXjwE3GV_ETgxc7kG2c8m_Vxfavt_AVp56k-uW9uVP02-3sS946Nm67VR3r1hle5jw3FJ1A6hJwvk6I7oyfpWxlcZvC8ab3fOT)

 ![](https://lh4.googleusercontent.com/794ANe4OjfzAaQcAJefxyiAChoSJnBbK2zlZ26NRCN5yl6SWSm36cO2hrnfYw7f1KU3Ity5ReKl8FTA-mQQUhjBFIaueYR4TJC-m7-8YVyw4p0aXJvKJyNglFKURbp3ibMzaJK4K)
  
  

From the virtual warehouse I can grab the JDBC URL that I will need to add to my Impala Connection pool in CFM for connecting to the warehouse. I will also need the JDBC driver.
  
  

 ![](https://lh5.googleusercontent.com/dQfDgCyHfKDf8xnwJFI3_r0S2HJtPTMjA3fPXLfEZq7WUM7iHnkb1c2qWmnWrNs_k1RPdTRZFCxv7XYU3carB7Ff016P7DFdX0tnZr_9rJDd5p1Kv5rvowbjZGLJ0v42ub1fZLfU)
  
  

From CFM I add a JDBC Controller and copy in the URL, the Impala driver name and a link to that JDBC jar. I will also set my user and password, or Kerberos credentials, to connect.
  
  

 ![](https://lh3.googleusercontent.com/USNX8jh-7buJ-raMT8LLo3ELjgijAo-6dRyl-_0mp808NRjQ4kQ6BhtYxfWZ9gFN0yg4bvkVL_WwXFIcz7RC485pUNNLR4M4P2jUnrGBdkqa4Cq-1iEmm3tQ3pFDxqtfMCgUmJCq)
  
  

 ![](https://lh5.googleusercontent.com/zNN8a50DrDEKrMQ2o2Da9K1LOLw27dS9ndsGZa5TSdGXoWknA3xhvbeCBDgLJafRqE0wn5nqrtHzWtYBuYLeAa0egzqtHU60u1yw2LJyRASieKRAhkOuK6sB2F3fEF8ipP1cvt92)
  
  

After having called CML from CFM, I can see the scoring results and now use them to augment my twitter data. The data is added to the attributes for each event and does not affect the current flowfile data.
  
  

 ![](https://lh4.googleusercontent.com/zmdRGKiBrtSHNu-vSIvu7mTJTRDHw5p3aKdjw7EDlfq3vb9lHN_SSx7Y8cAiSsYdqbCxN6jZlimtylXuuuE-WinCNpp8IESrodLxtGaEqhaGDr73AwHGv9mm_4cOF1cmzrzA9qU5)
  
  

Now that data is streaming into Impala I can run ad-hoc queries and build charts on my sentiment-enriched, cleaned-up twitter data.
  
  

For those of you that love the command line, we can grab a link to the Impala command line tool for the virtual warehouse as well, and query from there. Good for quick checks.
  
  

 ![](https://lh3.googleusercontent.com/I41tfZew07Azx2uAmPx2nfShoFPeB62njrZId2kwEILHQvzzReqOw4c5veP4WWr2cYcny_6YLLFZJ1Fs5GVZ8nMNNqIUukxRwsu5DbZR7mRSYacfwLLG1B5cK7C1iom0PDeplMtV)
  
  

In another section of our flow we are also storing our enriched tweets in a CDP Data Center (CDP-DC) Kudu table for additional analytics that we are running in Hue and in a Jupyter notebook  
 that we spin up with our CDP-DC CML.

  

  
  

 ![](https://lh3.googleusercontent.com/-WKouM1_N4EgP0YxmB2Im-7hgchoUoQOws_OYjxf8MncFhBKrTo_IN_zWLiDn66qdqVVxnLbHoFoovEnICpa2dnD46UYrX4EK6esThb8WHpAhJXtmlCpyyPasFOAZCLTHjJESikq) ![](https://lh6.googleusercontent.com/flm2AY6mfBYLpZe916KTCXBM_LD3TGbguL7L4wkJVZS1A7pWHrpK2slV5B5yby_di6N1ntUKkn6SkSyUR1z3TSbPdFEHMeacgqW7uvIdo3V9J5mQ_mHGMXWlPIcEfIcX9UTFWjhc) ![](https://lh3.googleusercontent.com/O1HqYjbGLQGrGYDaUdQwWf8DUsEGWgHTLCAKCTJN8Wq0C4-edSFziTN0utNO9OPEmS2F5i9ymkJwYUmfnAyc8tUv1RO57xwbNzA79y-fgJsI3HA3gDf7R1ZQEHwbZTEga_gh_HlO)

Jupyter notebooks spun up from Cloudera Machine Learning let me explore my data and do some charting, graphs and SQL work in Python3.

 ![](https://lh3.googleusercontent.com/L6rGqRSXT1mYmIuHgqtp4ooBHuBz428bkxe3dqw4RY0u_8HhuAs8ZSZZiKdTFHB_E6IxN0xeBNtoGDFbSxTszv5sFN1dC-KDavgZ3MMN7C6jR5Lcb3wlpULzOkiCvrTGnUvKH4V7) ![](https://lh5.googleusercontent.com/WhfCT3Vf2xuqxdm3El44TyP4XQ4YeoceyogvAFsVST8r9zpFAEoRbz5FKWOkZVaOT5N-DjzKsKXPgo5YpIQp-Ox5AUXNSG5QI3ZhBVvK34XWHmjCbQrQw9C6JfVHZRaXE7DnDHpe)
  

 ![](https://lh5.googleusercontent.com/NNWhB3JQXhY_FJCjvMf40-4Bv0x51IjSDveIT51VLsQgwNBFtjeNDIEBocJ_vF2hQVR0z4EvQm2C0uQ8xqVIXufQJ08HtWVTVIQzSRaPg4VlGB6UMWWjvOEhfDDR9QGWibdul9VE) ![](https://lh5.googleusercontent.com/SSp8dApwKX5M4iR6U3kZX1n44lRaPZ61Z6GifEiYgeixRQD8vc-SvmZurWkSPvsej5JN1AmtShJx-GRUfaBQTWWXBImex8-dsjkPBiAKHCvXDeSXmSpaGay-eTBLCoozRR8JADG7) ![](https://lh5.googleusercontent.com/PI6KrFGz6a0zVqJaRuzayHt0PLkKl0hI4rZ7RdA6INDFOgdpIcEX3PUVnNBiqPiI0juFGH2uctV9RId8CZ_ylJkipQoEpxEGr-s1gQRmZ2ddhm1I4ipuQbJhss3jBNZfpxY6EgZj)
  

 ![](https://lh4.googleusercontent.com/OvBqzsmy6PCcRbWJmUNduZkW5Y2eOWtoyOlDP-j0HDuFh9DtcIZ1U_fgAL5SsNt5DWvYw2a8WPnbfKurWNmuEiUh01ICLtUz3fezC2l0VaPKjFOag3jdZecqL72YhZTPx_QHINAq)
  
  

One of the amazing features that comes in handy when you have a complex flow that spans a hybrid   
environment is to have data management and governance abilities. We can do that with Apache Atlas.  
 We can navigate and search through Atlas to see how data travels through Apache NiFi, Apache  
 Kafka, tables and Cloudera Machine Learning model activities like deployment.
  
  

 ![](https://lh5.googleusercontent.com/Vybf87YYjbc_osKD_ZN6VEQ-p1C0tXJ9jxuSbMVO4MM7Zzj3X0_PE0g8S90XpT2EHWtIAUxSTff6WxUStpFLxite4du7vrjk15YRujiJ-gTBCVxDx34gptoO9lq_7teGL8-w6gsf) ![](https://lh4.googleusercontent.com/E5ZySe0mBeC7pxMD0q6SU2lgc0U-72GeBd4tdT_PuAVR3JttF22Zojz2hiwUz2fD0ZouZCHulxgLhPQ0eTDvvlf-TBn7rAprZu1icHAFw-uOU2vxes8ONgkoVDArVInjGsiG84qE) ![](https://lh5.googleusercontent.com/ttJsNckVA7xv5txKsm9u7MD6ZiPEnhh0dG8Bf5fQKVeTPfLltv4LVs1ypnNy2yBPBJ2nxsojwpu5mebteFEcFtE_ZPdkdGe6V3qsYOYmlaiOdOzwjTHAi62f9cjs1ilIg4p65NhG) ![](https://lh5.googleusercontent.com/OtPYgcYqgrxgXgVzkgW9yU2cEpSWqIw1EpfPv7ACyaJW4J8h-iPnj3CQMoY2Hbp_ePY_xQDK73vNFxdGU7df2r6tELpzOV4a4ahYenZbSsOwUMkIQX65mP2hvmbOe2yoxLToZiD_) ![](https://lh5.googleusercontent.com/nrMb05M3P57ORKcI7lXYl674qdYRJbiaLD5au6phIfJjxnbG9VaCqNWQhE716XIVnK8ddkXuYSklhCXYAEkdYC_BJRBd_0BOn9VUloWVVmSbbkDZDyaD3eqEnL8X-nj9i5AV9OrF) ![](https://lh4.googleusercontent.com/t1UfGvLEVbXvhvZw-v3WsszczaCCPqy4zRM0zu-cBA4w-sgxThyKSBqvVjzrEwT7Nf3KTQ193Ty9293C0kraAzcZJxxTM7ErIeOJMYMM1-Jp65Fo9_IcBo6W4H3HuAikbK0XYary)
  
  

Final DataFlow For Scoring
  
  

 ![](https://lh3.googleusercontent.com/nqSmcw4QG5vQrF_Vp_Z2INWFPVKgWD0R1yI8RiWoGOsxXg-0SU6ZQznibbhsvSxLy2MX8YHcHEMu9AyhpIO3hPCaJ4pqg--LEyzkoUPlg3aCj6mSyb8AeVSC3P5rDwRT0a8aHJF2)

 ![](https://lh6.googleusercontent.com/foW0RylZ5JxbkSnRMJu4JaGN95vLISM0pRwiBiizXRRY8QYBPOUphuHRiMOq7cBKuCeVa-pY6LJKdv_0tEOy-BYRvMyKrw2XEUBa1Lw5FacYqNE2GtJfN4XDHJSmW46qEsZrw5wQ)

 ![](https://lh4.googleusercontent.com/ToblblYDq0ydywokBclLW0JR_DbfvM979HAo9YVgAOy7XrErFVxWpN5XNAIk-q96OyIk3PF4kbN4G5p6DE2tf6hUwVL3urPryqKFxZLhZxqRxcBx6B7_Lubp36yXIO9HQVvHrlkw)
  
  

We have a Query Record processor in CFM that analyzes the streaming events and looks for   
Negative sentiment by influencers, we then push those events to a Slack channel for our social   
media team to handle.
  
  

 ![](https://lh5.googleusercontent.com/C4GJkNA9vqGMbkeLR0qpOjv2WiIQH7AbwTLH7UezdPRA2Ab2lRMUOB73jVFbhmsyu3HwGriDLb1quuFnTKOMELJOe400D6pJUpv6qGqM1BHfQU1bzZq6la8ZjOr1j7T_NQ5Tdpt9)
  
  

As we have seen, we are sending several different streams of data to Kafka topics for further   
processing with Spark Streaming, Flink, NiFi, Java and Kafka Streams applications. Using   
Cloudera Streams Messaging Manager we can see all the components of our Kafka cluster  
 and where our events are as they travel through topics in various brokers. You can see   
messages in all of the partitions, you can also build up alerts for any part of your Kafka system.   
An important piece is you can trace messages from all of the consumers to all of the producers  
 and see any lag or latency that occurs in clients.
  
  

 ![](https://lh6.googleusercontent.com/Lcxrmx66PqzM4CLDuSDh2kBkKyTxM8WFZqvMz0_meVHUOiBnbeGLc-ji9B5TXT9ju-DyQViOmTZ-m22Vr6TScauReKBoDMqVGDFG-CV2Lez6t6NobVWyZ_TkgrX164NSGPE9UVIP)
  
  

 ![](https://lh6.googleusercontent.com/dRsWyFGJhPE7qoJ10kSNLG9EAH80elurFfgke5z9m6f4bPbFwSiLpQ6HMx-fy-uA7PItONakpuUXB1mF4uurLU1-XCf7IXiRt4RkRhPfR88v9F7uhjyQZy7cUM48rc42ftv8duqs) ![](https://lh4.googleusercontent.com/ZAgtr4rwtMXkVMZ9c-lnvrqX2jPK9bI4yFPDjXf_X9XRJhxIyHyIyMj1-1LI88oJ3VtE1eSGKYWUQoNo0RkDJArslaE5fj8lsf5I-liFy_hWDGdkgavr-kCge1awW4bYgxOghP6V) ![](https://lh6.googleusercontent.com/7uVtMKeSgvc8jjzk5-WbhxHVkUqnH1rMcVz0GrhBSTNwNHFlqnZesgC2ZNDD7vfPrPsYF5BkXkd5jKNUcyKYjxBnHf3mMOchWjeM28ZNpyyGH4Q55mlXBiuSTkOIfhBNW7h7S-lV) ![](https://lh5.googleusercontent.com/S_LgU_fChk0x8UEkO6HhcdK0uiiy7t2eoopeallXoadRhYI8-LMbowvtXPgUt2c9lnG7M-eKsqbUDh8AQkkJtgJtfQHkQ_-KoXTyzr2Ff0n_r6jfDjQdkuLoUTfUeIr2LpXKJS8t)
  
  

We can also push to our Operational Database (HBase) and easily scan through the rapidly inserted rows.
  
  

 ![](https://lh6.googleusercontent.com/XVflRLF56y-0XNnGDR4FoAOTA81uPu9vBSr23v6YQqnzSP8lzAe3sVPtycSNFyuJkBczGr_lDJz73JP7e20C9ZDRsstsl8rbJLV1399FmbhF29naLxrcniIdz1QstyHRO7mpAIlH)
  
  

This demo was presented in the webinar,   
[Harnessing the Data Lifecycle for Customer Experience Optimization](https://www.cloudera.com/about/events/webinars/harnessing-the-data-lifecycle-for-customer-experience-optimization.html). 
  
  

Source Code Resources
  
  

Queries, Python, Models, Notebooks

[https://github.com/tspannhw/airline-sentiment-streaming](https://github.com/tspannhw/airline-sentiment-streaming)
  
  

Example Cloudera Machine Learning Connector

[https://github.com/tspannhw/ExecuteClouderaML](https://github.com/tspannhw/ExecuteClouderaML)

  

SQL

[https://github.com/tspannhw/table-ddl](https://github.com/tspannhw/table-ddl)