GithubHelp home page GithubHelp logo

tobigiwa / pyspark-structured-streaming-file-source Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 131 KB

This is a Spark streaming program that streams data from a file source(e.g CSV, JSON, Parquet, AVRO), applies aggregations with SparkSQL and sends the data and its aggregations to a sink (e.g console, file source).

License: MIT License

Python 100.00%

pyspark-structured-streaming-file-source's Introduction

Learning Data Engineering

Project Description

This is a Spark streaming program that streams data from a file source(e.g CSV, JSON, Parquet, AVRO), applies aggregations with SparkSQL and sends the data and its aggregations to a sink (e.g console, file source).

Project Objective

To demonstrate a simple Spark streaming with aggregation using PySpark.

spark_streaming

  • Used the Python Faker library to produce fake data files (CSV, JSON) which is populated to a source destination at intervals set with the built-in python time module.
  • Define the table schema with StructType.
  • Create a spark session, spark readstream object and a output spark writestream object.
  • Performed aggregation on the data with SparkSQL (i.e with SQL query).

Setup/How to run

  • Inside the cloned repo, create your virtual env, and run pip install -r dependencies.txt in the activated virtual env to set up required libraries and packages.

  • Activte the virtual env.

  • It would be a good idea to split the terminal, run python spark_streaming_from_csv.py then python generation_csv_from_faker.py in the terminal.

  • I would advice not to delay time in running both scripts as the spark streaming session is timed, otherwise change the numerial argument in .awaitTerminatio(). Any number gives it a time in secs and nothing awaits for a keyboard or program interruption.

  • Any acceptable file format by Spark can be used with this program with a well defined schema. ๐Ÿ‘

Improving our project

  • We can include scheduling and orchestration with Apache Airflow.

Having any issues, reach me at this email. More is definitely coming, do come back to check them out.

Now go get your cup of coffee/tea and enjoy a good code-read and criticism ๐Ÿ‘ ๐Ÿ‘.

pyspark-structured-streaming-file-source's People

Contributors

tobigiwa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.