Skip to content
Advertisement

How to setup properties on CSV import in OrientDB?

I have a CSV file like:

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

And I am importing it into OrientDB like:

{
  "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"}
       ]
    }
  }
}

I would like to set the import so that it created properties so that FN becomes first_name, MI becomes middle_name and so on, as well as set some values to lowercase. For ex: Carolina to become carolina

I could probably make this changes from the SCHEMA once the data is added. My reason to do this here is that I have multiple CSV files and I want to keep the the same schema for all

Any ideas?

Advertisement

Answer

To rename a field, take a look at the Field transformer:

http://orientdb.com/docs/last/Transformer.html#field-transformer

Rename the field from salary to renumeration:

  { "field": 
    { "fieldName": "remuneration", 
      "expression": "salary"
    } 
  },
  { "field": 
    { "fieldName": "salary", 
      "operation": "remove"
    } 
  }

in the same way, you can apply the lowerCase function to the property

{field: {fieldName:'name', expression: '$input.name.toLowerCase()'}}

Try it and let me know if it works.

Advertisement