Solv date variable resolver does not work with MySql

I used the Solr 3.3 version as a Data Import Handler (DIH) with Oracle . His work is wonderful for me.

Now I am trying to do the same with Mysql . With the database change, I changed the query used in data-config.xml for MySql .

There are variables in the request that are passed to http. The same thing works fine in Oracle with variable resolution, but not in MySql .

Request:

SELECT DISTINCT doc.document_id , doc.first_version_id, doc.acl_id, fol.folder_id FROM ds_document_c doc, ds_folder fol WHERE doc.cabinet_id = ${dataimporter.request.cabinetId} AND fol.folder_id = doc.document_folder_id AND doc.index_state_modification_date >= to_date('${dataimporter.request.lastIndexDate}', 'DD/MM/YYYY HH24:MI:SS') 

and Url:

 localhost:8983/solr/dataimport?command=full-import&clean=true&commit=true&cabinetId=17083360&lastIndexDate='24/05/2015 00:00:00' 

Solr builds the query as shown below:

 SELECT DISTINCT doc.document_id , doc.first_version_id, doc.acl_id, fol.folder_id FROM ds_document_c doc, ds_folder fol WHERE doc.cabinet_id = 24 AND fol.folder_id = doc.document_folder_id AND doc.index_state_modification_date >= to_date('[?, '28/05/2015 11:13:50']', 'DD/MM/YYYY HH24:MI:SS') 

I cannot understand why our date variable is not corrected properly in this case.

Due to_date('[?, '28/05/2015 11:13:50']' there is no correct MySql syntax, I get a MySql syntax error.

I get the following error

 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[?, '28/05/2015 11:13:50'], 'DD/MM/YYYY HH24:MI:SS')))' at line 1 

Does anyone know where the problem is? Why is the resolver variable not working properly?

Note: to_date is a function that we wrote in MySql.

+5
source share
1 answer

I checked the source code for solr and tried to solve my problem.

I had a fix for it, and it worked for me.

Resolving a variable in the case of a date somehow creates an array and so it adds

 '[?, '28/05/2015 11:13:50']'. 

In TemplateString.java in the fillTokens (VariableResolver resolver) method, I added code that removes the extra part added to the date.

 if (i < s.length) { if(s[i].startsWith("[")){ String temp = s[i].replace("[?,", ""); temp = temp.replace("]", ""); sb.append(temp); }else{ sb.append(s[i]); } } 

With this change, the resolver variable adds the date as "05/28/2015 11:13:50" and removes my MySql syntax error.

(Note. I did not have much time to analyze why the date variable is resolved as an array. I made a temporary fix and solved my problem.)

+2
source

All Articles