【发布时间】:2018-09-09 17:27:38
【问题描述】:
我有一个 Amazon EMR 集群 - 30 个节点 我的 Python 代码如下所示 -
spark = SparkSession \
.builder \
.appName("App") \
.config(conf=sparkConf) \
.getOrCreate()
def fetchCatData(cat, tableName):
df_gl = spark.sql("select * from {} where category = {}".format(tableName, cat))
df_pandas = df_gl.select("*").toPandas()
df_pandas.to_csv("/tmp/split/{}_{}.csv".format(tableName, cat))
catList = [14, 15, 63, 65, 74, 21, 23, 60, 79, 86, 107, 147, 196, 199, 200, 201, 229, 263, 265, 267, 328, 421, 468, 469,504]
tableList = ["Table1","Table2"
,"Table3",
"Table4", "Table5", "Table6",
"Table7"
]
def main(args):
log4jLogger = spark._jvm.org.apache.log4j
LOGGER = log4jLogger.LogManager.getLogger(__name__)
for table in tableList:
LOGGER.info("Starting Split for {}".format(table))
dataLocation = "s3://test/APP/{}".format( table)
df = spark.read.parquet(dataLocation)
df = df.repartition("CATEGORY").cache()
df.createOrReplaceTempView(table)
for cat in catList:
fetchGLData(cat, table)
我想解决以下问题-
- 基本上我想读取我的镶木地板数据,将其按类别划分并将其作为 pandas 数据框存储在 csv 中。
- 目前我正在按顺序运行,我想在 EMR 中的一个节点上运行每个类别并行运行它
- 我尝试使用多处理,但对结果不满意。
在最短的时间内解决这个问题的最佳方法是什么?
【问题讨论】:
标签: python pandas pyspark amazon-emr