ETL - Extractors

When OrientDB executes the ETL module, extractor components handle data extraction from source. They are the first part of the ETL process. The ETL module in OrientDB supports the following extractors:

Row Extractor

When the ETL module runs with a Row Extractor, it extracts content row by row. It outputs a string array class.

  • Compnent name: row
  • Output Class: [ string ]

Syntax

Parameter Description Type Mandatory Default value
"multiLine" Defines whether the process supports multiline. Useful with CSV’s supporting linefeed inside of string. boolean true
"linefeed" Defines the linefeed to use in the event of multiline processing. string \r\n

The "multiLine" and "linefeed" parameters were introduced in version 2.0.9.

Examples

  • Use the row extractor with its default configuration:

    1. {
    2. "row": {}
    3. }

CSV Extractor

When the ETL module runs the CSV Extractor, it parses a file formated to Apache Commons CSV and extracts the data into OrientDB. This component was introduced in version 2.1.4 and is unavailable in older releases of OrientDB.

  • Component name: csv
  • Output class: [ ODocument ]

Syntax

Parameter Description Type Mandatory Default value
"separator" Defines the column separator. char ,
"columnsOnFirstLine" Defines whether the first line contains column descriptors. boolean true
"columns" Defines array for names and (optionally) types to write. string array
"nullValue" Defines the null value in the file. string NULL
"dateFormat" Defines the format to use in parsing dates from file. string yyyy-mm-dd
"quote" Defines string character delimiter. char "
"skipFrom" Defines the line number you want to skip from. integer
"skipTo" Defines the line number you want to skip to. integer
"ignoreEmptyLines" Defines whether it should ignore empty lines. boolean false
"predefinedFormat" Defines the CSV format you want to use. string
  • For the "columns" parameter, specify the type by postfixing it to the value. Specifying types guarantees better performance.

  • For the "predefinedFormat" parameter, the available formats are: DEFAULT, EXCEL, MYSQL, RFC4180, TDF.

Examples

  • Extract lines from CSV to the ODocument class, using commas as the separator, considering NULL as the null value and skipping rows two through four:

    1. { "csv":
    2. { "separator": ",",
    3. "nullValue": "NULL",
    4. "skipFrom": 1,
    5. "skipTo": 3
    6. }
    7. }
  • Extract lines from a CSV exported from MySQL:

    1. { "csv":
    2. { "predefinedFormat": "MYSQL"}
    3. }
  • Extract lines from a CSV with the default formatting, using N/A as the null value and a custom date format:

    1. { "csv":
    2. { "predefinedFormat": "DEFAULT",
    3. "nullValue" : "N/A",
    4. "dateFormat" : "dd-mm-yyyy HH:MM"
    5. }
    6. }

JDBC Extractor

When the ETL module runs the JDBC Extractor, it can access any database management system that supports the JDBC driver.

In order for the ETL component to connect to the source database, put the source database’s JDBC driver in the classpath, or in the $ORIENTDB_HOME/lib directory.

  • Component name: jdbc
  • Output class: [ ODocument ]

Syntax

Parameter Description Type Mandatory Default value
"driver" Defines the JDBC Driver class. string yes
"url" Defines the JDBC URL to connect to. string yes
"userName" Defines the username to use on the source database. string yes
"userPassword" Defines the user password to use on the source database. string yes
"query" Defines the query to extract the record you want to import. string yes
"queryCount" Defines query that returns the count of the fetched records, (used to provide a correct progress indicator). string

Example

  • Extract the contents of the client table on the MySQL database test at localhost:

    1. { "jdbc": {
    2. "driver": "com.mysql.jdbc.Driver",
    3. "url": "jdbc:mysql://localhost/test",
    4. "userName": "root",
    5. "userPassword": "my_mysql_passwd",
    6. "query": "SELECT * FROM client"
    7. }
    8. }

JSON Extractor

When the ETL module runs with a JSON Extractor, it extracts data by parsing JSON objects. If the data has more than one JSON items, you must enclose the in [] brackets.

  • Component name: json
  • Output class: [ ODocument ]

Example

  • Extract data from a JSON file.

    1. { "json": {} }

XML Extractor

When the ETL module runs with the XML extractor, it extracts data by parsing XML elements. This feature was introduced in version 2.2.

  • Component name: xml
  • Output class: [ ODocument ]

Syntax

Parameter Description Type Mandatory Default value
"rootNode" Defines the root node to extract in the XML. By default, it builds from the root element in the file. string
"tagsAsAttribute" Defines an array of elements, where child elements are considered as attributes of the document and the attribute values as the text within the element. string array

Examples

  • Extract data from an XML file, where the XML file reads as:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <a>
    3. <b>
    4. <c name='Ferrari' color='red'>ignore</c>
    5. <c name='Maserati' color='black'/>
    6. </b>
    7. </a>

    While the OrientDB-ETL configuration file reads as:

    1. { "source":
    2. { "file":
    3. { "path": "src/test/resources/simple.xml" }
    4. },
    5. "extractor" :
    6. { "xml": {} },
    7. "loader":
    8. { "test": {} }
    9. }

    This extracts the data as:

    1. {
    2. "a": {
    3. "b": {
    4. "c": [
    5. {
    6. "color": "red",
    7. "name": "Ferrari"
    8. },
    9. {
    10. "color": "black",
    11. "name": "Maserati"
    12. }
    13. ]
    14. }
    15. }
    16. }
  • Extract a collection from XML, where the XML file reads as:

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <CATALOG>
    3. <CD>
    4. <TITLE>Empire Burlesque</TITLE>
    5. <ARTIST>Bob Dylan</ARTIST>
    6. <COUNTRY>USA</COUNTRY>
    7. <COMPANY>Columbia</COMPANY>
    8. <PRICE>10.90</PRICE>
    9. <YEAR>1985</YEAR>
    10. </CD>
    11. <CD>
    12. <TITLE>Hide your heart</TITLE>
    13. <ARTIST>Bonnie Tyler</ARTIST>
    14. <COUNTRY>UK</COUNTRY>
    15. <COMPANY>CBS Records</COMPANY>
    16. <PRICE>9.90</PRICE>
    17. <YEAR>1988</YEAR>
    18. </CD>
    19. <CD>
    20. <TITLE>Greatest Hits</TITLE>
    21. <ARTIST>Dolly Parton</ARTIST>
    22. <COUNTRY>USA</COUNTRY>
    23. <COMPANY>RCA</COMPANY>
    24. <PRICE>9.90</PRICE>
    25. <YEAR>1982</YEAR>
    26. </CD>
    27. </CATALOG>

    While the OrientDB-ETL configuration file reads:

    1. { "source":
    2. { "file":
    3. { "path": "src/test/resources/music.xml" }
    4. }, "extractor" :
    5. { "xml":
    6. { "rootNode": "CATALOG.CD",
    7. "tagsAsAttribute": ["CATALOG.CD"]
    8. }
    9. },
    10. "loader": { "test": {} }
    11. }

    This extracts the data as:

    1. {
    2. "TITLE": "Empire Burlesque",
    3. "ARTIST": "Bob Dylan",
    4. "COUNTRY": "USA",
    5. "COMPANY": "Columbia",
    6. "PRICE": "10.90",
    7. "YEAR": "1985"
    8. }
    9. {
    10. "TITLE": "Hide your heart",
    11. "ARTIST": "Bonnie Tyler",
    12. "COUNTRY": "UK",
    13. "COMPANY": "CBS Records",
    14. "PRICE": "9.90",
    15. "YEAR": "1988"
    16. }
    17. {
    18. "TITLE": "Greatest Hits",
    19. "ARTIST": "Dolly Parton",
    20. "COUNTRY": "USA",
    21. "COMPANY": "RCA",
    22. "PRICE": "9.90",
    23. "YEAR": "1982"
    24. }