Metaprogramming in Abinitio


1. How to create output DML dynamically based in INPUT DML


2. How to create intermediate transform( XFR) dynamically based on INPUT DML

 

   Please See my you tube video for explanation :

PART 1


PART 2



For Example, let us say, we have an Input DML as below-:

cat input.dml

record

string(",") name;

decimal(",") age;

decimal(",") salary;

string(",") aadharid;

date("yyyy-mm-dd")(",") joiningdate;

string(",") mobileno=NULL;

string(",") dlno=NULL;

string(",") passportnumber=NULL;

end;



(1.1) prepare a new DML based on input DML i.e. add fields, remove fields, modify type

Graph based parameters:
=====================================================================


input_dml=$DIR/input.dml  [interpretation = constant]

input_dml_info =$[read_type(input_dml)]   [interpretation = pdl]

/* Define functions in AB_DML_DEFS */
AB_DML_DEFS=
$[

out:: dynamic_dml_gen(input_dml_info)=
begin
let dml_field_info_vec dml_info = record_info(input_dml_info);
let int no_of_fields = length_of(dml_info);
let dml_field_info_vec out_dml_info = [vector];
let int i=0;

for(i, i<no_of_fields)
begin

if( is_defined(fail_if_error(dml_info.name)) and !(dml_info.name member [vector 'dlno','passportnumber' ])
out_dml_info = vector_append(out_dml_info,make_field(dml_info.name,dml_info.dml_type));

end

out_dml_info = vector_append(out_dml_info,make_field("address","string(',')",'',1,1,'string'));
out_dml_info = vector_append(out_dml_info,make_field("year","string('\n')",'',1,1,'string'));
out :: out_dml_info;

end

out::dynamic_dml(out_dml_info) =
begin
let dml_field_info_vec out_dml_info = out_dml_info;
out :: add_fields('record n end', out_dml_info);
end

out::dynamic_transform(input_dml_info,out_dml_info)=
begin
let dml_field_info_vec dml_info = record_info(input_dml_info);
let dml_field_info_vec out_dml_info = out_dml_info;
let int no_in_fields = length_of(out_dml_info);

let dml_variable_vec var_vec = [vector];
let dml_statement_vec stmt_vec = [vector];
let dml_rule_vec rules_vec = [vector];


let string(int) priority = "1d";
let int i=0;

var_vec = vector_append(var_vec,make_local('l_year','string(",")','string_substring(in.joiningdate,1,4)'));
var_vec = vector_append(var_vec,make_local('l_address','string(",")',"1 triveninagar jaipur 302018"));

for(i, i<no_in_fields)
begin
rules_vec = vector_append(rules_vec, make_rule("out."+out_dml_info[i].name,"in."+out_dml_info[i].name),priority));
end 

rules_vec = vector_append(rules_vec, make_rule("out.address","l_address",priority));
rules_vec = vector_append(rules_vec, make_rule("out.year","l_year",priority));


out :: make_transform("reformat", [vector make_arg("in")],[vector make_arg("out")],var_vec,stmt_vec,rules_vec);

end

]

output_dml_info=$[dynamic_dml_gen(input_dml_info)]  pdl interpretation

output_dml=$[dynamic_dml(output_dml_info)]
output_xfr=$[dynamic_transform(input_dml_info,output_dml_info)]



============================
output.dml
record
string(",") name;  /* this signifies name of employee*/
decimal(",") age;
decimal(",") salary;
string(",") aadharid;
date("yyyy-mm-dd")(",") joiningdate;
string(",") mobileno=NULL;
string(",") adress=NULL;
string("\n") year=NULL;
end;

out_put.xfr

out:reformat(in)=
begin

let string(",") l_year=string_substring(in.joiningdate,1,4); /*year of joining */
let string(",") l_address="1 triveninagar jaipur 302018";


out.name::in.name;  
out.age::in.age;
out.salary::in.salary;
out.aadharcard::in.aadharcard;
out.joiningdate::in.joiningdate;
out.mobileno::in.mobileno;
out.year::l_year;
out.address::l_address;
end;


Other use cases can be created and solved by this are as below:

(1.2) create static dmls as required. these are such small dmls needed to collect known output.
  
(1.3) split the super dml in specific sub sets of dmls

(1.4) Combine the dml - May be to be used in fuse component or join component.



Other helpful types and Functions used in the metaprogramming:

Metaprogramming:

Type dml_field_info =record

                                             String(integer(4)) name;

                                             String(integer(4)) dml_type;

                                             String(integer(4)) default;

                                             Decimal(1) nullable;

                                             Decimal(1) nullflag;

                                             String(integer(4)) condition;

                                             String(integer(4)) form;

                              End;

Make_field

============================

              

Dml_variable_vec  = record

                                             String(integer(4)) name;

                                             String(integer(4)) dml_type;

                                             String(integer(4)) init;

                                             String(integer(4)) comment;

                                             Decimal(1) nullable=”1”;

                              End;

Make_local()

 

Dml_rule_vec   = record

                                             String(integer(4)) lhs;

                                             String(integer(4)) rhs;

                                             Decimal(“,”)   priority;

                                             String(integer(4)) comment=NULL(“”)

End;

make_rule()

Dml_statement_vec =record

                                     String(integer(4)) statement;

        String(integer(4)) comment=NULL(“”)

End;

Make_statement(statement=”if(i>56) k=k +1;”)

   Dml_statement

     Record

                 Dml_metadata_string  statement;

                Dml_metadata_String comment=null(“”);

               Dml_metadata_string scomment=null(“”);

     End

 

              

Input   àReformatàOutput


For other such content related to AWS , Abinitio, and UNIX , SQL DWH , please visit my channel.


DataPundit 


                                                                DATAPUNDIT

                                                                by DataPundit...



Comments

Post a Comment

Popular posts from this blog

Abinitio Interview Question # 1 - Write Multiple Files in Abinitio

Next In Sequence in ABinitio | How next_in_sequence() works in MFS