gpt4 book ai didi

pyspark 程序抛出名称 'spark' 未定义

转载 作者:行者123 更新时间:2023-12-02 03:13:35 25 4
gpt4 key购买 nike

下面的程序抛出错误名称 'spark' is not defined

Traceback (most recent call last):  
File "pgm_latest.py", line 232, in <module>
sconf =SparkConf().set(spark.dynamicAllocation.enabled,true)
.set(spark.dynamicAllocation.maxExecutors,300)
.set(spark.shuffle.service.enabled,true)
.set(spark.shuffle.spill.compress,true)
NameError: name 'spark' is not defined
spark-submit --driver-memory 12g --master yarn-cluster --executor-memory 6g --executor-cores 3 pgm_latest.py

代码

#!/usr/bin/python
import sys
import os
from datetime import *
from time import *
from pyspark.sql import *
from pyspark
import SparkContext
from pyspark import SparkConf

sc = SparkContext()
sqlCtx= HiveContext(sc)

sqlCtx.sql('SET spark.sql.autoBroadcastJoinThreshold=104857600')
sqlCtx.sql('SET Tungsten=true')
sqlCtx.sql('SET spark.sql.shuffle.partitions=500')
sqlCtx.sql('SET spark.sql.inMemoryColumnarStorage.compressed=true')
sqlCtx.sql('SET spark.sql.inMemoryColumnarStorage.batchSize=12000')
sqlCtx.sql('SET spark.sql.parquet.cacheMetadata=true')
sqlCtx.sql('SET spark.sql.parquet.filterPushdown=true')
sqlCtx.sql('SET spark.sql.hive.convertMetastoreParquet=true')
sqlCtx.sql('SET spark.sql.parquet.binaryAsString=true')
sqlCtx.sql('SET spark.sql.parquet.compression.codec=snappy')
sqlCtx.sql('SET spark.sql.hive.convertMetastoreParquet=true')

## Main functionality
def main(sc):

if name == 'main':

# Configure OPTIONS
sconf =SparkConf() \
.set("spark.dynamicAllocation.enabled","true")\
.set("spark.dynamicAllocation.maxExecutors",300)\
.set("spark.shuffle.service.enabled","true")\
.set("spark.shuffle.spill.compress","true")

sc =SparkContext(conf=sconf)

# Execute Main functionality

main(sc)
sc.stop()

最佳答案

我认为您使用的是比 2.x 更旧的 spark 版本。

而不是这个

spark.createDataFrame(..)

在下面使用

> df = sqlContext.createDataFrame(...)

关于pyspark 程序抛出名称 'spark' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38403113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com