You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Bertie Shen <be...@gmail.com> on 2009/11/01 19:29:59 UTC

Question about DIH execution order

Hi folks,

  I have the following data-config.xml. Is there a way to
let transformation take place after executing SQL "select comment from
Rating where Rating.CourseId = ${Course.CourseId}"?  In MySQL database,
column CourseId in table Course is integer 1, 2, etc;
template transformation will make them like Course:1, Course:2; column
CourseId in table Rating is also integer 1, 2, etc.

  If transformation happens before executing "select comment from Rating
where Rating.CourseId = ${Course.CourseId}", then there will no match for
the SQL statement execution.

 <document>
     <entity name="Course" transformer="TemplateTransformer" query="select *
from Course">
      <field
column="CourseId" template="Course:${Course.CourseId}" name="id"/>
      <entity name="Rating" query="select comment from Rating where
Rating.CourseId = ${Course.CourseId}">
        <field column="comment" name="review"/>
      </entity>
    </entity>
  </document>

Re: Question about DIH execution order

Posted by Bertie Shen <be...@gmail.com>.
Hi Fergus,

   "select * from Course" returns all columns in table Course, one of which
is CourseId.

   Thanks for Noble's private reply. His trick works.

  For the record, his solution is to replace the line
      <field column="TmpCourseId"
name="CourseId" template="Course:${Course.CourseId}" name="id"/>
by
      <"field column="TmpCourseId" template="Course:${Course.CourseId}"
name="id"/>"

   I guess DIH works as the following order.
   1) First SQL statement executes, returns CourseId, e.g., value of
CourseId is 1.
   2) Have a temporary column TmpCourseId, value of which is still 1.
   3) Make template transformation for column TmpCourseId, the value becomes
Course:1, while the original CourseId column is still 1.
   4) SQL statement of joining Rating and Course is executed. CourseId is
still 1, which is what I want.


Cheers.




On Mon, Nov 2, 2009 at 2:43 PM, Fergus McMenemie <fe...@twig.me.uk> wrote:

> Bertie,
>
> Not sure what you are trying to do, we need a clearer description of
> what "select *" returns and what you want to end up in the index. But
> to answer your question The transformations happen after DIH has
> performed the SQL statement. In fact the rows output from the SQL
> command are assigned to the DIH fields and then any transformations
> are applied. The examples in
>        http://wiki.apache.org/solr/DataImportHandler
> are quite good.
>
> >Hi Noble,
> >
> >   I tried to understand your suggestions and played different variations
> >according to your reply.  But none of them work. Can you explain it in
>  more
> >details?
> >   Thanks a lot!
> >
> >
> >
> >
> >BTW, do you mean your solution as follows?
> >
> ><document>
> >   <entity name="Course" transformer=" TemplateTransformer" query="select
> *
> >from Course">
> >       <field column="TmpCourseId" name="CourseId"
> >template="Course:${Course.CourseId}" name="id"/>
> >         <entity name="Rating" query="select comment from Rating where
> >Rating.CourseId = ${Course.CourseId}">
> >           <field column="comment" name="review"/>
> >         </entity>
> >  </entity>
> > </document>
> >
> > But
> >   1) There is no TmpCourseId field column.
> >   2) Can we put two name CourseId and id in the same map? It seems not.
> >
> >
> >
> >
> >
> >2009/11/1 Noble Paul ??????  Â Ë³Ë <no...@corp.aol.com>
> >
> >> On Sun, Nov 1, 2009 at 11:59 PM, Bertie Shen <be...@gmail.com>
> >> wrote:
> >> > Hi folks,
> >> >
> >> >  I have the following data-config.xml. Is there a way to
> >> > let transformation take place after executing SQL "select comment from
> >> > Rating where Rating.CourseId = ${Course.CourseId}"?  In MySQL
> database,
> >> > column CourseId in table Course is integer 1, 2, etc;
> >> > template transformation will make them like Course:1, Course:2; column
> >> > CourseId in table Rating is also integer 1, 2, etc.
> >> >
> >> >  If transformation happens before executing "select comment from
> Rating
> >> > where Rating.CourseId = ${Course.CourseId}", then there will no match
> for
> >> > the SQL statement execution.
> >> >
> >> >  <document>
> >> >     <entity name="Course" transformer="TemplateTransformer"
> query="select
> >> *
> >> > from Course">
> >> >      <field
> >> > column="CourseId" template="Course:${Course.CourseId}" name="id"/>
> >> >      <entity name="Rating" query="select comment from Rating where
> >> > Rating.CourseId = ${Course.CourseId}">
> >> >        <field column="comment" name="review"/>
> >> >      </entity>
> >> >    </entity>
> >> >  </document>
> >> >
> >>
> >> keep the field as follows
> >>  <field
> >> column="TmpCourseId" name="CourseId"
> >> template="Course:${Course.CourseId}" name="id"/>
> >>
> >>
> >>
> >>
> >> --
> >> -----------------------------------------------------
> >> Noble Paul | Principal Engineer| AOL | http://aol.com
> >>
>
> --
>
> ===============================================================
> Fergus McMenemie               Email:fergus@twig.me.uk<Em...@twig.me.uk>
> Techmore Ltd                   Phone:(UK) 07721 376021
>
> Unix/Mac/Intranets             Analyst Programmer
> ===============================================================
>

Re: Question about DIH execution order

Posted by Fergus McMenemie <fe...@twig.me.uk>.
Bertie,

Not sure what you are trying to do, we need a clearer description of
what "select *" returns and what you want to end up in the index. But 
to answer your question The transformations happen after DIH has
performed the SQL statement. In fact the rows output from the SQL
command are assigned to the DIH fields and then any transformations
are applied. The examples in 
	http://wiki.apache.org/solr/DataImportHandler
are quite good.  

>Hi Noble,
>
>   I tried to understand your suggestions and played different variations
>according to your reply.  But none of them work. Can you explain it in  more
>details?
>   Thanks a lot!
>
>
>
>
>BTW, do you mean your solution as follows?
>
><document>
>   <entity name="Course" transformer=" TemplateTransformer" query="select *
>from Course">
>       <field column="TmpCourseId" name="CourseId"
>template="Course:${Course.CourseId}" name="id"/>
>         <entity name="Rating" query="select comment from Rating where
>Rating.CourseId = ${Course.CourseId}">
>           <field column="comment" name="review"/>
>         </entity>
>  </entity>
> </document>
>
> But
>   1) There is no TmpCourseId field column.
>   2) Can we put two name CourseId and id in the same map? It seems not.
>
>
>
>
>
>2009/11/1 Noble Paul ?????? Â Ë³Ë <no...@corp.aol.com>
>
>> On Sun, Nov 1, 2009 at 11:59 PM, Bertie Shen <be...@gmail.com>
>> wrote:
>> > Hi folks,
>> >
>> >  I have the following data-config.xml. Is there a way to
>> > let transformation take place after executing SQL "select comment from
>> > Rating where Rating.CourseId = ${Course.CourseId}"?  In MySQL database,
>> > column CourseId in table Course is integer 1, 2, etc;
>> > template transformation will make them like Course:1, Course:2; column
>> > CourseId in table Rating is also integer 1, 2, etc.
>> >
>> >  If transformation happens before executing "select comment from Rating
>> > where Rating.CourseId = ${Course.CourseId}", then there will no match for
>> > the SQL statement execution.
>> >
>> >  <document>
>> >     <entity name="Course" transformer="TemplateTransformer" query="select
>> *
>> > from Course">
>> >      <field
>> > column="CourseId" template="Course:${Course.CourseId}" name="id"/>
>> >      <entity name="Rating" query="select comment from Rating where
>> > Rating.CourseId = ${Course.CourseId}">
>> >        <field column="comment" name="review"/>
>> >      </entity>
>> >    </entity>
>> >  </document>
>> >
>>
>> keep the field as follows
>>  <field
>> column="TmpCourseId" name="CourseId"
>> template="Course:${Course.CourseId}" name="id"/>
>>
>>
>>
>>
>> --
>> -----------------------------------------------------
>> Noble Paul | Principal Engineer| AOL | http://aol.com
>>

-- 

===============================================================
Fergus McMenemie               Email:fergus@twig.me.uk
Techmore Ltd                   Phone:(UK) 07721 376021

Unix/Mac/Intranets             Analyst Programmer
===============================================================

Re: Question about DIH execution order

Posted by Bertie Shen <be...@gmail.com>.
Hi Noble,

   I tried to understand your suggestions and played different variations
according to your reply.  But none of them work. Can you explain it in  more
details?
   Thanks a lot!




BTW, do you mean your solution as follows?

<document>
   <entity name="Course" transformer=" TemplateTransformer" query="select *
from Course">
       <field column="TmpCourseId" name="CourseId"
template="Course:${Course.CourseId}" name="id"/>
         <entity name="Rating" query="select comment from Rating where
Rating.CourseId = ${Course.CourseId}">
           <field column="comment" name="review"/>
         </entity>
  </entity>
 </document>

 But
   1) There is no TmpCourseId field column.
   2) Can we put two name CourseId and id in the same map? It seems not.





2009/11/1 Noble Paul നോബിള്‍ नोब्ळ् <no...@corp.aol.com>

> On Sun, Nov 1, 2009 at 11:59 PM, Bertie Shen <be...@gmail.com>
> wrote:
> > Hi folks,
> >
> >  I have the following data-config.xml. Is there a way to
> > let transformation take place after executing SQL "select comment from
> > Rating where Rating.CourseId = ${Course.CourseId}"?  In MySQL database,
> > column CourseId in table Course is integer 1, 2, etc;
> > template transformation will make them like Course:1, Course:2; column
> > CourseId in table Rating is also integer 1, 2, etc.
> >
> >  If transformation happens before executing "select comment from Rating
> > where Rating.CourseId = ${Course.CourseId}", then there will no match for
> > the SQL statement execution.
> >
> >  <document>
> >     <entity name="Course" transformer="TemplateTransformer" query="select
> *
> > from Course">
> >      <field
> > column="CourseId" template="Course:${Course.CourseId}" name="id"/>
> >      <entity name="Rating" query="select comment from Rating where
> > Rating.CourseId = ${Course.CourseId}">
> >        <field column="comment" name="review"/>
> >      </entity>
> >    </entity>
> >  </document>
> >
>
> keep the field as follows
>  <field
> column="TmpCourseId" name="CourseId"
> template="Course:${Course.CourseId}" name="id"/>
>
>
>
>
> --
> -----------------------------------------------------
> Noble Paul | Principal Engineer| AOL | http://aol.com
>

Re: Question about DIH execution order

Posted by Noble Paul നോബിള്‍ नोब्ळ् <no...@corp.aol.com>.
On Sun, Nov 1, 2009 at 11:59 PM, Bertie Shen <be...@gmail.com> wrote:
> Hi folks,
>
>  I have the following data-config.xml. Is there a way to
> let transformation take place after executing SQL "select comment from
> Rating where Rating.CourseId = ${Course.CourseId}"?  In MySQL database,
> column CourseId in table Course is integer 1, 2, etc;
> template transformation will make them like Course:1, Course:2; column
> CourseId in table Rating is also integer 1, 2, etc.
>
>  If transformation happens before executing "select comment from Rating
> where Rating.CourseId = ${Course.CourseId}", then there will no match for
> the SQL statement execution.
>
>  <document>
>     <entity name="Course" transformer="TemplateTransformer" query="select *
> from Course">
>      <field
> column="CourseId" template="Course:${Course.CourseId}" name="id"/>
>      <entity name="Rating" query="select comment from Rating where
> Rating.CourseId = ${Course.CourseId}">
>        <field column="comment" name="review"/>
>      </entity>
>    </entity>
>  </document>
>

keep the field as follows
  <field
column="TmpCourseId" name="CourseId"
template="Course:${Course.CourseId}" name="id"/>




-- 
-----------------------------------------------------
Noble Paul | Principal Engineer| AOL | http://aol.com