用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/OleanderHQ/pyspark-template --skill spark-best-practices命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | spark-best-practices |
| description | General Apache Spark best practices for scalable, maintainable, and performant DataFrame jobs. |
Use this skill for general Apache Spark guidance when optimizing performance, reliability, and maintainability.
collect(), toPandas(), and large take() in core data paths.coalesce when reducing output partitions.explain() and execution metrics/logs to inspect physical plans and shuffle boundaries.Every Structured Streaming query needs a stable checkpoint location. The checkpoint stores progress metadata and, for stateful queries such as windows, state-store data that Spark needs to recover correctly.
Use shared storage for cluster runs, not local /tmp, because executors must be
able to see the same checkpoint path.
oleander provides spark.oleander.app.state.dir as a shared application state
directory that users can use for streaming checkpoints.
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, count, window
spark = SparkSession.builder.appName("message-counts").getOrCreate()
state_dir = spark.conf.get("spark.oleander.app.state.dir", "").strip()
checkpoint = f"{state_dir.rstrip('/')}/public-stream/checkpoints/message-counts"
events = (
spark.readStream.format("kafka")
.option("kafka.bootstrap.servers", "localhost:9092")
.option("subscribe", "messages")
.load()
)
counts = (
events.selectExpr("CAST(value AS STRING) AS body", "timestamp AS event_time")
.withWatermark("event_time", "1 minute")
.groupBy(window(col("event_time"), "1 minute"))
.agg(count("*").alias("message_count"))
)
query = (
counts.writeStream
.format("console")
.outputMode("append")
.option("checkpointLocation", checkpoint)
.start()
)
query.awaitTermination()