pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    • <bdo id='5zbEL'></bdo><ul id='5zbEL'></ul>

      <small id='5zbEL'></small><noframes id='5zbEL'>

      <tfoot id='5zbEL'></tfoot>
    1. <legend id='5zbEL'><style id='5zbEL'><dir id='5zbEL'><q id='5zbEL'></q></dir></style></legend>

    2. <i id='5zbEL'><tr id='5zbEL'><dt id='5zbEL'><q id='5zbEL'><span id='5zbEL'><b id='5zbEL'><form id='5zbEL'><ins id='5zbEL'></ins><ul id='5zbEL'></ul><sub id='5zbEL'></sub></form><legend id='5zbEL'></legend><bdo id='5zbEL'><pre id='5zbEL'><center id='5zbEL'></center></pre></bdo></b><th id='5zbEL'></th></span></q></dt></tr></i><div class="zhxnhpx" id='5zbEL'><tfoot id='5zbEL'></tfoot><dl id='5zbEL'><fieldset id='5zbEL'></fieldset></dl></div>

        在 SparkSQL 中使用窗口函數 (dense_rank()) 進行選擇

        select with window function (dense_rank()) in SparkSQL(在 SparkSQL 中使用窗口函數 (dense_rank()) 進行選擇)
        <i id='sKaUx'><tr id='sKaUx'><dt id='sKaUx'><q id='sKaUx'><span id='sKaUx'><b id='sKaUx'><form id='sKaUx'><ins id='sKaUx'></ins><ul id='sKaUx'></ul><sub id='sKaUx'></sub></form><legend id='sKaUx'></legend><bdo id='sKaUx'><pre id='sKaUx'><center id='sKaUx'></center></pre></bdo></b><th id='sKaUx'></th></span></q></dt></tr></i><div class="vl7vndr" id='sKaUx'><tfoot id='sKaUx'></tfoot><dl id='sKaUx'><fieldset id='sKaUx'></fieldset></dl></div>
          <bdo id='sKaUx'></bdo><ul id='sKaUx'></ul>

            <tbody id='sKaUx'></tbody>

        • <small id='sKaUx'></small><noframes id='sKaUx'>

          1. <tfoot id='sKaUx'></tfoot>
              <legend id='sKaUx'><style id='sKaUx'><dir id='sKaUx'><q id='sKaUx'></q></dir></style></legend>

                  本文介紹了在 SparkSQL 中使用窗口函數 (dense_rank()) 進行選擇的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個包含客戶購買記錄的表格,我需要指定購買是在特定日期時間窗口內進行的,一個窗口是 8 天,所以如果我今天購買了 5 天內購買了一次,那么如果窗口號是我的購買1,但如果我在今天的第一天和 8 天后的第二天這樣做,第一次購買將在窗口 1 中,最后一次購買將在窗口 2 中

                  I have a table which contains records for customer purchases, I need to specify that purchase was made in specific datetime window one window is 8 days , so if I had purchase today and one in 5 days its mean my purchase if window number 1, but if I did it on day one today and next in 8 days, first purchase will be in window 1 and the last purchase in window 2

                  create temporary table transactions
                   (client_id int,
                   transaction_ts datetime,
                   store_id int)
                  
                   insert into transactions values 
                   (1,'2018-06-01 12:17:37', 1),
                   (1,'2018-06-02 13:17:37', 2),
                   (1,'2018-06-03 14:17:37', 3),
                   (1,'2018-06-09 10:17:37', 2),
                   (2,'2018-06-02 10:17:37', 1),
                   (2,'2018-06-02 13:17:37', 2),
                   (2,'2018-06-08 14:19:37', 3),
                   (2,'2018-06-16 13:17:37', 2),
                   (2,'2018-06-17 14:17:37', 3)
                  

                  窗口是8天,問題是我不明白如何指定dense_rank() OVER (PARTITION BY)查看日期時間并在8天內制作一個窗口,結果我需要這樣的東西

                  the window is 8 days, the problem is I don't understand how to specify for dense_rank() OVER (PARTITION BY) to look at datetime and make a window in 8 days, as result I need something like this

                  1,'2018-06-01 12:17:37', 1,1
                  1,'2018-06-02 13:17:37', 2,1
                  1,'2018-06-03 14:17:37', 3,1
                  1,'2018-06-09 10:17:37', 2,2
                  2,'2018-06-02 10:17:37', 1,1
                  2,'2018-06-02 13:17:37', 2,1
                  2,'2018-06-08 14:19:37', 3,2
                  2,'2018-06-16 13:17:37', 2,3
                  2,'2018-06-17 14:17:37', 3,3
                  

                  知道如何獲得它嗎?我可以在 Mysql 或 Spark SQL 中運行它,但 Mysql 不支持分區.還是找不到解決辦法!任何幫助

                  any idea how to get it? I can run it in Mysql or Spark SQL, but Mysql doesn't support partition. Still cannot find solution! any help

                  推薦答案

                  很可能你可以在 Spark SQL 中使用時間和分區窗口函數來解決這個問題:

                  Most likely you may solve this in Spark SQL using time and partition window functions:

                  val purchases = Seq((1,"2018-06-01 12:17:37", 1), (1,"2018-06-02 13:17:37", 2), (1,"2018-06-03 14:17:37", 3), (1,"2018-06-09 10:17:37", 2), (2,"2018-06-02 10:17:37", 1), (2,"2018-06-02 13:17:37", 2), (2,"2018-06-08 14:19:37", 3), (2,"2018-06-16 13:17:37", 2), (2,"2018-06-17 14:17:37", 3)).toDF("client_id", "transaction_ts", "store_id")
                  
                  purchases.show(false)
                  +---------+-------------------+--------+
                  |client_id|transaction_ts     |store_id|
                  +---------+-------------------+--------+
                  |1        |2018-06-01 12:17:37|1       |
                  |1        |2018-06-02 13:17:37|2       |
                  |1        |2018-06-03 14:17:37|3       |
                  |1        |2018-06-09 10:17:37|2       |
                  |2        |2018-06-02 10:17:37|1       |
                  |2        |2018-06-02 13:17:37|2       |
                  |2        |2018-06-08 14:19:37|3       |
                  |2        |2018-06-16 13:17:37|2       |
                  |2        |2018-06-17 14:17:37|3       |
                  +---------+-------------------+--------+
                  
                  
                  
                  val groupedByTimeWindow = purchases.groupBy($"client_id", window($"transaction_ts", "8 days")).agg(collect_list("transaction_ts").as("transaction_tss"), collect_list("store_id").as("store_ids"))
                  
                  val withWindowNumber = groupedByTimeWindow.withColumn("window_number", row_number().over(windowByClient))
                  
                  withWindowNumber.orderBy("client_id", "window.start").show(false)
                  
                      +---------+---------------------------------------------+---------------------------------------------------------------+---------+-------------+
                  |client_id|window                                       |transaction_tss                                                |store_ids|window_number|
                  +---------+---------------------------------------------+---------------------------------------------------------------+---------+-------------+
                  |1        |[2018-05-28 17:00:00.0,2018-06-05 17:00:00.0]|[2018-06-01 12:17:37, 2018-06-02 13:17:37, 2018-06-03 14:17:37]|[1, 2, 3]|1            |
                  |1        |[2018-06-05 17:00:00.0,2018-06-13 17:00:00.0]|[2018-06-09 10:17:37]                                          |[2]      |2            |
                  |2        |[2018-05-28 17:00:00.0,2018-06-05 17:00:00.0]|[2018-06-02 10:17:37, 2018-06-02 13:17:37]                     |[1, 2]   |1            |
                  |2        |[2018-06-05 17:00:00.0,2018-06-13 17:00:00.0]|[2018-06-08 14:19:37]                                          |[3]      |2            |
                  |2        |[2018-06-13 17:00:00.0,2018-06-21 17:00:00.0]|[2018-06-16 13:17:37, 2018-06-17 14:17:37]                     |[2, 3]   |3            |
                  +---------+---------------------------------------------+---------------------------------------------------------------+---------+-------------+
                  

                  如果需要,您可以explode 列出 store_ids 或 transaction_tss 中的元素.

                  If you need, you may explode list elements from store_ids or transaction_tss.

                  希望能幫到你!

                  這篇關于在 SparkSQL 中使用窗口函數 (dense_rank()) 進行選擇的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                  <tfoot id='uq6ex'></tfoot>
                1. <i id='uq6ex'><tr id='uq6ex'><dt id='uq6ex'><q id='uq6ex'><span id='uq6ex'><b id='uq6ex'><form id='uq6ex'><ins id='uq6ex'></ins><ul id='uq6ex'></ul><sub id='uq6ex'></sub></form><legend id='uq6ex'></legend><bdo id='uq6ex'><pre id='uq6ex'><center id='uq6ex'></center></pre></bdo></b><th id='uq6ex'></th></span></q></dt></tr></i><div class="hfx1ztd" id='uq6ex'><tfoot id='uq6ex'></tfoot><dl id='uq6ex'><fieldset id='uq6ex'></fieldset></dl></div>

                    <tbody id='uq6ex'></tbody>

                        <legend id='uq6ex'><style id='uq6ex'><dir id='uq6ex'><q id='uq6ex'></q></dir></style></legend>

                        <small id='uq6ex'></small><noframes id='uq6ex'>

                            <bdo id='uq6ex'></bdo><ul id='uq6ex'></ul>
                            主站蜘蛛池模板: 五轴加工中心_数控加工中心_铝型材加工中心-罗威斯 | 板材品牌-中国胶合板行业十大品牌-环保板材-上海声达板材 | 伊卡洛斯软装首页-电动窗帘,别墅窗帘,定制窗帘,江浙沪1000+别墅窗帘案例 | 丁基胶边来料加工,医用活塞边角料加工,异戊二烯橡胶边来料加工-河北盛唐橡胶制品有限公司 | 航拍_专业的无人机航拍摄影门户社区网站_航拍网 | 求是网 - 思想建党 理论强党 | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | 自动售货机_无人售货机_专业的自动售货机运营商_免费投放售货机-广州富宏主官网 | 儿童乐园|游乐场|淘气堡招商加盟|室内儿童游乐园配套设备|生产厂家|开心哈乐儿童乐园 | GAST/BRIWATEC/CINCINNATI/KARL-KLEIN/ZIEHL-ABEGG风机|亚喜科技 | 彩信群发_群发彩信软件_视频短信营销平台-达信通 | 屏蔽泵厂家,化工屏蔽泵_维修-淄博泵业| 福州甲醛检测-福建室内空气检测_环境检测_水质检测-福建中凯检测技术有限公司 | 电子厂招聘_工厂招聘_普工招聘_小时工招聘信息平台-众立方招工网 | 碳纤维布-植筋胶-灌缝胶-固特嘉加固材料公司| 海德莱电力(HYDELEY)-无功补偿元器件生产厂家-二十年专业从事电力电容器 | 没斑啦-专业的祛斑美白嫩肤知识网站-去斑经验分享 | 合肥宠物店装修_合肥宠物美容院装修_合肥宠物医院设计装修公司-安徽盛世和居装饰 | 天然气分析仪-液化气二甲醚分析仪|传昊仪器 | 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 | 庭院灯_太阳能景观灯_草坪灯厂家_仿古壁灯-重庆恒投科技 | TwistDx恒温扩增-RAA等温-Jackson抗体-默瑞(上海)生物科技有限公司 | 板材品牌-中国胶合板行业十大品牌-环保板材-上海声达板材 | 福建自考_福建自学考试网 | 广州展台特装搭建商|特装展位设计搭建|展会特装搭建|特装展台制作设计|展览特装公司 | 重庆磨床过滤机,重庆纸带过滤机,机床伸缩钣金,重庆机床钣金护罩-重庆达鸿兴精密机械制造有限公司 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 耐酸碱泵-自吸耐酸碱泵型号「品牌厂家」立式耐酸碱泵价格-昆山国宝过滤机有限公司首页 | 电动垃圾车,垃圾清运车-江苏速利达机车有限公司 | 氟氨基酮、氯硝柳胺、2-氟苯甲酸、异香兰素-新晨化工 | 创绿家招商加盟网-除甲醛加盟-甲醛治理加盟-室内除甲醛加盟-创绿家招商官网 | 上海皓越真空设备有限公司官网-真空炉-真空热压烧结炉-sps放电等离子烧结炉 | 车间除尘设备,VOCs废气处理,工业涂装流水线,伸缩式喷漆房,自动喷砂房,沸石转轮浓缩吸附,机器人喷粉线-山东创杰智慧 | 釜溪印象网络 - Powered by Discuz! | KBX-220倾斜开关|KBW-220P/L跑偏开关|拉绳开关|DHJY-I隔爆打滑开关|溜槽堵塞开关|欠速开关|声光报警器-山东卓信有限公司 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 | 自动检重秤-动态称重机-重量分选秤-苏州金钻称重设备系统开发有限公司 | 东莞ERP软件_广州云ERP_中山ERP_台湾工厂erp系统-广东顺景软件科技有限公司 | 中红外QCL激光器-其他连续-半导体连续激光器-筱晓光子 | arch电源_SINPRO_开关电源_模块电源_医疗电源-东佑源 | MES系统-WMS系统-MES定制开发-制造执行MES解决方案-罗浮云计算 |