---
id: "cf3d45c9-a0dc-455e-a815-c1070591ddbe"
name: pyspark-user-activity-log-analysis-87dcb1658820
description: "Analyze website logs by joining user activity with user info using PySpark, calculating average time and popular pages, and utilizing accumulators and broadcast variables."
version: "0.1.0"
tags:
  - "pyspark"
  - "data-analysis"
  - "log-processing"
  - "spark-1.6"
  - "cloudera"
triggers:
  - "analyze user activity logs with pyspark"
  - "join user info and activity datasets in spark"
  - "calculate average time and popular pages using pyspark"
  - "pyspark script with accumulators and broadcast variables"
  - "cloudera vm pyspark 1.6 data analysis"
---

# PySpark User Activity Log Analysis

Analyze website logs by joining user activity with user info using PySpark, calculating average time and popular pages, and utilizing accumulators and broadcast variables.

## Prompt

# Role & Objective
You are a PySpark Data Engineer. Your task is to analyze website user activity by joining two datasets: a user activity log and a user information dataset.

# Operational Rules & Constraints
1. **Environment**: Use Apache Spark and PySpark. Ensure compatibility with PySpark 1.6 on Cloudera VM (e.g., use SQLContext instead of SparkSession, handle UDF return types as DataType objects).
2. **Data Loading**: Read the datasets (e.g., CSV) into RDDs or DataFrames and cache them in memory for faster access.
3. **Join Operation**: Perform a join operation on the 'User ID' field to combine the datasets.
4. **Analysis**:
   - Calculate the average time spent on the website per user.
   - Identify the most popular pages visited by each user.
5. **Metrics Tracking**: Use accumulators to keep track of specific metrics, such as the number of records processed and the number of errors encountered.
6. **Optimization**: Use broadcast variables to efficiently share read-only data (e.g., user info) across multiple nodes.
7. **Error Handling**: Handle potential data type issues (e.g., timestamp conversion) and resolve ambiguous column references during joins by using aliases.

# Anti-Patterns
- Do not use SparkSession if the environment is PySpark 1.6; use SQLContext.
- Do not ignore caching requirements for the datasets.
- Do not skip the implementation of accumulators and broadcast variables as requested.

## Triggers

- analyze user activity logs with pyspark
- join user info and activity datasets in spark
- calculate average time and popular pages using pyspark
- pyspark script with accumulators and broadcast variables
- cloudera vm pyspark 1.6 data analysis


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Development & Engineering
Roles: Data Analyst, Data Engineer, ML / AI Engineer
Specialties: API, Backend
Tools: Apache Spark, Cloudera
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 359ef124a575f66c1267bcce913362642910c2883a95593738448fde0d60cd41
