简体   繁体   English

Solr数据导入和带有xml转义的SQL

[英]Solr dataimport and SQL with xml escape

I tried the following SQL in entity tag of dataimport config file: 我在dataimport配置文件的实体标签中尝试了以下SQL:

<entity name="Page" dataSource="a1" query="SELECT &amp;apos;26484-&amp;apos;&amp;amp;`book`.id&amp;amp;&amp;apos;-&amp;apos;&amp;amp;`book`.page&amp;amp;&amp;apos;-&amp;apos;&amp;amp;`book`.part AS PageID, `book`.id AS pid, `book`.nass AS Content, `book`.part AS Part, `book`.page AS PageNum FROM `book` ORDER BY `book`.id, `book`.page">

The Sql query contains characters should be escaped in xml, ' and & . Sql查询包含的字符应以xml, ' and &进行转义。 However, I recive the following error in the log: 但是,我在日志中看到以下错误:

 DocBuilder     Exception while processing: Page document : SolrInputDocument(fields: []):org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: SELECT '26484-'&`book`.id&'-'&`book`.page&'-'&`book`.part AS PageID,​ `book`.id AS pid,​ `book`.nass AS Content,​ `book`.part AS Part,​ `book`.page AS PageNum FROM `book` ORDER BY `book`.id,​ `book`.page Processing Document # 1 

and

DataImporter    Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: SELECT '26484-'&`book`.id&'-'&`book`.page&'-'&`book`.part AS PageID,​ `book`.id AS pid,​ `book`.nass AS Content,​ `book`.part AS Part,​ `book`.page AS PageNum FROM `book` ORDER BY `book`.id,​ `book`.page Processing Document # 1 

I use jdbc driver. 我使用 jdbc驱动程序。

When I tried to remove concatination from the SQL query so, removing the escaped characters, I have not got this error, but I have got solrWriter warning about duplicate Unique key. 当我尝试从SQL查询中删除隐藏条件,从而删除转义字符时,我没有收到此错误,但是我收到了关于重复的唯一键的solrWriter警告。 and I understand this warning. 而且我明白这个警告。 However, How could I able to write use the Sql query shown above? 但是,如何编写上面显示的Sql查询呢?

  1. There is no need to escape single quotes, you can put ' directly into the query. 无需转义单引号,您可以将'直接放入查询中。

  2. A & is required for every escaped character. 每个转义字符都必须使用& So you will need to replace &amp;apos; 因此,您将需要替换&amp;apos; with &amp;&apos; &amp;&apos; .

The fact that corrupts your query should be (2). 破坏查询的事实应该是(2)。

<entity name="Page" dataSource="a1" query="SELECT &amp;'26484-&amp;'&amp;&amp;`book`.id&amp;&amp;&amp;'-&amp;'&amp;&amp;`book`.page&amp;&amp;&amp;'-&amp;'&amp;&amp;`book`.part AS PageID, `book`.id AS pid, `book`.nass AS Content, `book`.part AS Part, `book`.page AS PageNum FROM `book` ORDER BY `book`.id, `book`.page">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM