[ 
https://issues.apache.org/jira/browse/SOLR-1229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Lance Norskog updated SOLR-1229:
--------------------------------

    Attachment: SOLR-1229.patch

There are two bugs in this issue:

1) The deletedPkQuery must say "select field from table". It may not say 
"select expression" or "select field AS FIELD from table". The former does not 
work and the latter may work with some databases and not others.  In other 
words, the first example works and the others fail:

    deletedPkQuery="select id from item where EXPRESSION"
    deletedPkQuery="select concat('',id) from item where EXPRESSION"
    deletedPkQuery="select id from item AS ID where EXPRESSION"
    deletedPkQuery="select id from item AS ITEM.ID where EXPRESSION"

2) If a template is used to format the contents of the Solr primary key, that 
template is declared at the <field> level and is not visible in the parent 
<entity> level. Since the deletedPkQuery is declared in the <entity> level, it 
cannot see the field's template. Thus the template cannot be applied to the 
results of the deletedPkQuery. Any formatting in the <field> template must be 
duplicated (in SQL syntax) in the deletedPkQuery. 

This is workaround that achieves the goal of #2: if the Solr primary key is 
declared as

    <field name="id" template="prefix-${item.id}"

then the deletedPkQuery must be declared as

    deletedPkQuery="select concat('prefix',id) from item where EXPRESSION"

Because of bug #1, it is not possible to use this workaround.

The attached patch fixes bug #1, making it possible to use the workaround. It 
is Erik's second patch but only with the fix for bug #1. It does not create an 
automatic way for results of deletedPkQuery to be formatted with the primary 
key's template.



> deletedPkQuery feature does not work when pk and uniqueKey field do not have 
> the same value
> -------------------------------------------------------------------------------------------
>
>                 Key: SOLR-1229
>                 URL: https://issues.apache.org/jira/browse/SOLR-1229
>             Project: Solr
>          Issue Type: Bug
>          Components: contrib - DataImportHandler
>    Affects Versions: 1.4
>            Reporter: Erik Hatcher
>             Fix For: 1.4
>
>         Attachments: SOLR-1229.patch, SOLR-1229.patch, SOLR-1229.patch, 
> SOLR-1229.patch
>
>
> Problem doing a delta-import such that records marked as "deleted" in the 
> database are removed from Solr using deletedPkQuery.
> Here's a config I'm using against a mocked test database:
> <dataConfig>
>  <dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/db"/>
>  <document name="tests">
>    <entity name="test"
>            pk="board_id"
>            transformer="TemplateTransformer"
>            deletedPkQuery="select board_id from boards where deleted = 'Y'"
>            query="select * from boards where deleted = 'N'"
>            deltaImportQuery="select * from boards where deleted = 'N'"
>            deltaQuery="select * from boards where deleted = 'N'"
>            preImportDeleteQuery="datasource:board">
>      <field column="id" template="board-${test.board_id}"/>
>      <field column="datasource" template="board"/>
>      <field column="title" />
>    </entity>
>  </document>
> </dataConfig>
> Note that the uniqueKey in Solr is the "id" field.  And its value is a 
> template board-<PK>.
> I noticed the javadoc comments in DocBuilder#collectDelta it says "Note: In 
> our definition, unique key of Solr document is the primary key of the top 
> level entity".  This of course isn't really an appropriate assumption.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to