title: Splitting database column into multivalued Solr field
body: <p>I'm going nuts trying to figure out how to get the Data Import Handler's <code>splitBy</code> construct to work. I was expecting it to split the input column into a multivalued field. Here's a test case to reproduce the problem:</p>
  
  <pre class="lang-java prettyprint-override"><code>import java.io.File;
  import java.io.IOException;
  import java.sql.SQLException;
  
  import static org.junit.Assert.*;
  
  import javax.sql.DataSource;
  
  import org.apache.commons.dbutils.QueryRunner;
  import org.apache.commons.io.FileUtils;
  import org.apache.solr.client.solrj.SolrQuery;
  import org.apache.solr.client.solrj.SolrServer;
  import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
  import org.apache.solr.client.solrj.response.QueryResponse;
  import org.apache.solr.common.SolrDocument;
  import org.apache.solr.core.CoreContainer;
  import org.hsqldb.jdbc.JDBCDataSource;
  import org.junit.After;
  import org.junit.Before;
  import org.junit.Test;
  
  public class TestSplitBy {
  
    SolrServer server;
    File configPath = new File(FileUtils.getTempDirectory(), Long.toString(System.nanoTime()));
  
    String solrconfig_xml = "&lt;config&gt;&lt;luceneMatchVersion&gt;LUCENE_41&lt;/luceneMatchVersion&gt;&lt;requestHandler name=\"search\" class=\"solr.SearchHandler\" default=\"true\"&gt;&lt;lst name=\"defaults\"&gt;&lt;str name=\"fl\"&gt;*&lt;/str&gt;&lt;str name=\"df\"&gt;id&lt;/str&gt;&lt;/lst&gt;&lt;/requestHandler&gt;&lt;requestHandler name=\"/dataimport\" class=\"org.apache.solr.handler.dataimport.DataImportHandler\"&gt;&lt;lst name=\"defaults\"&gt;&lt;str name=\"config\"&gt;data-config.xml&lt;/str&gt;&lt;/lst&gt;&lt;/requestHandler&gt;&lt;/config&gt;";
  
    String data_config_xml = "&lt;dataConfig&gt;" +
        "&lt;dataSource url=\"jdbc:hsqldb:mem:testdb\" user=\"SA\" driver=\"org.hsqldb.jdbc.JDBCDriver\" /&gt;" +
        "&lt;document&gt;" +
        "&lt;entity name=\"item\" transformer=\"RegexTransformer\" query=\"SELECT * FROM test\"&gt;" +
        "&lt;field column=\"type\" name=\"type\" splitBy=\",\" /&gt;" +
        "&lt;/entity&gt;" +
        "&lt;/document&gt;" +
        "&lt;/dataConfig&gt;";
  
    String schema_xml = "&lt;schema version=\"1.3\" name=\"test\"&gt;" +
        "&lt;types&gt;" +
        "&lt;fieldType name=\"string\" class=\"solr.StrField\" sortMissingLast=\"true\" omitNorms=\"true\" /&gt;" +
        "&lt;/types&gt;" +
        "&lt;fields&gt;" +
        "&lt;field stored=\"true\" name=\"id\" type=\"string\" /&gt;" +
        "&lt;field stored=\"true\" name=\"type\" type=\"string\" multiValued=\"true\"/&gt;" +
        "&lt;/fields&gt;" +
        "&lt;uniqueKey&gt;id&lt;/uniqueKey&gt;" +
        "&lt;/schema&gt;";
  
    DataSource getDataSource() {
      JDBCDataSource ds = new JDBCDataSource();
      ds.setUser("SA");
      ds.setUrl("mem:testdb");
      return ds;
    }
  
    void populateDb(DataSource ds) {
      QueryRunner runner = new QueryRunner(ds);
      try {
        runner.update("DROP TABLE test IF EXISTS");
        runner.update("CREATE TABLE test(id INTEGER, type VARCHAR(256));");
        runner.update("INSERT INTO test VALUES 1, 'foo,bar,baz'");
      } catch (SQLException e) {
        System.err.println(e);
      }
    }
  
    void writeSolrConfig() throws IOException {
      File corePath = new File(configPath, "collection1");
      corePath.mkdir();
      File confPath = new File(corePath, "conf");
      confPath.mkdir();
      FileUtils.write(new File(confPath, "data-config.xml"), data_config_xml);
      FileUtils.write(new File(confPath, "schema.xml"), schema_xml);
      FileUtils.write(new File(confPath, "solrconfig.xml"), solrconfig_xml);
    }
  
    void startSolr() {
      System.setProperty("solr.solr.home", configPath.getAbsolutePath());
      CoreContainer.Initializer initializer = new CoreContainer.Initializer();
      CoreContainer coreContainer = initializer.initialize();
      server = new EmbeddedSolrServer(coreContainer, "collection1");
    }
  
    @Before
    public void setup() throws IOException {
      populateDb(getDataSource());
      writeSolrConfig();
      startSolr();
    }
  
    @After
    public void tearDown() {
      server.shutdown();
      FileUtils.deleteQuietly(configPath);
    }
  
    @Test
    public void testSplitBy() throws Exception {
      SolrQuery query = new SolrQuery();
      query.set("qt", "/dataimport");
      query.setParam("command", "full-import");
      QueryResponse response = server.query(query);
      Thread.sleep(500);
  
      response = server.query(new SolrQuery("*:*"));
      for (SolrDocument doc: response.getResults()) {
        assertNotNull(doc.getFieldValues("type"));
        assertEquals(3, doc.getFieldValues("type").size());
      }
    }
  }
  </code></pre>
  
  <p>And the POM for the test case:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;org.example&lt;/groupId&gt;
    &lt;artifactId&gt;solr&lt;/artifactId&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;Solr Sanity&lt;/name&gt;
  
    &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;2.3.2&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.6&lt;/source&gt;
            &lt;target&gt;1.6&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;/plugins&gt;
    &lt;/build&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.apache.solr&lt;/groupId&gt;
        &lt;artifactId&gt;solr&lt;/artifactId&gt;
        &lt;version&gt;4.1.0&lt;/version&gt;
        &lt;type&gt;war&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.apache.solr&lt;/groupId&gt;
        &lt;artifactId&gt;solr-dataimporthandler&lt;/artifactId&gt;
        &lt;version&gt;4.1.0&lt;/version&gt;
        &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.apache.solr&lt;/groupId&gt;
        &lt;artifactId&gt;solr-solrj&lt;/artifactId&gt;
        &lt;version&gt;4.1.0&lt;/version&gt;
        &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;commons-dbutils&lt;/groupId&gt;
        &lt;artifactId&gt;commons-dbutils&lt;/artifactId&gt;
        &lt;version&gt;1.5&lt;/version&gt;
        &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.hsqldb&lt;/groupId&gt;
        &lt;artifactId&gt;hsqldb&lt;/artifactId&gt;
        &lt;version&gt;2.2.9&lt;/version&gt;
        &lt;type&gt;jar&lt;/type&gt;
        &lt;scope&gt;runtime&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.11&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
        &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
        &lt;version&gt;2.5&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Any insight on how to get those types to split correctly into multiple values?</p>