我有一个CSV文件,如:
FN | MI | LN | ADDR | CITY | ZIP | GENDER
------------------------------------------------------------------------------
Patricia | | Faddar | 7063 Carr xxx | Carolina | 00979-7033 | F
------------------------------------------------------------------------------
Lui | E | Baves | PO Box xxx | Boqueron | 00622-1240 | F
------------------------------------------------------------------------------
Janine | S | Perez | 25 Calle xxx | Salinas | 00751-3332 | F
------------------------------------------------------------------------------
Rose | | Mary | 229 Calle xxx | Aguadilla | 00603-5536 | F
我将它导入OrientDB,如:
{
"source": { "file": { "path": "/sample.csv" } },
"extractor": { "csv": {} },
"transformers": [
{ "vertex": { "class": "Users" } }
],
"loader": {
"orientdb": {
"dbURL": "plocal:/orientdb/databases/test",
"dbType": "graph",
"classes": [
{"name": "Users", "extends": "V"}
]
}
}
}
我想设置导入,以便它创建属性,以便FN
变为first_name
,MI
变为middle_name
等等,并设置一些值小写。例如:Carolina
成为carolina
添加数据后,我可能会从SCHEMA进行此更改。我这样做的原因是我有多个CSV文件,我想为所有
保持相同的模式有什么想法吗?
编辑: 解决方案基于Roberto Franchini的回答
{
"source": { "file": { "path": "/sample.csv" } },
"extractor": {
"csv": {
"columns": ["first_name:string", "middle_name:string", "last_name:string", "address:string", "city:string", "zip:string", "zip_four:string", "gender:string"]
}
},
"transformers": [
{
"vertex": { "class": "User" }
},
{
"field": { "fieldName": "first_name", "expression": "$input.first_name.toLowerCase()" }
},
{
"field": { "fieldName": "address", "expression": "$input.address.toLowerCase()" }
},
{
"field": { "fieldName": "gender", "expression": "if(($input.gender === 'F'), 'female', 'male')" }
}
],
"loader": {
"orientdb": {
"dbURL": "plocal:/orientdb/databases/test",
"dbType": "graph",
"classes": [
{ "name": "User", "extends": "V" }
]
}
}
}
答案 0 :(得分:0)
要重命名字段,请查看Field变换器:
http://orientdb.com/docs/last/Transformer.html#field-transformer
将字段从salary重命名为renumeration:
{ "field":
{ "fieldName": "remuneration",
"expression": "salary"
}
},
{ "field":
{ "fieldName": "salary",
"operation": "remove"
}
}
以同样的方式,您可以将lowerCase函数应用于属性
{field: {fieldName:'name', expression: '$input.name.toLowerCase()'}}
尝试一下,让我知道它是否有效。