gwy*_*842 7 python apache-spark pyspark
这里是新手,我通过 JDBC 从 PySpark 中的 MySQL 读取了一个表(大约 200 万行)作为 Spark 的 DataFrame,并尝试显示前 10 行:
from pyspark.sql import SparkSession
spark_session = SparkSession.builder.master("local[4]").appName("test_log_processing").getOrCreate()
url = "jdbc:mysql://localhost:3306"
table = "test.fakelog"
properties = {"user": "myUser", "password": "********"}
df = spark_session.read.jdbc(url, table, properties=properties)
df.cache()
df.show(10) # can't get the printed results, and runs pretty slow and consumes 90%+ CPU resources
spark_session.stop()
Run Code Online (Sandbox Code Playgroud)
这是控制台日志:
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
[Stage 0:> (0 + 1) / 1]
Run Code Online (Sandbox Code Playgroud)
我的教育背景是统计学,最近刚刚开始学习 Spark,所以我不知道代码背后发生了什么(对于较小的数据集,这效果很好),我应该如何解决这个问题?或者说我还应该了解哪些关于Spark的知识?
mur*_*ash -2
| 归档时间: |
|
| 查看次数: |
8029 次 |
| 最近记录: |