zoukankan      html  css  js  c++  java
  • sparksql字段类型转换

    1、spark sql 计算时,一定要注意精度的问题,一般像金额之类的值,要先转换为double或者 decimal来进行计算了。

    一、sql的方式:
    select
    shop_id,order_id,sum(cast(deal_price as decimal(15,2))) deal_price,sum(cast(total_price as decimal(15,2))) total_price from aaa where stat_day='20190617' and cid1 not in (293,-1) and cid2 not in (422,421,427,525,446) and substr(pay_time,1,10)>='2019-06-01' and substr(pay_time,1,10)<='2019-06-17' group by shop_id,order_id
    二、df的方式:
      c_tran_df.withColumn("l_picked_amt", c_tran_df("l_special_amt").cast(DecimalType(15,4)))
    decimal(15,2)  
    2 表示小数部分的位数,如果插入的值,未指定小数部分或者小数部分不足两位,则会自动补到2为小数。
    15 表示整数部分加小数部分的总长度。         
  • 相关阅读:
    HTML5小游戏-绵羊快跑
    JavaScript模拟下拉菜单代码
    作业6
    作业5
    作业4
    作业三
    作业2(第二遍)
    sap jco3安装
    jmeter脚本文件(jmx)关联
    正则替换:删除空行、格式化Json/xml
  • 原文地址:https://www.cnblogs.com/ssqq5200936/p/12041489.html
Copyright © 2011-2022 走看看