Solr DataImportHandler CachedSqlEntityProcessor ClassCastException

时间:2014-02-04 09:52:25

标签: solr classcastexception dataimporthandler

我正在使用Solr 4.6.0并尝试使用CachedSqlEntityProcessor导入我的数据,但不知怎的,我最终获得了ClassCastException

模式

<fields>
   <field name="_version_" type="long" indexed="true" stored="true"/>
   <field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> 
   <field name="conference" type="string" indexed="true" stored="true" />
   <field name="year" type="int" indexed="true" stored="true" />
   <field name="doi" type="string" indexed="false" stored="true" />
   <field name="text" type="text_en_shingling" indexed="true" stored="true" />
 </fields>

数据配置

<dataConfig>
    <dataSource name="mysql" type="JdbcDataSource" 
        driver="com.mysql.jdbc.Driver" 
        url="..." 
        batchSize="-1" 
        user="..." password="..." />
    <document name="publications">
        <entity name="publication" query="
            SELECT
                sm_publications.id AS p_id,
                sm_publications.year AS p_year,
                sm_publications.doi AS p_doi,
                CONCAT(sm_publications.title, ' ', sm_publications.abstract) AS p_text,
                sm_publications.conference_id 
            FROM sm_publications 
            WHERE '${dataimporter.request.clean}' != 'false' OR 
                modified > '${dataimporter.last_index_time}'">
            <field column="p_id" name="id" />
            <field column="p_text" name="text" />
            <field column="p_year" name="year" />
            <field column="p_doi" name="doi" />

            <entity name="conference" query="SELECT id AS CID,full_name FROM sm_conferences"
                processor="CachedSqlEntityProcessor" cacheKey="CID" cacheLookup="publication.conference_id">
                <field column="full_name" name="conference" />
            </entity>

        </entity>
    </document>
</dataConfig>

错误消息

Full Import failed:java.lang.RuntimeException: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:270)
    at org.apache.solr.handler.dataimport.DataImporter.doFullImport(DataImporter.java:411)
    at org.apache.solr.handler.dataimport.DataImporter.runCmd(DataImporter.java:476)
    at org.apache.solr.handler.dataimport.DataImportHandler.handleRequestBody(DataImportHandler.java:179)
    at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:1859)
    at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:710)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:413)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:197)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1419)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:455)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:557)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1075)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:384)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1009)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:154)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
    at org.eclipse.jetty.server.Server.handle(Server.java:368)
    at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:489)
    at org.eclipse.jetty.server.BlockingHttpConnection.handleRequest(BlockingHttpConnection.java:53)
    at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:953)
    at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:1014)
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:861)
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:240)
    at org.eclipse.jetty.server.BlockingHttpConnection.handle(BlockingHttpConnection.java:72)
    at org.eclipse.jetty.server.bio.SocketConnector$ConnectorEndPoint.run(SocketConnector.java:264)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: org.apache.solr.handler.dataimport.DataImportHandlerException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:410)
    at org.apache.solr.handler.dataimport.DocBuilder.doFullDump(DocBuilder.java:323)
    at org.apache.solr.handler.dataimport.DocBuilder.execute(DocBuilder.java:231)
    ... 33 more
Caused by: org.apache.solr.handler.dataimport.DataImportHandlerException: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at org.apache.solr.handler.dataimport.DataImportHandlerException.wrapAndThrow(DataImportHandlerException.java:63)
    at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:246)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:469)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:495)
    at org.apache.solr.handler.dataimport.DocBuilder.buildDocument(DocBuilder.java:408)
    ... 35 more
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
    at java.lang.String.compareTo(Unknown Source)
    at java.util.TreeMap.getEntry(Unknown Source)
    at java.util.TreeMap.get(Unknown Source)
    at org.apache.solr.handler.dataimport.SortedMapBackedCache.iterator(SortedMapBackedCache.java:147)
    at org.apache.solr.handler.dataimport.DIHCacheSupport.getIdCacheData(DIHCacheSupport.java:179)
    at org.apache.solr.handler.dataimport.DIHCacheSupport.getCacheData(DIHCacheSupport.java:145)
    at org.apache.solr.handler.dataimport.EntityProcessorBase.getNext(EntityProcessorBase.java:129)
    at org.apache.solr.handler.dataimport.SqlEntityProcessor.nextRow(SqlEntityProcessor.java:75)
    at org.apache.solr.handler.dataimport.EntityProcessorWrapper.nextRow(EntityProcessorWrapper.java:243)
    ... 38 more

表格结构 enter image description here

6 个答案:

答案 0 :(得分:4)

CachedSqlEntityProcessor依赖于DIHCacheSupportMap<String,Object> getIdCacheData(...)),它不适合使用Integer类型的键,这是任何缓存的预期行为。 (Object key = context.resolve(cacheForeignKey);,此键实际上应为String类型)

SELECT CAST(id as CHAR(32)) AS CID,full_name FROM sm_conferences 

答案 1 :(得分:2)

这是一个案例问题。您需要以大写形式在cacheLookup属性中编写密钥。如果你使用

cacheLookup="publication.CONFERENCE_ID"

它会起作用。

您为实体publication收集的所有列都会在内部收集到地图中。该地图的关键字是大写的。在cacheLookup="publication.CONFERENCE_ID"写下等号publication.CONFERENCE_ID后的短片是该地图的捷径时。显然,String#toUpper之间某处缺少cacheLookup="publication.CONFERENCE_ID"


我已经添加了一个关于此的测试用例,看看at the DIHCachedTest,检查一下并让它运行。你需要maven这个。我创建了一个嵌入式HSQLDB,它模仿您的架构并运行一个具有2个数据导入配置的嵌入式Solr。

  • 的src /主/资源/ solr的/ DIH缓存/ CONF /数据配置-fault.xml
  • 的src /主/资源/ solr的/ DIH缓存/ CONF /数据-config.xml中

第一个用于测试用例DIHCachedTest#runImportWithFault。这将遇到您在问题中发布的相同错误。

第二个用于测试用例DIHCachedTest#runImport。这将成功。

如果比较两种配置,您将看到唯一的区别是 cacheLookup="publication.conference_id" vs {{1}}。


问题SOLR-2483 DIH - an uppercase problem in query parameters描述了这种错误模式。

答案 2 :(得分:2)

这是https://issues.apache.org/jira/browse/SOLR-2382中引入可插入缓存支持的回归,而变通方法(对我而言)是强制转换为将用作键或值的所有列中的字符串。在PostgreSQL演员语法中:

<entity name="par" dataSource="d" query="SELECT id, xyz, child_id::text FROM par;">
  <entity name="child" dataSource="d" query="SELECT id::text, abc FROM child;"
          processor="CachedSqlEntityProcessor"
          where="id=par.child_id"/>
</entity>

(在其他数据库中,我猜您需要CAST(id AS VARCHAR(10)或其他数据而不是id::text)。

答案 3 :(得分:1)

我不认为您的dataimporthandler配置有问题,我宁愿检查您的数据库类型是否与您销售的相应字段类型相匹配

像数据库类型那样导致java.lang.Integer被传递给基于java.lang.String的solr字段

OUPS,我可能弄错了,SOLR的uniqueKey字段仍然是“id”吗?你已经在你的架构中将这个字段设置为一个整数,这是一个坏主意。

http://wiki.apache.org/solr/SchemaXml#The_Unique_Key_Field

  

“请注意,如果您已启用QueryElevationComponent   solrconfig.xml它要求模式具有类型的uniqueKey   StrField。例如,它不能是一个int字段。“

答案 4 :(得分:0)

答案 5 :(得分:0)

Solr CachedSqlEntityProcessor在版本4.5附近折旧。新语法使用cacheImpl,cacheKey&amp; cacheLookup

我必须更新data-config.xml中的SQL

旧语法

processor="CachedSqlEntityProcessor"
where="fkId=parentTable.parentId"

新语法

cacheKey="fkId" cacheLookup="parenttable.parentId" cacheImpl="SortedMapBackedCache"

查看最新的Solr wiki信息,旧的DataImportHanlder页面已过期https://cwiki.apache.org/confluence/display/solr/Uploading+Structured+Data+Store+Data+with+the+Data+Import+Handler#UploadingStructuredDataStoreDatawiththeDataImportHandler-EntityProcessors