【问题标题】:Selecting string after the last \\ using regex with Impala SQL使用正则表达式和 Impala SQL 在最后一个 \\ 之后选择字符串
【发布时间】:2018-12-03 18:19:49
【问题描述】:

我有一个数据集,其中有一列包含进程和路径。我正在尝试将正则表达式与 Impala 一起使用来剥离可执行文件。数据集如下所示:

C:\\Windows\\System32\\svchost.exe
C:\\Windows\\System32\\conhost.exe
C:\\Windows\\System32\\net1.exe
C:\\Windows\\System32\\schtasks.exe
C:\\Program Files (x86)\\Citrix\\ICA Client\\SelfServicePlugin\\SelfService.exe
C:\\Windows\\System32\\backgroundTaskHost.exe
C:\\Windows\\System32\\net.exe
C:\\Windows\\System32\\conhost.exe
C:\\Program Files (x86)\\Wireless AutoSwitch\\wrlssw.exe

期望的输出:

svchost.exe
conhost.exe
net1.exe
schtasks.exe
SelfService.exe
backgroundTaskHost.exe
net.exe
conhost.exe
wrlssw.exe

我已经尝试了很多类似下面两个的查询,但总是遇到错误

select regexp_extract(w.destinationprocessname, '([^\\]+)$')
from winworkstations_realtime w
where w.externalid = '4688'
limit 10

错误:

AnalysisException: No matching function with signature: regexp_replace(STRING, STRING).

select regexp_extract(w.destinationprocessname, '\\(?:.(?!\\))+$',0)
from winworkstations_realtime w
where w.externalid = '4688'
limit 10

错误:

Could not compile regexp pattern: \(?:.(?!\))+$ Error: invalid perl operator: (?!

向任何擅长 impala 或正则表达式的人寻求一些指导。

【问题讨论】:

  • 您知道您使用的是哪个版本的 ImpalaSQL?也许regex_replace 只是在较新的版本中实现...
  • 状态存储版本 2.10.0-cdh5.13.0 RELEASE @AdrianoValente

标签: sql regex impala


【解决方案1】:

不是正则表达式专家,我相信有更好的方法,但这确实有效

select regexp_replace(regexp_extract("C:\\\Windows\\\\System32\\\\svchost.exe", ".+(\\\\.+)$", 1), "\\\\", "");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 2022-01-20
    • 1970-01-01
    • 2023-02-10
    • 2021-02-23
    • 1970-01-01
    相关资源
    最近更新 更多