Impala Shell 查询 -q 在字符串中带有双引号

Posted

技术标签:

【中文标题】Impala Shell 查询 -q 在字符串中带有双引号【英文标题】:Impala Shell query -q with double quotes in string 【发布时间】:2016-06-21 15:55:05 【问题描述】:

我正在生成一个文本文件,plink 正在使用该文本文件来使用 impala shell 并使用 -q 运行插入语句。目前使用来自 Wikipedia 的虚拟数据来确保它没有错误,然后我才愤怒地使用它。

这在几乎所有情况下都可以正常工作,除了以下情况(我更改了一些位,但结果相同):

impala-shell -c -k -q "INSERT INTO TABLE imaginarydatabasename.T_Test
VALUES
('Bob','Monkhouse','1928-06-01',2003,'An expert on the history of silent cinema and a film collector, Monkhouse presented Mad Movies in 1966. He wrote, produced, financed and syndicated the show worldwide. The show featured clips from comic silent films, many from his own private collection, some of which he had helped to recover and restore. This film collection was the cause of a court case at the Old Bailey in 1979. Having loaned Terry Wogan\'s son a film, Monkhouse was charged with attempting to defraud film distributors of royalties, but after two years the judge decided that there was no case to answer.[8] Many of the films in his collection were seized and not returned to Monkhouse.[9] In 2008, the British Film Institute was contacted by Monkhouse\'s daughter, Abigail, who asked if they would like to view the collection and provide some advice as to the best way of preserving it. Amongst the discoveries were many radio and TV shows long thought lost. Dick Fiddy, the archivist, said \"It\'s a huge, unwieldy collection which deals with a number of areas. It\'s not just film and TV. Initially, we found half a dozen TV shows that we knew to be missing.\" Amongst those shows rediscovered were many that feature Monkhouse himself, including The Flip Side, a 1966 play in which he starred as a television DJ with his own late night show, and the 1957/58 series of his comedy My Pal Bob including an episode in which he is suspected of an extramarital affair.[10] The archive consisted of 36,000 videotapes, going back to when Monkhouse first bought a home video recorder in 1966. His film archive began in the late 1950s. The entire Monkhouse film and television archive is now held by Kaleidoscope, including all the material previously held by the NFTVA. It was catalogued and restored to digital formats for a major event at Bafta on 24 October 2009. Chris Perry, of Kaleidoscope and Kaleidoscope Publishing, said: \"We are painstakingly transferring the important contents of the video tapes and restoring radio shows. There are many incredible finds, and the event [is] an exciting time for all concerned.\" In his final years, Monkhouse hosted a show on BBC Radio 2 called The Monkhouse Archive, in which he provided humorous links to clips of comedy acts spanning the previous 50 years.',1,2.5,'2016-06-21 14:41:25');" -i impala-server.com;

如果我复制外部双引号内的部分(q 正在运行的内容),将其粘贴到 hue 并执行它,我没有问题。

我认为正在发生的事情是第 5 列中的双引号告诉 shell 的 -q 部分查询文本已经结束。

我如何告诉 shell 双引号没有结束它?

【问题讨论】:

【参考方案1】:

测试它的一种方法是运行直接选择语句而不是插入,以查看 impala shell 是否能够执行查询。从您的代码中查看下面的示例。我能够毫无问题地执行它,但是如果我去掉任何转义字符,它就会出错,所以我认为双引号不会导致问题。

impala-shell -i impala-server.com -c -k -q "select 'Bob','Monkhouse','1928-06-01',2003,'An expert on the history of silent cinema and a film collector, Monkhouse presented Mad Movies in 1966. He wrote, produced, financed and syndicated the show worldwide. The show featured clips from comic silent films, many from his own private collection, some of which he had helped to recover and restore. This film collection was the cause of a court case at the Old Bailey in 1979. Having loaned Terry Wogan\'s son a film, Monkhouse was charged with attempting to defraud film distributors of royalties, but after two years the judge decided that there was no case to answer.[8] Many of the films in his collection were seized and not returned to Monkhouse.[9] In 2008, the British Film Institute was contacted by Monkhouse\'s daughter, Abigail, who asked if they would like to view the collection and provide some advice as to the best way of preserving it. Amongst the discoveries were many radio and TV shows long thought lost. Dick Fiddy, the archivist, said \"It\'s a huge, unwieldy collection which deals with a number of areas. It\'s not just film and TV. Initially, we found half a dozen TV shows that we knew to be missing.\" Amongst those shows rediscovered were many that feature Monkhouse himself, including The Flip Side, a 1966 play in which he starred as a television DJ with his own late night show, and the 1957/58 series of his comedy My Pal Bob including an episode in which he is suspected of an extramarital affair.[10] The archive consisted of 36,000 videotapes, going back to when Monkhouse first bought a home video recorder in 1966. His film archive began in the late 1950s. The entire Monkhouse film and television archive is now held by Kaleidoscope, including all the material previously held by the NFTVA. It was catalogued and restored to digital formats for a major event at Bafta on 24 October 2009. Chris Perry, of Kaleidoscope and Kaleidoscope Publishing, said: \"We are painstakingly transferring the important contents of the video tapes and restoring radio shows. There are many incredible finds, and the event [is] an exciting time for all concerned.\" In his final years, Monkhouse hosted a show on BBC Radio 2 called The Monkhouse Archive, in which he provided humorous links to clips of comedy acts spanning the previous 50 years.',1,2.5,'2016-06-21 14:41:25'"

【讨论】:

是的,因为下面的内容很开心:impala-shell -c -k -q "select *, '\"Mr\" Bob\'s workshop' AS testthing from database.table" -B -o "Test.txt" --output_delimiter='|' --print_header -i impala-server; 可能是原始字符串中的方括号或其他内容。我将不得不使用试错法,看看是什么导致了问题。【参考方案2】:

原来是\

你必须这样做,不是一次,不是两次,而是三次,如下所示:

impala-shell -c -k -q "INSERT INTO TABLE database.table
VALUES
('Bob','Monkhouse','1928-06-01',2003,'see if I can get \\\ to work...',1,2.5,'2016-06-21 14:41:25');" -i impala-server;

【讨论】:

以上是关于Impala Shell 查询 -q 在字符串中带有双引号的主要内容,如果未能解决你的问题,请参考以下文章

impala-shell 查询失败并出现错误 (13)

如何使用 unix shell 脚本将 impala 查询输出日志转换为变量?

OOzie Shell -Impala 操作 XML 错误

为 impala 查询打开屏幕

impala shell 命令中的 MEM_LIMIT

一旦我已经在 impala shell 中,如何运行 .sql 文件?