Operations: How to Add ETL

You can add ETL task by using AddEtlOperation.

Syntax

public AddEtlOperation(EtlConfiguration<T> configuration);
Parameters
configuration EtlConfiguration<T> ETL configuration where T is connection string type

Example - Add Raven ETL

Secure servers

To connect secure RavenDB servers you need to

  1. Export the server certificate from the source server.
  2. Install it as a client certificate on the destination server.

This can be done in the RavenDB Studio -> Server Management -> Certificates view.

RavenEtlConfiguration configuration = new RavenEtlConfiguration();
configuration.setName("Employees ETL");
Transformation transformation = new Transformation();
transformation.setName("Script #1");
transformation.setScript("loadToEmployees ({\n" +
    "  Name: this.FirstName + ' ' + this.LastName,\n" +
    "  Title: this.Title\n" +
    "});");

configuration.setTransforms(Arrays.asList(transformation));
AddEtlOperation<RavenConnectionString> operation = new AddEtlOperation<>(configuration);
AddEtlOperationResult result = store.maintenance().send(operation);

Example - Add Sql ETL

SqlEtlConfiguration configuration = new SqlEtlConfiguration();
SqlEtlTable table1 = new SqlEtlTable();
table1.setTableName("Orders");
table1.setDocumentIdColumn("Id");
table1.setInsertOnlyMode(false);

SqlEtlTable table2 = new SqlEtlTable();
table2.setTableName("OrderLines");
table2.setDocumentIdColumn("OrderId");
table2.setInsertOnlyMode(false);

configuration.setSqlTables(Arrays.asList(table1, table2));
configuration.setName("Order to SQL");
configuration.setConnectionStringName("sql-connection-string-name");

Transformation transformation = new Transformation();
transformation.setName("Script #1");
transformation.setCollections(Arrays.asList("Orders"));
transformation.setScript("var orderData = {\n" +
    "    Id: id(this),\n" +
    "    OrderLinesCount: this.Lines.length,\n" +
    "    TotalCost: 0\n" +
    "};\n" +
    "\n" +
    "    for (var i = 0; i < this.Lines.length; i++) {\n" +
    "        var line = this.Lines[i];\n" +
    "        orderData.TotalCost += line.PricePerUnit;\n" +
    "\n" +
    "        // Load to SQL table 'OrderLines'\n" +
    "        loadToOrderLines({\n" +
    "            OrderId: id(this),\n" +
    "            Qty: line.Quantity,\n" +
    "            Product: line.Product,\n" +
    "            Cost: line.PricePerUnit\n" +
    "        });\n" +
    "    }\n" +
    "    orderData.TotalCost = Math.round(orderData.TotalCost  * 100) / 100;\n" +
    "\n" +
    "    // Load to SQL table 'Orders'\n" +
    "    loadToOrders(orderData)");

configuration.setTransforms(Arrays.asList(transformation));

AddEtlOperation<SqlConnectionString> operation = new AddEtlOperation<>(configuration);

AddEtlOperationResult result = store.maintenance().send(operation);

Example - Add OLAP ETL

OlapEtlConfiguration configuration = new OlapEtlConfiguration();

configuration.setName("Orders ETL");
configuration.setConnectionStringName("olap-connection-string-name");

Transformation transformation = new Transformation();
transformation.setName("Script #1");
transformation.setCollections(Arrays.asList("Orders"));
transformation.setScript("var orderDate = new Date(this.OrderedAt);\n"+
    "var year = orderDate.getFullYear();\n"+
    "var month = orderDate.getMonth();\n"+
    "var key = new Date(year, month);\n"+
    "loadToOrders(key, {\n"+
    "    Company : this.Company,\n"+
    "    ShipVia : this.ShipVia\n"+
    "})"
);

configuration.setTransforms(Arrays.asList(transformation));

AddEtlOperation<OlapConnectionString> operation = new AddEtlOperation<OlapConnectionString>(configuration);

AddEtlOperationResult result = store.maintenance().send(operation);