MIT License

技术解读

以下内容由 GitRead 中文社区 编辑团队基于项目 README 与官方资料整理, 结合中文开发者的常见使用场景补充技术选型建议。具体以项目官方文档为准。

多引擎 SQL 分析的实战沙盘:拆解 Python 与 Spark 之间的那层工程空白

项目背景与痛点

大多数 SQL 学习资源都停在“语法题”层面:给出建表语句,写一条 JOIN,再写一条窗口函数,打完收工。但真实的数据工作并不这样运转。真实的数据工作从一份脏 CSV 开始,中间要经历选引擎、清洗、建模、跨方言迁移,最终必须落到“能被业务方看懂的一张图”上。这条链路上的每一步都有容易踩的坑,而市面上的教程往往只讨论其中一小段。

ptyadana/SQL-Data-Analysis-and-Visualization-Projects 恰好绕开了这种内容碎片化的问题。它更像一个覆盖面很广的实战沙盘,把 MySQL、PostgreSQL、SQLite、Tableau、Apache Spark 和 pySpark 放在同一套数据语境里,展示“同一类分析问题在不同技术栈下如何实现”。它要解决的核心痛点很具体:开发者知道 SQL 怎么写,却不知道一条查询从哪个引擎出发、经过什么样的数据形态、最后以什么形式交付。

核心技术揭秘

从仓库的组织方式看,它的设计思想是**“按引擎分层、按项目切片”。这个结构本质上是一套多方言对照实验**:同一组清洗逻辑会在 SQLite 里做轻量验证,在 MySQL 与 PostgreSQL 中处理更复杂的建模,在 Spark 或 pySpark 中处理大规模宽表。

以下是推断出的数据流:

graph TD A[原始数据集<br/>CSV / 在线公开数据源] --> B[数据加载层] B -->|"小体量明细"| C[SQLite<br/>本地快速验证] B -->|"结构化业务数据"| D[MySQL / PostgreSQL<br/>关系建模与复杂查询] B -->|"大体量或宽表"| E[Apache Spark / pySpark<br/>分布式清洗与聚合] C --> F[SQL 分析脚本<br/>清洗、窗口函数、CTE] D --> F E --> F F --> G{"是否需要交互呈现?"} G -->|"是"| H[Tableau 仪表盘] G -->|"否"| I[分析报告 / CSV 输出] H --> J[业务洞察与决策] I --> J

这个流程真正的技术含量藏在方言差异里。像窗口函数、日期截断、NULL 与空串语义、字符串拼接,这些写法在 MySQL 和 PostgreSQL 中并不通用;Spark SQL 又更接近 Hive 风格,collect_list、explode 这类高阶操作在关系型数据库中根本没有对等实现。能把这套差异消化在同一个仓库里,说明作者对 SQL 的掌握不是“会写”,而是“懂迁移”。

第二个难点是 pySpark 的双轨表达:同一个清洗任务既能用 DataFrame API 串起来,也能用 Spark SQL 的字符串模板完成。这种对照在工程上价值极高。因为你一旦遇到 UDF 性能瓶颈,或者遇到 Catalyst 优化器不认的写法,就必须能在两种范式之间来回切换。

功能亮点与差异

与 sql-exercises、SQLZoo 这类刷题仓库相比,这个项目最大的不同是项目制而非题目制:它的每个目录都是一条完整的数据流水线,从原始数据到可视化产出自成闭环,不会出现“写对一条查询就结束”的情况。

与只做 Tableau 或 Power BI 的仪表盘仓库相比,它的杀手锏是保留了引擎层。很多可视化作品集的问题在于,读者只能看到漂亮的图,却看不到图背后的数据是怎么建模出来的。而这个仓库把 SQL 脚本和仪表盘放在一起,相当于把“结论”和“推导过程”同时交了出来。

此外,多引擎并置本身就是一种隐性能力证明:它展示的不只是“我会用某个数据库”,而是“我理解数据库之间为什么不同”。

应用场景与落地建议

在生产环境借用这类仓库时,有三点需要特别注意。

第一是可复现性。这类仓库的常见做法是直接引用在线数据源,或者把连接串写死在脚本里,一旦数据源下线或版本变化,脚本就会立刻失效。建议在上手前先补一层 docker-compose.yml,把 MySQL 和 PostgreSQL 固定到具体版本,并把原始数据落地成种子文件。

第二是引擎选型的克制。Spark 不是“大就是好”,如果数据量还在单机内存内,用 SQLite 或 PostgreSQL 的速度反而更快,调试成本也低得多。pySpark 更适合处理宽表聚合和多轮迭代的清洗,不要在数据量还很小的时候就先上分布式。

第三是缺少 DDL 与索引层面的验证。分析型 SQL 和工程型 SQL 的边界在索引设计上。如果要把这套脚本推进到生产,至少要补上执行计划(EXPLAIN)的对比,否则很难判断一条窗口函数查询在数据量涨十倍后会不会崩。

适用场景很明确:数据工程入门训练、面试作品集、BI 团队的 SQL 规范参考,以及跨引擎迁移前的可行性验证。

综合评价

优点:结构呈全景式,覆盖了从关系型数据库到分布式引擎再到 BI 呈现的完整链路;多方言对照有真实的教学价值;项目制组织让每个目录都能独立复现,也便于面试时直接当作案例讲解。

缺点:工程化外壳偏弱,缺少容器化环境与种子数据,可复现性依赖外部条件;没有性能基准对比,导致“为什么用 Spark 而不是 PostgreSQL”这类关键决策缺乏数据支撑;部分脚本更像分析笔记,而不是可以重复运行的流水线。

一句话总结:它是一个优秀的技术视野展示品和学习参照系,但要把它变成生产可用的资产,还需要补上环境固化、数据落地和执行计划验证这三块内容,它离一个完整项目还差这三块。

关于

GitHub 原始描述(英文)

SQL data analysis & visualization projects using MySQL, PostgreSQL, SQLite, Tableau, Apache Spark and pySpark.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

语言占比

Jupyter Notebook
Python

贡献者

README

SQL Data Analysis & Data Visualizaiton Projects

Compilation of SQL, Tableau, PySpark data analysis related projects and challenges where I practice those skills.

Built with

  • SQL Languages

    • SQL
    • MySQL
    • PostgreSQL
    • SQLite
  • Tools

    • MySQL Workbench
    • pgAdmin
    • DB Browser for SQLite
  • Apache Spark

    • Spark with pySpark
    • databricks
  • Python

    • psycopg2
    • jupyter notebook

Projects & Challenges

Instagram Clone Project

MySQL project which is a cloned mimic version of Instagram database. It is used to perform data analysis for real world business related questions and scenarios such as

  • find out the rewarding system for the loyal users
  • launching campaign to target the weekdays with the most user registerations
  • encouraging inactive users to log in back to the system
  • etc.

Film Rental Store Project

MySQL data analysis project in helping Film Rental Store to

  • perform data analysis for user behaviours
  • discover marketing stats
  • find actionable customer/business insights
  • measure and track marketing efforts
  • etc.

Company Employees - SQL & Tableau Visualization Project

MySQL & Tableau integration project for analyzing employee data and visualizing the findings across the departments for management including

  • What is breakdown between the male and female employees working in the company each year, starting from 1990?
  • What is the number of male managers to the number of female managers from different departments for each year, starting from 1990?
  • What is the average salary of female versus male employees in the entire company until year 2002? Need to filter out by departments.
  • etc.

Parch & Posey - Data Analysis Project

PostgreSQL project for helping fictional company called Parch & Posey for

  • managing the Orders,
  • finding out the relationship with different Accounts
  • monitoring the performance of Sales Reps
  • etc.

Digital Music Store - Data Analysis Project

PostgreSQL Data Analysis project to help Chinook Digital Music Store to help how they can optimize their business opportunities and to help answering business related questions.

  • countries with most invoices
  • city with best customers
  • finding out who the best customer is
  • etc.

Restaurant & Library - Information & Patrons Project

SQLite project for

  • In the Restaurant - helping the Restaurant to manage customer information, reservations, orders and party invities in for Restaurant 20th Anniversary.
  • At the Library - helping the Library to manage the books statistics, check out and loan process, managing on due loans, encouraging patrons, etc.

California Population Project

MySQL project for analyzing Californa population projection data

  • getting population data and loading for data analysis
  • finidng out male and female populations per county for 2014

California Education Project

MySQL project for analyzing Population Projection and Education data

  • initital cleaning for education data
  • finding the percentage of education attainment for each category across differnent age group
  • getting demographics based on education data and age group
  • finding out projection of education demand for each age group based on Population Projection and Education data

UK Road Safty Accidents 2015 Project

MySQL and python project for analyzing UK road safty data, accidents and severity level

  • finding out what is meadian severity value of accidents caused by various Motrocycle
  • Accident Severity and Total Accidents per Vehicle Type
  • Average Severity by vehicle type
  • Average Severity and Total Accidents by Motorcyle

Mid Summer Night Dream Project

MySQL and python project for analyzing Shakespeare’s Mid Summer Night Dream play texts and characters

  • loading information for analyzing purpose
  • calcuating performance different queriy types such as SELECT, INSERT, UPDATE, DELETE
  • manipulating plays and characters

Project - Analyze International Debt Statistics

PostgreSQL project in Jupyter notebook for analyzing international debt statistics using data from world bank.

  • What is the average debt across countries?
  • What is the maximum debt indicator?
  • Which country has the highest debt in which debt indicator
  • etc.

Tableau

SQL

Ultimate MySQL

Complete SQL Mastery

  • handling and analyzing Large Ecommerce Store for clients, payments, invoices, products and shipping information.
  • Course: Complete SQL Mastery

SQL Code Challenges

  • In the Restaurant - helping the Restaurant to manage customer information, reservations, orders and party invities in for Restaurant 20th Anniversary.
  • At the Library - helping the Library to manage the books statistics, check out and loan process, managing on due loans, encouraging patrons, etc.
  • Lynda Course: SQL Code Challenges

SQL 30 Questions

SQL Queries - Practice your SQL Knowledge

SQL for Data Analysis - Weekender Crash Course

Complete SQL & Databases - ZTM

Advancing SQL Journey - (In Progress)

To skill up my SQL related skills in specific areas and topics:

Apache Spark & PySpark

License

This project is licensed under the MIT License - see the LICENSE.md file for details

评论

暂无评论