Question

I'm configuring DataImportHandler to index my db but I run into this problem.

I have a table A with a nullable integer field F that is the fk to another table (call it B). I was modeling this way:

...
<entity name="main" query="select ..., F from A">
  ...
  <entity name="sub" query="select ... form B where Id = ${main.F}">
    ...
  </entity>
<entity>
...

The problem is that when F is NULL i get a runtime error because ${main.F} get replaced with nothing and it try to execute the following query:

select ... from B where Id =

Is there a way to handle this situation?

Was it helpful?

Solution 3

Just for record this is the solution I'm using at the moment.

I changed the sub-entity definistion as:

<entity name="sub" query="select ... form B where Id = '${main.F}'">

This is not the best solution because F is a numeric field, not a string and surrounding it with ' may cause problems with some databases (performance problem in Oracle).

OTHER TIPS

is there a reason where you cannot use "WHERE F is NOT NULL",

alternatively you can replace F with some unused value using immedate if in sql.

using OnError =SKIP will be similar to "WHERE F is NOT NULL" , but usng IF in sql to replace with an unused value will ensure the main part is indexed only ignoring th esub part, if that is your requirement.

We use dataimport handler, but frankly haven't come across this scenario yet.
May be you want to try the onError attribute with the entity, which will allow you the skip or continue when an error occurs.

http://wiki.apache.org/solr/DataImportHandler#Configuration_in_data-config.xml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top