tMongoDBInput properties in Spark Batch Jobs - 6.3

Talend Components Reference Guide

EnrichVersion
6.3
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

Component family

Databases/MongoDB

 

Basic settings

Property type

Either Built-In or Repository.

Built-In: No property data stored centrally.

Repository: Select the repository file where the properties are stored.

 

MongoDB configuration

Select this check box and in the Component List click the relevant connection component to reuse the connection details you already defined.

 

Schema and Edit Schema

A schema is a row description. It defines the number of fields (columns) to be processed and passed on to the next component. The schema is either Built-In or stored remotely in the Repository.

Click Edit schema to make changes to the schema. If the current schema is of the Repository type, three options are available:

  • View schema: choose this option to view the schema only.

  • Change to built-in property: choose this option to change the schema to Built-in for local changes.

  • Update repository connection: choose this option to change the schema stored in the repository and decide whether to propagate the changes to all the Jobs upon completion. If you just want to propagate the changes to the current Job, you can select No upon completion and choose this schema metadata again in the [Repository Content] window.

If a column in the database is a JSON document and you need to read the entire document, put an asterisk (*) in the DB column column, without quotation marks around.

 

Collection

Enter the name of the collection to be used.

A MongoDB collection is the equivalent of an RDBMS table and contains documents.

If the collection to be used is not sharded, it is recommended to add the mongo.input.split_size property to the Advanced Hadoop MongoDB properties table. This parameter determines how the collection is going to be partitioned and read by the Spark executors. The number of partitions of the input collection can be calculated using the following formula:

Number of partitions = Collection size in MB / mongo.input.split_size

Without this property, Spark uses the default value, 8 MB, for the partition size.

For example:

mongo.input.split_size   1

In this example, Spark dispatches 1 MB to each Spark executor in order to read the non-sharded collection in parallel. If the collection size is 10 MB, 10 executors are employed.

 

Set read preference

Select this check box and from the Read preference drop-down list that is displayed, select the member to which you need to direct the read operations.

If you leave this check box clear, the Job uses the default Read preference, that is to say, uses the primary member in a replica set.

For further information, see MongoDB's documentation about Replication and its Read preferences.

 

Query

Specify the query statement to select documents from the collection specified in the Collection field. For example, type in "{'id':'4'}" to retrieve the record whose id is 4 from the collection.

The default query, {} within double quotation marks provided with this component, means to select all of the files. You can also apply a regular expression by putting {'filename':{'$regex':'REGEX_PATTERN'}} to define the file names to be used.

Different from the query statements required in the MongoDB client software, the query here refers to the contents inside find(), such as the query {'filename':{'$regex':'REGEX_PATTERN'}} here is the equivalent of db.blog.find({filename:{$regex:REGEX_PATTERN}}) in the MongoDB client query.

 

Mapping

Each column of the schema defined for this component represents a field of the documents to be read. In this table, you need to specify the parent nodes of these fields, if any.

For example, in the document reading as follows

{
               _id: ObjectId("5099803df3f4948bd2f98391"),
               person: { first: "Joe", last: "Walker" }
            }

The first and the last fields have person as their parent node but the _id field does not have any parent node. So once completed, this Mapping table should read as follows:

Column     Parent node path
_id
first       "person"
last        "person"
 

Limit

Enter the maximum number of records to be retrieved.

Advanced settings

Advanced Hadoop MongoDB properties

Add properties to define extra operations you need tMongoDBInput to perform when reading data.

The available properties are listed and explained in MongoDB Connector for Hadoop.

If the collection to be used is not sharded, it is recommended to add the mongo.input.split_size property to the Advanced Hadoop MongoDB properties table. This parameter determines how the collection is going to be partitioned and read by the Spark executors. The number of partitions of the input collection can be calculated using the following formula:

Number of partitions = Collection size in MB / mongo.input.split_size

Without this property, Spark uses the default value, 8 MB, for the partition size.

For example:

mongo.input.split_size   1

In this example, Spark dispatches 1 MB to each Spark executor in order to read the non-sharded collection in parallel. If the collection size is 10 MB, 10 executors are employed.

Usage in Spark Batch Jobs

This component is used as a start component and requires an output link..

This component should use a tMongoDBConfiguration component present in the same Job to connect to a MongoDB database. You need to drop a tMongoDBConfiguration component alongside this component and configure the Basic settings of this component to use tMongoDBConfiguration.

This component, along with the Spark Batch component Palette it belongs to, appears only when you are creating a Spark Batch Job.

Note that in this documentation, unless otherwise explicitly stated, a scenario presents only Standard Jobs, that is to say traditional Talend data integration Jobs.

Log4j

If you are using a subscription-based version of the Studio, the activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User Guide.

For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html.

Spark Connection

You need to use the Spark Configuration tab in the Run view to define the connection to a given Spark cluster for the whole Job. In addition, since the Job expects its dependent jar files for execution, one and only one file system related component from the Storage family is required in the same Job so that Spark can use this component to connect to the file system to which the jar files dependent on the Job are transferred:

This connection is effective on a per-Job basis.