0% found this document useful (0 votes)
39 views9 pages

Stream Processing Lab Manual Guide

Lab manual for stream processing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views9 pages

Stream Processing Lab Manual Guide

Lab manual for stream processing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

lOMoARcPSD|50167572

Stream Processing Lab Manual

Stream Processing (Ramco Institute of Technology)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Genshin Impact (genshinimpact90306@[Link])
lOMoARcPSD|50167572

1A. POSTGRESQL Installation and Configuration

Step 1:

Step 2:

Step 3:

Step 4:

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

Step 5:

Step 6:

Step 7:

Step 8:

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

Step 9:

Step 10:

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

1B. Relational Database Schema

Step 1:

Step 2:

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

EX NO: 2

REALTIME DATA ANALYSIS

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

3. INSTALL MONGODB

Step 1:

Step 2:

Step 3:

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

4. MONGODB WEB APPLICATION


[Link]:
from flask import Flask, render_template, request
from flask_pymongo import PyMongo

app = Flask(__name__)

# Configure MongoDB
[Link]["MONGO_URI"] = "mongodb://localhost:27017/myDatabase"
mongo = PyMongo(app)

@[Link]('/')
def index():
return render_template('[Link]')

@[Link]('/submit', methods=['POST'])
def submit():
fname = [Link]['fname']
lname = [Link]['lname']
emp_id = [Link]['emp_id'] # Ensure this is unique or use MongoDB's _id
salary = [Link]['salary']

emp_collection = [Link] # 'table' is the collection name


emp_collection.insert_one({'fname': fname, 'lname': lname, 'emp_id': emp_id, 'salary
return render_template('[Link]', data=fname)

if __name__ == '__main__':
[Link](debug=True)

[Link]:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/static/[Link]">
</head>
<body>
<div>
<form action="/submit" method="POST">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname"><br><br>
<label for="emp_id">Employee ID:</label><br>
<input type="number" id="emp_id" name="emp_id"><br><br>
<label for="salary">Salary:</label><br>

Downloaded by Genshin Impact (genshinimpact90306@[Link])


lOMoARcPSD|50167572

5. APPLY QUERY DESIGN TO SYSTEM USING MONGOD


Collections:

Insert:

[Link]({
"_id": ObjectId(), // Generate a new ObjectId for _id
"accountID": 1,
"accountName": "Checking Account",
"userID": 1,
"accountType": "Checking",
"balance": 1000,
"interestRate": "0.25%",
"openingDate": ISODate("2024-03-14T00:00:00.000Z")
});

Update:

[Link](
{ "_id": ObjectId("65f3e703fd04b76977bf036c") }, // Filter criteria to find the
update
{
$set: { // Specify the fields to update
"date": ISODate("2024-03-14T00:00:00.000Z"), // Update the date field
"amount": 150, // Update the amount field

Downloaded by Genshin Impact (genshinimpact90306@[Link])

Common questions

Powered by AI

Efficient query processing in MongoDB is achieved through techniques such as indexing, sharding, and the aggregation framework. Indexes are employed to expedite the retrieval of documents by optimizing query paths, reducing the time needed to scan collections. Sharding enables large datasets to be distributed across various nodes, not only balancing the load but also allowing parallel query execution. The aggregation framework allows for data processing and transformation directly within the database, reducing the need to transfer large volumes of data between client and server for analysis, which optimizes performance .

The Stream Processing Lab Manual outlines specific steps for PostgreSQL setup, aiming to provide a stable and efficient data processing environment. These include downloading the PostgreSQL software, configuring initial settings, creating users with different privilege levels, and setting up databases with optimized schemas for processing. Each step ensures that the system is prepared for handling large volumes of data efficiently, maintaining data integrity, and supporting concurrent transactions. The manual provides a structured approach to establish a database environment that is resilient to failures and ensures reliability in processing data streams .

Flask provides several benefits when used in web applications managing MongoDB, particularly in handling HTTP requests and web content dynamically. Its lightweight nature allows for swift setup and execution, which is ideal for rapid development environments. Flask's routing capabilities simplify the management of HTTP request handling, coupling easily with data operations in MongoDB through extensions like PyMongo. This integration streamlines the operations between user interfaces and database transactions, allowing dynamic generation of web content based on database queries, enhancing user interactivity and application responsiveness .

Integrating MongoDB with a Flask-based web application provides flexibility through MongoDB's non-relational schema, which allows developers to iterate and adjust data models without disrupting existing content. Furthermore, Flask's micro-framework approach gives developers control over components, enabling custom application scaling as needed. MongoDB's inherent scalability allows data and operations to be distributed across partitions or shards, optimizing both application load balancing and resource utilization. Flask complements this by offering ease with third-party integrations and extensions, adaptable for future technological needs or expanded web functionality .

In the MongoDB web application, the data insertion process prevents duplicate entries by leveraging unique identifiers, such as the '_id'. This field acts as a unique constraint on documents within a collection, disallowing any duplicate '_id' values. In the sample code, 'emp_id' can also be checked for uniqueness before insertion. Preventing duplicates is crucial in application development to maintain data integrity, avoid errors in data processing, and ensure reliable query results, thus offering consistent user experiences .

Data integrity in MongoDB is maintained through careful management of _id fields and atomic operations. Insertion ensures each document has a unique '_id', preventing duplicates. For updates, the use of ObjectId within 'updateOne' ensures targeted and safe updates by filtering the correct document. Atomic operations in MongoDB ensure that single document updates are performed with data consistency and integrity, meaning if part of an update fails or is interrupted, the database remains unaffected, ensuring transactional safety .

In a MongoDB-based web application, Flask's configuration and route management are pivotal for security and efficiency. Flask configurations enable secure connections to the MongoDB database and manage different environments (development, testing, production) efficiently. Route management in Flask can include authentication procedures and the use of secure request methods, such as HTTPS, to protect data payloads. The efficiency comes from Flask’s ability to segregate tasks through different routes, applying middleware functions that can handle security, such as input validation or rate limiting, before accessing the database .

Using Flask with MongoDB streamlines user form submissions by linking front-end form interfaces directly with back-end data operations. Flask captures and processes form submission data through request handling routes, which then utilize PyMongo for seamless data insertion into MongoDB collections. This direct integration reduces the complexity of data flow from user input to database storage, providing real-time processing and immediate reflection of submitted data on the platform, thus enhancing user engagement and application efficiency .

MongoDB offers several architectural advantages for real-time data processing, including its flexible schema design and horizontal scalability. As a NoSQL database, it allows for quick alterations to data structures without downtime, which is beneficial for handling varying data sizes or structures in real-time applications. MongoDB's capability to distribute data across multiple servers enhances its ability to manage large datasets and provides redundancy. Furthermore, real-time applications benefit from its fast read and write operations, supported by in-memory storage options and efficient indexing mechanisms .

The MongoDB web application uses Flask to handle HTTP requests by routing them through defined endpoints. For example, the '/' endpoint renders an HTML template 'index.html', and the '/submit' endpoint processes POST requests to capture form data. Flask's built-in 'render_template' and 'request' functions facilitate this process. PyMongo is configured in the Flask app using 'app.config["MONGO_URI"]', which connects to a MongoDB database. The data submitted via the form (e.g., 'fname', 'lname', 'emp_id', 'salary') is inserted into a MongoDB collection using 'mongo.db.table.insert_one()', where 'table' is the collection name .

You might also like