pyspark执行hivesqlstr

spark执行hivesqlstr

法1:

spark = SparkSession \

   .builder \

   .appName("app_level") \

   .enableHiveSupport() \

.getOrCreate()

 

spark.sql(sql)

 

法2:

os.system("export PYSPARK_PYTHON=python2.7.5")

appName = "VL_caltion"

mode = "yarn-client"

conf =SparkConf().setAppName(appName).setMaster("yarn-client")

sc = SparkContext(conf=conf)

hiveContext= HiveContext(sc)

 

self.result=sku_result.join(dept_result,["dc_id","seller_code","dept_code"]).coalesce(10)\

               .select("seller_code","dept_code","sku_code","dc_id",F.when(sku_result.amt<10,dept_result.vl_mean_dept).otherwise(sku_result.vl_mean).alias("vl_mean"),

                       F.when(sku_result.amt<10,dept_result.vl_std_dept).otherwise(sku_result.vl_std).alias("vl_std"),

                       col("amt").alias("sku_order_count"),col("amt_dept").alias("dept_order_count"),

                       F.when(sku_result.amt<10,2).otherwise(1).alias("dim_type")).withColumn("dt",lit(endDate)).coalesce(10)

 

 

hiveContext.sql("set hive.exec.dynamic.partition.mode=nonstrict;set hive.exec.dynamic.partition=true;")

           hiveContext.sql("alter table app.app_ivlt drop if existspartition(dt='"+endDate+"')")

           self.result.write.mode("append").insertInto("app.app_ivlt ")

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值