如何使用hive -e“QUERY”语法编写以下查询。原因是查询本身包含双引号和%。
create external table tmp2(logdate string, time string, computername string, clientip string, uri string, qs string, localfile string, status string, referer string, w3status string, sc_bytes string, cs_bytes string, w3wpbytes string, cs_username string, cs_user_agent string, time_local string, timetakenms string, sc_substatus string, s_sitename string, s_ip string, s_port string, RequestsPerSecond string, s_proxy string, cs_version string, c_protocol string, cs_method string, cs_Host string, EndRequest_UTC string, date_local string, CPU_Utilization string, cs_Cookie string, BeginRequest_UTC string) ROW FORMAT SERDE
'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" ="([0-9-]+) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) (\".*\"|[^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) (\".*\"|[^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) (\".*\"|[^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([^ ]*) ([0-9-]+ [0-9:.]+) ([^ ]*) ([^ ]*) (\".*\"|[^ ]*) ([0-9-]+ [0-9:.]+)",
"output.format.string"="%1$s %2$s %3$s %4$s %5$s %6$s %7$s %8$s %9$s %10$s %11$s %12$s %13$s %14$s %15$s %16$s %17$s %18$s %19$s %20$s %21$s %22$s %23$s %24$s %25$s %26$s %27$s %28$s %29$s %30$s %31$s %32$s")
答案 0 :(得分:1)
这完全取决于您如何将其发送到Hive。只需从命令行运行它,您就必须遵循双引号的标准转义规则。如果你有双引号内的引号,你必须用反斜杠转义它。同样,你必须使用另一个反斜杠来逃避反斜杠。
另外,请务必在引号内转义回车。
如果我们像这样简化你的例子:
create external table tmp2(logdate string, time string) ROW FORMAT SERDE
'org.apache.hadoop.hive.contrib.serde2.RegexSerDe'
WITH SERDEPROPERTIES (
"input.regex" = "(\".*\"|[^ ]*) (\".*\"|[^ ]*)",
"output.format.string"="%1$s %2$s")
然后你应该能够从命令行运行它:
hive -e "create external table tmp2(logdate string, time string) ROW FORMAT SERDE \
'org.apache.hadoop.hive.contrib.serde2.RegexSerDe' \
WITH SERDEPROPERTIES ( \
\"input.regex\" = \"(\\\".*\\\"|[^ ]*) (\\\".*\\\"|[^ ]*)\", \
\"output.format.string\"=\"%1$s %2$s\")"
我建议在发布之前简化您的问题。有时,简化行为将为您解决问题。
答案 1 :(得分:-1)
您需要使用三重反斜杠