tCouchDBOutput
Loads JSON documents, writes data into or remove data from them and then saves the
documents back to the database on a CouchDB server.
tCouchDBOutput receives data from
the preceding component, and writes data into CouchDB.
tCouchDBOutput Standard properties
These properties are used to configure tCouchDBOutput running in the Standard Job framework.
The Standard
tCouchDBOutput component belongs to the Big Data and the Databases families.
The component in this framework is available when you are using one of the Talend solutions with Big Data.
Basic settings
Schema and Edit schema |
A schema is a row description. It defines the number of fields (columns) to Click Edit schema to make changes to the schema.
|
|
Built-In: You create and store the |
|
Repository: You have already created When the schema to be reused has default values that are integers or You can find more details about how to verify default |
Sync columns |
Click this button to retrieve schema from the previous component |
Use existing connection |
Select this check box and in the Component |
DB Version |
Select the CouchDB version that you are using. |
Server |
Hostname or IP address of the CouchDB server. |
Port |
Listening port number of the CouchDB server. |
Database |
Name of the database that you want to use. |
Required authentication |
Select this check box to provide credentials for the CouchDB
To enter the password, click the […] button next to the |
Use trigger replication |
Select this check box to trigger replication between Warning:
This check box appears only if you do not select the Use an existing connection check |
Target DB name |
Specify the target database to which the documents will be copied. |
Continuous |
Select this check box to continue a replication upon the server |
Create target DB |
Select this check box to create the target database if it does not |
IS Canceled |
Select this check box to cancel the existing replication between |
Action on data |
On the data of interest, you can perform:
|
Generate JSON Document |
Select this check box to generate a JSON document and configure |
Key |
Select the key that you want to use from the list. |
Configure JSON Tree |
Click the […] button to open |
Group by |
Customize the input columns based on which you want to group the |
Remove root node |
Select this check box to remove the root node. |
Die on error |
This check box is cleared by default, meaning to skip the row on |
Advanced settings
tStatCatcher Statistics |
Select this check box to gather the Job processing metadata at the |
Global Variables
Global Variables |
NB_LINE: the number of rows read by an input component or
NB_LINE_INSERTED: the number of rows inserted. This is an
ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see |
Usage
Usage rule |
This component is used as an output component and it always needs |
Scenario: Replicating data from the source database to the target database
This scenario applies only to a Talend solution with Big Data.
This scenario describes a Job that writes the information of books into a CouchDB
database, replicates the data to the target database, and then displays some replicated
information of interest on the console.
Linking the components
-
Drop the following components from the Palette onto the design workspace: tCouchDBConnection, tFileInputDelimited, tCouchDBOutput, tCouchDBInput, tLogRow and
tCouchDBClose. - Connect tFileInputDelimited to tCouchDBOutput using a Row > Main link.
-
Do the same to connect tCouchDBInput to
tLogRow. -
Connect tCouchDBConnection to tFileInputDelimited using a Trigger > OnSubjobOk
link. - Do the same to connect tFileInputDelimited to tCouchDBInput and tCouchDBInput to tCouchDBClose.
- Label the components to better identify their functions.
Configuring the components
Opening a CouchDB connection and triggering replication
-
Double-click the tCouchDBConnection
component to open its Basic settings view
in theComponent tab. - In the Server and Port fields, type in the connection details.
-
In the Database field, type in the name
of the database you want to use: bookstore_old in this example. - Select the CouchDB version that you are using from the DB Version list.
-
Select the Use trigger replication check
box. -
In the Replicate target database area,
click [+] to add one line for database
replication settings. - Enter the name of the target database name: bookstore_new in this example.
-
Select the Continuous check box to
continue the replication upon the server restart. -
In this example, the target database does not exist. Select the Create target DB check box to create the target
database. -
Select the Is Canceled check box to
cancel the replication between bookstore_old and bookstore_new at the end of the Job.
Reading the input data
-
Double-click the tFileInputDelimited
component to open its Component
view. -
Click the […] button next to the
File name/Stream field to browse to the
file that you want to read data from. In this scenario, it is D:/Input/bookstore.txt. The file contains six
columns: _id, title, author, category, ISBN, and abstract._id;title;author;category;ISBN;abstract
001;Computer Networks: A Systems Approach;Larry L. Peterson, Bruce S. Davie;Computer Science;0123850606;This best-selling and classic book teaches you the key principles of computer networks with examples drawn from the real world of network and protocol design.
002;David Copperfield;Charles Dickens;Language&Literature;1555763227;This adaptation of the original story is presented in the format of a novel study, complete with exercises and vocabulary lists, and is geared to the language arts classes of grades 4 and 5.
003;Life of Pi;Yann Martel;Language&Literature;0547350651;The son of a zookeeper, Pi Patel has an encyclopedic knowledge of animal behavior and a fervent love of stories.
004;Les Miserables: Easyread Comfort Edition;Victor Hugo;Language&Literature;1425048250;Expressing the author's ideas about society, religion and politics, it is in the backdrop of Napoleonic Wars and ensuing years that the story unravels. Grace, moral philosophy, law and history of France are discussed.
005;Computer Security;Dieter Gollmann;Computer Science;0470741155;This text moves away from the 'multi-level' security approach to compare and evaluate design alternatives in computer security.
006;Advanced Database Systems;Carlo Zaniolo;Database;155860443X;This book, written by a team of leading specialists in their fields, introduces the research issues at the forefront of database technology and supports them with a variety of examples.
-
In the Header field, type in 1 so that the header of the file will be
skipped. -
Click Edit schema to define the data to
pass on to the tCouchDBOutput component.
Writing data into one database and replicating the data
-
Double-click the tCouchDBOutput component
to open its Basic settings view in the
Component tab. -
Click Sync columns to retrieve the schema
from the preceding component. -
Select the Use an existing connection
check box. In this example, the replication is triggered when opening the
CouchDB connection. - Select Upsert from the Action on data drop-down list.
Extracting the replicated data of interest
-
Double-click the tCouchDBInput component
to open its Component view. -
Click Edit schema to define the data
structure to be read from the CouchDB database.By default, the Include docs check box is
selected, so the id, key, value and jsonDoc columns are available in the
schema.In this example, we define four columns to be extracted: id, title,
author and category. - Enter the Server and Port information.
-
In the Database field, enter the name of
the database from which the replicated data will be read. In this example,
it is bookstore_new. -
In the Querying options area, type in the
start key and end key to set the range of the data to be read: “001” and “006” in this example. -
Select the Extract JSON field check box
to extract the desired data. - Select jsonDoc from the JSON field list.
-
In the Mapping area, click [+] to add items. Select the schema output column
from the list and then type in the proper XPath query.
Displaying the extracted data
-
Double-click the tLogRow component to
open its Component view. -
Click Edit schema to define the data
structure to be displayed on the console. In this example, we need to remove
the jsonDoc column. - In the Mode area, select Table (print values in cells of a table).
Closing the CouchDB connection
-
Double-click the tCouchDBClose component
to open its Component view. - Select the connection to be closed from the Component List.
Saving and executing the Job
- Press Ctrl+S to save your Job.
-
Execute the Job by pressing F6 or
clicking Run on the Run tab.The book information read from the replicated database is shown on the
console.