Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

sql - calling stored procedure from solr

I’m writing an application that searches by solr 3.4. To fill the index of solr I use the dataimporthandler and the com.microsoft.sqlserver.jdbc.SQLServerDriver class to get the data from the MS SQL database.

Now I’m trying to call a stored procedure on Database but solr log always return errors:

Full Import failed:org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: exec dbo.h_getThumbnails @h = '52'        Processing Document # 48
    at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:72)
    at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:253)
    at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSource.java:210)
    at org.apache.solr.handler.dataimport.JdbcDataSource.getData(JdbcDataSource.java:39)
    at org.apache.solr.handler.dataimport.SqlEntityProcessor.initQuery(SqlEntityProcessor.java:59)
    at org.apache.solr.handler.dataimport.CachedSqlEntityProcessor.getAllNonCachedRows(CachedSqlEntityProcessor.java:69)
    at org.apache.solr.handler.dataimport.EntityProcessorBase.getSimpleCacheData(EntityProcessorBase.java:259)
    at org.apache.solr.handler.dataimport.CachedSqlEntityProcessor.nextRow(CachedSqlEntityProcessor.java:58)
    at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:238)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:596)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:622)
    at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:268)
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:187)
    at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:359)
    at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:427)
    at org.apache.solr.handler.dataimport.DataImporter$1.run(DataImporter.java:408)
Caused by: java.lang.NullPointerException
    at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:251)
    ... 14 more

The I’ve tried diferent versions to call the stored procedure. Here the queries:

<entity  name="PicturePath" processor="CachedSqlEntityProcessor" query="exec dbo.h_getThumbnails @h = 4
">      </entity>

<entity  name="PicturePath" processor="CachedSqlEntityProcessor" query="call dbo.h_getThumbnails @h = 4
">      </entity>
<entity  name="PicturePath" processor="CachedSqlEntityProcessor" query=" dbo.h_getThumbnails @h = 4
">      </entity>

Does anyone know how to call a stored procedure from solr? Or does anyone know where I should search the cause?

Thanks a lot for all your answers!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For me it works like this:

<dataSource name="ds-1" type="JdbcDataSource" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://10.0.2.47;databaseName=dbname" user="username" password="password" 
    responseBuffering="adaptive" batchSize="0" autoCommit="false"   /> 
<entity name="item" dataSource="ds-1" query="[sp_StuffDataImportHandler]"></entity>

But this only works if the stored procedure contains a simple SELECT query.

If I declare some variables or temporrary tables before the query that will return the results then the import fails, giving me the same exception that you get.

LATER EDIT

I managed to make it work with more complex queries in the Stored Procedure. by adding SET NOCOUNT ON; at the beginning of the stored procedure.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...