根据此帖子,我的查询不起作用similar post
将以下命令与sql一起使用。但即时通讯不是从 shell 执行。 sql在python中创建为字符串,并使用paramiko传递给hive。在 shell 上工作正常。但是,当从python作为字符串传递时,im出现bash错误。看起来是一些角色逃逸问题。
我试图加载csv文件,每个列值都用双引号引起来。
strsql='''create table temp(col1 INT,col2 string) ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' WITH SERDEPROPERTIES ("quoteChar" = "\"") tblproperties ('skip.header.line.count'='1'); '''
错误
["bash: -c: line 4: unexpected EOF while looking for matching `''\n", 'bash: -c: line 5: syntax error: unexpe cted end of file\n']
我将其更改为
("quoteChar" = "\\"")
以添加额外的斜杠。然后我得到一个SQL错误:FAILED: ParseException line 4:38 cannot recognize input near 'quoteChar' '=' ')' i n table properties list
在进一步检查中,将使用以下某些提取属性来调用hive命令。这可能是个问题吗?
hive -e set hive.cli.print.header=true;hive.support.quoted.identifiers=column;hvesql;
最佳答案
理想情况下,sql应该包含双引号。如下。因此,正如罗纳克(Ronak)在评论中提到的,应避免使用双引号。
ROW FORMAT SERDE "org.apache.hadoop.hive.serde2.OpenCSVSerde"
WITH SERDEPROPERTIES ("quoteChar" = '"') tblproperties ("skip.header.line.count"="1")
因此,当从 shell 程序作为字符串变量发送时,应按以下说明进行转义。需要使用双斜杠
ROW FORMAT SERDE \\"org.apache.hadoop.hive.serde2.OpenCSVSerde\\"
WITH SERDEPROPERTIES (\\"quoteChar\\" = '\\"') tblproperties (\\"skip.header.line.count\\"=\\"1\\")
有点简单。但是花了很多时间才找到:)
关于python - 从双引号包含的csv文件格式配置单元数据加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48643406/