You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 27, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: examples/rowToDoc/README.md
+33-5Lines changed: 33 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,40 @@
1
1
# SQL Example #1 - Import Invoice Documents
2
2
3
-
This is an batch processing job example that migrates the tabular rows of a SQL Query, transforms them into either JSON or XML and inserts the data into MarkLogic.
3
+
This is an batch processing job example that migrates the tabular rows of a SQL Query, transforms them into either JSON or XML and inserts the data into MarkLogic.
4
4
5
5
The RDBMS data set is using the [Invoice data](invoices-sql-diagram.jpg) from the [HSQL relational database](http://www.hsqldb.org/).
6
6
7
+
This job can take two tables and create child elements from the many relationship. For this example, we will examine the
8
+
customer and invoice tables. These two tables are joined via a one (customer) to
9
+
many (invoice) relationship. We have decided that the root element is going to be based on the customer
10
+
and many invoice children will be created. By renaming the column names using a
11
+
**[parent element]/[child element]** naming convention in your SQL query, this batch processing job
12
+
will create the document accordingly.
13
+
14
+
SELECT customer.*, invoice.id as \"invoice/id\", invoice.total as \"invoice/total\"
15
+
FROM invoice LEFT JOIN customer on invoice.customerId = customer.id
16
+
ORDER BY customer.id
17
+
18
+
In this example, this would generate the following sample document.
19
+
20
+
<invoice>
21
+
<ID>13</ID>
22
+
<FIRSTNAME>Laura</FIRSTNAME>
23
+
<LASTNAME>Ringer</LASTNAME>
24
+
<STREET>38 College Av.</STREET>
25
+
<CITY>New York</CITY>
26
+
<invoice>
27
+
<id>43</id>
28
+
<total>3215</total>
29
+
</invoice>
30
+
<invoice>
31
+
<id>30</id>
32
+
<total>1376</total>
33
+
</invoice>
34
+
</invoice>
35
+
36
+
Please note that any child elements beyond the second level are not yet supported.
37
+
7
38
## Create RowToDoc Distribution Program
8
39
1) gradle installDist
9
40
2) Verify the program that was installed under ./build/install/rowToDoc
@@ -21,11 +52,8 @@ This command uses the [gradle application plugin](https://docs.gradle.org/curren
21
52
1) Open rowToDoc.bat and check the host, port, username, and password parameters to make sure that they point to a valid MarkLogic application server
22
53
2) Execute: rowToDoc.bat
23
54
24
-
For Unix based systems, execute build\install\rowToJson\bin\sql
25
-
26
-
The program can also be executed via a Gradle JavaExec task
55
+
For Unix based systems, execute build\install\rowToJson\bin\rowToDoc
"--sql", "SELECT * FROM invoice LEFT JOIN customer on invoice.customerId=customer.id LEFT JOIN item on invoice.id=item.invoiceId LEFT JOIN product on product.id=item.productId ORDER BY invoice.id asc",
privateStringsql = "SELECT customer.*, invoice.id as \"invoice/id\", invoice.total as \"invoice/total\" FROM invoice LEFT JOIN customer on invoice.customerId = customer.id ORDER BY customer.id";
@@ -69,7 +77,7 @@ public void jdbcCursorItemReaderTest() throws Exception {
69
77
}
70
78
71
79
@Test
72
-
publicvoidrunRowToDocJobTest() {
80
+
publicvoidrunRowToDocJobWithTransformTest() {
73
81
runJob(RowToDocTestConfig.class,
74
82
"--sql", "SELECT customer.*, invoice.id as \"invoice/id\", invoice.total as \"invoice/total\" FROM invoice LEFT JOIN customer on invoice.customerId = customer.id ORDER BY customer.id",
75
83
"--jdbc_username", "sa",
@@ -78,7 +86,29 @@ public void runRowToDocJobTest() {
0 commit comments