【问题标题】:Amend part of string using BigQuery REGEXP_REPLACE使用 BigQuery REGEXP_REPLACE 修改部分字符串
【发布时间】:2019-08-24 14:57:55
【问题描述】:

我想知道是否有人可以帮助我。

我的 bigquery 表中的 eventinfo.eventLabel 字段包含以下数据:

查看 BDAT 组的红色查看代码

SELECT
  #select all fields excluding those under the hits record
  * EXCEPT (hits),
  #start array - this rebuilds the hit record
  ARRAY(
  SELECT
    #unnest the hit field, select each field excluding those under the page record
    AS STRUCT * EXCEPT (eventInfo ),
    (
    SELECT
      #select all page fields excluding pageTitle
      AS STRUCT eventInfo.* EXCEPT (eventLabel),
      #remove the query parameter from the pagePath fields
      REGEXP_REPLACE(eventinfo.eventLabel, r'View\sView .*', 'View View redacted') AS eventLabel) AS eventinfo
  FROM
    UNNEST(hits) ) AS hits
FROM
  `bigquery.Tested.ga_sessions_20180801` 

我正在尝试删除数据的“红色代码”元素并将其替换为术语“已编辑”。

请注意,“红色代码”不是唯一的值,字符数可以增加和减少。但是“视图视图”和“用于”在我的数据中是不变的。

我知道问题出在 REGEXP REPLACE 行,我可以设法将“已编辑”文本放入字段中,但我无法删除“代码红色”文本。

有人可以看看这个并提供一些关于我如何能够改变它的指导。

非常感谢和亲切的问候

克里斯

【问题讨论】:

    标签: string google-bigquery regexp-replace


    【解决方案1】:
    select 
      [
      REGEXP_REPLACE('View View Code red for the BDAT group', r'View View .*? for the', 'View View redacted for the'),
      REGEXP_REPLACE('View View Code blue for the BDAT group', r'View View .*? for the', 'View View redacted for the'),
      REGEXP_REPLACE('View View red code for the BDAT group', r'View View .*? for the', 'View View redacted for the')
      ]
    

    【讨论】:

    • 嗨@Yun Zhang。感谢您抽出宝贵时间与我联系。效果很好。
    猜你喜欢
    • 2014-11-17
    • 2017-01-11
    • 2016-06-07
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    相关资源
    最近更新 更多