Created
October 31, 2012 20:32
-
-
Save lancepantz/3989651 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.geni.solr; | |
import java.sql.SQLException; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.HashMap; | |
import java.util.Iterator; | |
import org.apache.solr.handler.dataimport.Context; | |
import org.apache.solr.handler.dataimport.DataImporter; | |
import org.apache.solr.handler.dataimport.DataSource; | |
import com.geni.solr.TemplatedTransformer; | |
public class CoalesceTransformer extends TemplatedTransformer { | |
public Map<String,Object> transformRow(Map<String, Object> row, Context context) { | |
List<Map<String,String>> fields = context.getAllEntityFields(); | |
for (Map<String,String> field : fields) { | |
String coalesceTo = field.get("coalesce"); | |
if (coalesceTo != null) { | |
String columnName = field.get(DataImporter.COLUMN); | |
String value = (String) row.get(columnName); | |
if (value == null) { | |
List<String> variables = getVars(coalesceTo); | |
if (variables.size() != 1) | |
throw new RuntimeException("coalesce value contains more than one templated variable"); | |
String newValue = (String) context.resolve(variables.get(0)); | |
if (newValue == null) | |
throw new RuntimeException("coalesce templated value unresolvable"); | |
row.put(columnName, newValue); | |
} | |
} | |
} | |
return row; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<field name="parent_id" | |
coalesce="${document.id}" | |
column="parent_id"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment