aws spark_使用Spark构建AWS数据湖时的一些问题以及如何处理这些问题

aws spark

技术提示 (TECHNICAL TIPS)

介绍 (Introduction)

At first, it seemed to be quite easy to write down and run a Spark application. If you are experienced with data frame manipulation using pandas, numpy and other packages in Python, and/or the SQL language, creating an ETL pipeline for our data using Spark is quite similar, even much easier than I thought. And comparing to other database (such as Postgres, Cassandra, AWS DWH on Redshift), creating a Data Lake database using Spark appears to be a carefree project.

最初,写下并运行一个Spark应用程序似乎很容易。 如果您熟悉使用Python和/或SQL语言中的pandas,numpy和其他软件包进行数据帧操作的经验,那么使用Spark为我们的数据创建ETL管道非常相似,甚至比我想象的要容易得多。 与其他数据库(例如Postgres,Cassandra,Redshift上的AWS DWH)相比,使用Spark创建Data Lake数据库似乎是一个轻松的项目。

But then, when you deployed Spark application on the cloud service AWS with your full dataset, the application started to slow down and fail. Your application ran forever, you even didn’t know if it was running or not when observing the AWS EMR console. You might not know where it was failed: It was difficult to debug. The Spark application behaved differently between the local mode and stand alone mode, between the test set — a small portion of dataset — and full dataset. The list of problems went on and on. You felt frustrated. Really, you realized that you knew nothing about Spark. Well, optimistically, then it was indeed a very good opportunity to learn more about Spark. Running into issues is the normal thing in programming anyway. But, how to solve problems quickly? Where to start?

但是,当您将具有完整数据集的Spark应用程序部署到云服务AWS上时,该应用程序开始运行缓慢并失败。 您的应用程序永远运行,在观察AWS EMR控制台时,您甚至都不知道它是否正在运行。 您可能不知道它在哪里失败:这很难调试。 在局部模式和独立模式之间,测试集(数据集的一小部分)和完整数据集之间,Spark应用程序的行为有所不同。 问题的清单还在不断。 你感到沮丧。 确实,您意识到自己对Spark一无所知。 好吧,乐观的话,那确实是一个很好的机会,更多地了解Spark。 无论如何,遇到问题是编程中的正常现象。 但是,如何快速解决问题? 从哪儿开始?

After struggling with creating a Data Lake database using Spark, I feel the urge to share what I have encountered and how I solved these issues. I hope it is helpful for some of you. And please, correct me if I am wrong. I am still a newbie in Spark anyway. Now, let’s dive in!

在努力使用Spark创建Data Lake数据库之后,我感到有分享自己遇到的问题以及如何解决这些问题的渴望。 希望对您中的某些人有所帮助。 如果我错了,请纠正我。 无论如何,我还是Spark的新手。 现在,让我们开始吧!

Cautions

注意事项

1. This article assumes that you already have some working knowledge of Spark, especially PySpark, command line environment, Jupyter notebook and AWS. For more about Spark, please read the reference here.

1.本文假设您 已经具备一些Spark的工作知识,尤其是PySpark,命令行环境,Jupyter Notebook和AWS。 有关Spark的更多信息,请在此处阅读参考。

2. This is your responsibility for monitoring usage charges on the AWS account you use. Remember to terminate the cluster and other related resources each time you finish working. The EMR cluster is costly.

2.这是您负责监视所使用的AWS账户的使用费用的责任。 请记住,每次完成工作时都要终止集群和其他相关资源。 EMR集群的成本很高。

3. This is one of the accessing projects for the Data Engineering nanodegree on Udacity. So to respect the Udacity Honor Code, I would not include the full notebook with the workflow to explore and build the ETL pipeline for the project. Part of the Jupyter notebook version of this tutorial, together with other tutorials on Spark and many more data science tutorials could be found on my github.

3.这是Udacity上的数据工程纳米学位的访问项目之一。 因此,为了遵守Udacity荣誉守则,我不会在工作流程中包括完整的笔记本来探索和构建该项目的ETL管道。 本教程的Jupyter笔记本版本的一部分,以及Spark上的其他教程以及更多数据科学教程,都可以在我的github上找到

项目介绍 (Project Introduction)

项目目标 (Project Goal)

Sparkify is a startup company working on a music streaming app. Through the app, Sparkify has collected information about user activity and songs, which is stored as a directory of JSON logs (log-data - user activity) and a directory of JSON metadata files (song_data - song information). These data resides in a public S3 bucket on AWS.

Sparkify是一家致力于音乐流应用程序的新兴公司。 通过该应用程序,Sparkify收集了有关用户活动和歌曲的信息,这些信息存储为JSON日志的目录( log-data -用户活动)和JSON元数据文件的目录( song_data歌曲信息)。 这些数据位于AWS上的公共S3存储桶中。

In order to improve the business growth, Sparkify wants to move their processes and data onto the data lake on the cloud.

为了提高业务增长,Sparkify希望将其流程和数据移至云上的数据湖中。

This project would be a workflow to explore and build an ETL (Extract — Transform — Load) pipeline that:

该项目将是一个工作流程,用于探索和构建ETL(提取-转换-加载)管道 ,该管道包括:

  • Extracts data from S3

    从S3提取数据
  • Processes data into analytics tables using Spark on an AWS cluster

    在AWS集群上使用Spark将数据处理到分析表中
  • Loads the data back into S3 as a set of dimensional and fact tables for the Sparkify analytics team to continue finding insights in what songs their users are listening to.

    将数据作为一组维度表和事实表加载到S3中,以供Sparkify分析团队继续查找其用户正在收听的歌曲的见解。

Below are the sample from JSON log file and JSON song file:

以下是JSON日志文件和JSON歌曲文件的示例:

Image for post
Sample of the log_data json file
log_data json文件的样本
Image for post
Sample of the song_data json file
song_data json文件的样本

The dimension and fact tables for this database were designed as followed: Fields in bold: partition keys.

此数据库的维和事实表的设计如下: 粗体字的字段:分区键。

Image for post

(ERD diagram was made using https://dbdiagram.io/)

(ERD图是使用https://dbdiagram.io/制作的 )

Project Workflow

项目工作流程

This is my workflow for the project. An experienced data engineer might skip many of these steps, but for me, I would rather go slowly and learn more:

这是我的项目工作流程。 经验丰富的数据工程师可能会跳过许多步骤,但是对我来说,我宁愿慢慢学习并了解更多信息:

  • Build the ETL process step-by-step using Jupyter notebook on sample data in local directory; write output to local directory.

    使用Jupyter Notebook在本地目录中的示例数据上逐步构建ETL流程; 将输出写入本地目录。
  • Validate the ETL Process using the sub-dataset on AWS S3; write output t
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 使用Spark构建AWS数据湖可能会遇到以下问题: 1. 数据格式不一致:在构建数据湖,数据来自不同的来源,可能会有不同的格式。这可能会导致Spark无法正确解析数据。解决方法是使用Spark的Schema推断功能来自动推断数据格式,或手动指定Schema。 2. 数据质量问题数据湖中的数据可能存在质量问题,如缺失值、异常值等。可以使用Spark的数据清洗功能来处理这些问题。 3. 数据量过大:数据湖中的数据量可能非常大,可能会导致Spark的性能问题。可以使用Spark的分布式计算功能来处理大规模数据。 4. 数据安全问题数据湖中的数据可能包含敏感信息,需要进行安全保护。可以使用AWS的安全服务来保护数据湖中的数据。 5. 数据管理问题数据湖中的数据可能需要进行管理,如备份、恢复、版本控制等。可以使用AWS的数据管理服务来管理数据湖中的数据。 处理这些问题的方法包括使用Spark的功能和AWS的服务来解决。同,需要根据具体情况进行调整和优化,以确保数据湖的稳定和可靠性。 ### 回答2: 使用Spark构建AWS数据湖可能会遇到以下一些问题,以及相应的解决方法: 1. 数据分析速度慢:当数据湖中的数据量非常大Spark可能无法快速处理,导致分析速度慢。可以采取以下几种解决办法:首先,优化代码和查询,使用更高效的算法和数据结构;其次,增加集群的规模,增加集群的计算和存储资源,从而提高处理速度;另外,可以使用数据分区、分区缓存等技术来提高查询性能。 2. 数据质量问题:在构建数据湖,数据源可能来自不同的系统,数据质量可能存在问题,如缺失值、错误数据等。可以通过使用Spark的数据清洗和转换功能,对数据进行清洗和修正,去除错误或缺失的数据,从而提高数据质量。 3. 数据安全问题数据湖中储存的数据可能包含敏感信息,需要确保数据的安全性。可以通过使用AWS提供的安全服务,如AWS Identity and Access Management(IAM)、加密存储等,来确保数据的安全性。同,还可以使用Spark的安全特性,如数据加密、访问控制等,对数据进行保护。 4. 自动化数据处理问题:在构建数据湖,可能需要定期从不同的数据源中获取数据,并进行清洗、转换等处理。可以使用Spark的调度功能,如Apache Airflow等,来自动化这些数据处理流程,以减少人工干预,提高效率。 5. 数据一致性问题:在数据湖中,可能存在来自不同源的数据,这些数据可能不一致,如字段名、数据格式等不同。可以使用Spark的数据合并和转换功能,将来自不同数据源的数据统一到一致的格式中,从而提高数据一致性。 通过解决以上问题,可以更好地构建和管理AWS数据湖,从而提高数据分析的效率和准确性。 ### 回答3: 使用Spark构建AWS数据湖可能会遇到以下一些问题,以及相应的处理方式: 1. 数据源的异构性:AWS数据湖通常包含各种类型的数据源,如结构化数据、半结构化数据和非结构化数据。在使用Spark构建数据湖,可能需要处理这些不同类型的数据。可以使用Spark的多功能性来处理不同的数据源,根据不同的需求采用适当的处理方式。 2. 数据质量和一致性:AWS数据湖中的数据可能来自不同的数据源,可能存在数据质量和一致性的问题。可以使用Spark的数据清洗和转换功能来清理和规范化数据。此外,还可以使用Spark的数据验证和一致性检查功能来确保数据的质量和一致性。 3. 大规模数据的处理AWS数据湖中可能存储着大规模的数据,使用传统的数据处理方法可能会面临性能瓶颈。使用Spark可以充分利用其分布式计算能力,在集群上并行处理大规模数据,提高处理效率。 4. 数据安全和权限管理:AWS数据湖中的数据可能包含敏感信息,需要进行安全保护。可以使用AWS的安全功能,如访问控制策略和加密功能,来确保数据的安全性。此外,还可以使用Spark的身份验证和授权功能来限制对数据湖的访问权限。 5. 数据湖架构的设计:AWS数据湖的设计涉及到数据的组织和管理方式。可以使用Spark的数据分区和分桶功能,根据不同的需求对数据进行组织和管理。可以根据数据的属性和访问模式来设计合适的数据湖架构,提高数据的查询和访问效率。 总之,使用Spark构建AWS数据湖需注意处理数据源的异构性、数据质量和一致性、大规模数据的处理、数据安全和权限管理、以及数据湖架构的设计。通过合理使用Spark的功能和AWS的安全和管理功能,可以解决这些问题构建高效可靠的数据湖

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值