Accessing kettle internal components using JavaScript
There are few ETL project requirements that cannot be achieved using kettle standard steps. Let's say that every record needs to be marked as information from that database, and the original database is set through the DB connection, how do I get these settings? (Type, host, port, database name, etc.)
There are no standard steps to implement in kettle, fortunately JavaScript steps can access the kettle internal components and implement the requirements above.
Access kettle internal components are _STEP_ variables, which are automatically set in each JavaScript step. It represents the JavaScript step itself, the Gettransmeta () method of the step returns the Transmeta object, representing the entire transformation, and the Transmeta object can be used to obtain information about the database connection that is defined in the transformation. The correct Transmeta object is obtained through the Finddatabase () method, returns the Databasemeta object, and other information that provides a set of methods to return the database connection.
The following code gets some information that is named "Sourcedb" database connection.
Get DB Object
var db = _step_.gettransmeta (). Finddatabase ("Sourcedb");
Ask DB object for information
var db_type = Db.getdatabasetypedesc ();
var db_host = Db.gethostname ();
var db_port = db.getdatabaseportnumberstring ();
var db_name = Db.getdatabasename ();
var db_tblspace = Db.getdatatablespace ();
var db_idxspace = Db.getindextablespace ();
var db_user = Db.getusername ();
var db_pass = Db.getpassword ();
var db_url = Db.geturl ();
var db_driver = Db.getdriverclass ();
It is to be recalled that the kettle version is constantly being updated and that its internal components may be different between versions. Therefore, a comprehensive test is required to upgrade the code that accesses kettle internal components to a new version.
Saying so much, it's better to download the sample code, which writes the database connection information to a text file in the 5.1 version of the test.
I hope you will share the discussion, your suggestion is my motivation.
Accessing kettle internal components using JavaScript