[英]Dynamic column names using DIH (DataImportHandler)
Is there a way to create dynamic column (as a key/value) names using the values returned from the query throw DIH (DataImportHandler)? 有没有办法使用从查询抛出DIH(DataImportHandler)返回的值创建动态列(作为键/值)名称?
For example: 例如:
<entity name="foo" dataSource="my_database" query="select key,value from foo where id=${item.id}">
<field column="${foo.key}" value="${foo.value}" name="${foo.key}_s"/>
</entity>
?? ??
Use ScriptTransformer - 使用ScriptTransformer -
Example - 示例 -
Data Config - Add custom field - 数据配置 - 添加自定义字段 -
<script><![CDATA[
function addfield(row){
var fieldName = row.get('key') + "_s"
row.put(fieldName, row.get('value'));
return row;
}
]]></script>
Entity mapping - 实体映射 -
<entity name="foo" dataSource="my_database" transformer="script:addfield" query="select key,value from foo where id=${item.id}">
......
</entity>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.