Search code examples
solrdataimporthandler

Solr DataImportHandler with optional sub-entities


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?


Solution

  • 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).