jsonarray打jar包处理.sql


MSCK REPAIR TABLE dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h;

drop table if exists dw_tmp.a02;
create table dw_tmp.a02(
    content string
);
insert overwrite table dw_tmp.a02
select get_json_object(get_json_object(get_json_object(get_json_object(content,'$.trade_fullinfo_get_response'),'$.trade'),'$.promotion_details'),'$.promotion_detail')
from
dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h
where  dt >= '2023030710' limit 1;





WITH a_json
         AS (SELECT '
{
   "fixed_charge": {
      "discount": 1,
      "fixed_fee": -1,
      "end_amount": -1,
      "actual_rate": -1,
      "origin_rate": -1,
      "start_amount": -1
   },
   "float_charges": [
      {
         "discount": 10,
         "fixed_fee": -1,
         "end_amount": 1000000,
         "actual_rate": 0.01,
         "origin_rate": 0.01,
         "start_amount": 0
      },
      {
         "discount": 10,
         "fixed_fee": -1,
         "end_amount": 3000000,
         "actual_rate": 0.006,
         "origin_rate": 0.006,
         "start_amount": 1000000
      },
      {
         "discount": 10,
         "fixed_fee": -1,
         "end_amount": 5000000,
         "actual_rate": 0.002,
         "origin_rate": 0.002,
         "start_amount": 3000000
      },
      {
         "discount": -1,
         "fixed_fee": 1000,
         "end_amount": -999,
         "actual_rate": -1,
         "origin_rate": -1,
         "start_amount": 5000000
      }
   ],
   "user_discount_flag": 0
}' AS doc)
SELECT GET_JSON_OBJECT(doc, '$.fixed_charge.discount'),
       GET_JSON_OBJECT(doc, '$.fixed_charge.fixed_fee'),
       GET_JSON_OBJECT(doc, '$.fixed_charge.end_amount'),
       GET_JSON_OBJECT(doc, '$.fixed_charge.actual_rate'),
       GET_JSON_OBJECT(doc, '$.fixed_charge.origin_rate'),
       GET_JSON_OBJECT(doc, '$.fixed_charge.start_amount'),
       GET_JSON_OBJECT(float_charges, '$.discount'),
       GET_JSON_OBJECT(float_charges, '$.fixed_fee'),
       GET_JSON_OBJECT(float_charges, '$.end_amount'),
       GET_JSON_OBJECT(float_charges, '$.actual_rate'),
       GET_JSON_OBJECT(float_charges, '$.origin_rate'),
       GET_JSON_OBJECT(float_charges, '$.start_amount'),
       GET_JSON_OBJECT(doc, '$.float_charges')
FROM a_json t
         LATERAL VIEW
--              EXPLODE_JSON_ARRAY(GET_JSON_OBJECT(doc, '$.float_charges')) tmp AS float_charges;
             ExplodeJSON2(GET_JSON_OBJECT(doc, '$.float_charges')) tmp AS float_charges;




create table dw_ods.ods_app_tmall_trade_fullinfo_get_topic_iu_h(
    content string
)partitioned by (dt string);

create table dw_ods.ods_app_tmall_items_seller_list_get_topic_iu_h(
    content string
)partitioned by (dt string);




select count(1)
from (
    select dt,
           single_sku_array,
           item
    from (
       select dt,
              item,
              get_json_object(get_json_object(item,'$.skus'),'$.sku') sku_array
       from (
           select
                  get_json_object(get_json_object(get_json_object(content, '$.items_seller_list_get_response'), '$.items'),'$.item')item_array,
                  dt
           from dw_ods.ods_app_tmall_items_seller_list_get_topic_iu_h
           where dt >= '2023030701' and  dt <= '2023030701'
       )t LATERAL VIEW EXPLODE_JSON_ARRAY(item_array) tmp as item
       where get_json_object(get_json_object(item,'$.skus'),'$.sku') is not null
    ) LATERAL VIEW EXPLODE_JSON_ARRAY(sku_array) tmp2 as single_sku_array
);















### 回答1: 这段代码的作用是将一个名为"data"的对象转换为JSON格式的字符串,然后再将该字符串解析为一个JSONArray对象。其中,JSONArray.parseArray() 方法将JSON字符串转换为JSONArray对象,而JSONArray.toJSONString() 方法将Java对象转换为JSON格式的字符串。最终得到的 JSONArray 对象可以用于操作和处理JSON数据。 ### 回答2: 这段代码是使用阿里巴巴的fastjson库中的JSONArray类来对一个对象data进行转换的过程。 首先,JSONArray.parseArray(JSONArray.toJSONString(data))这个方法是将一个对象data转换为JSON格式的字符串,然后再通过JSONArray.parseArray()方法将这个JSON格式的字符串解析为JSONArray数组对象。 具体来说,JSONArray.toJSONString(data)这个方法会将data对象转换为JSON格式的字符串。这个字符串的格式符合JSON的规范,可以表示列表、键值对以及嵌套的JSON对象。 然后,JSONArray.parseArray()方法将JSON格式的字符串解析为JSONArray对象。这个JSONArray对象可以提供一系列方法来操作和遍历JSON数据,比如获取元素、添加元素等。 总的来说,这段代码的作用是将一个对象转换为JSON格式的字符串,再将这个JSON格式的字符串解析为JSONArray数组对象。这样可以方便地对JSON数据进行操作和处理。 ### 回答3: 这行代码的作用是将一个名为"data"的对象转换为JSONArray类型的数组。 首先,通过JSONArray.toJSONString(data)将对象"data"转换为JSON字符串。 然后,再使用JSONArray.parseArray()方法将JSON字符串转换为JSONArray类型的数组。 这样做的目的是将一个复杂的数据结构(例如Java对象)转换为JSON数组,方便在接收方进行处理和解析。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值