Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
public static Integer get_measurementiID(String columnname){
if (columnname != null) {
String[] explode=columnname.split("X");
return Integer.parseInt(explode);
}
return null;
}
// start part of your Java code
int ncount=0;
String columnName="";
DynamicMetadata column;
Boolean firstRow = true;
String create = "CREATE TABLE " + "\"" + context.TABLENAME + "\"" + " ( ";
ncount=dynamic_tFileInputDelimited_2.getColumnCount();
int counter = 0;
/* Empty */
for( int columnIndex = 0; columnIndex < ncount; columnIndex++ ) {
column=dynamic_tFileInputDelimited_3.getColumnMetadata(columnIndex);
columnName=column.getName();
if( context.ROW_LEVEL_LOGGING ) {
System.out.println(columnName + " index: " + columnIndex + "counter: " + counter);
}
if( (null != columnName) && (!"".equals(columnName)) ) {
if( firstRow ) {
create += "\"" +columnName + "\"" + " VARCHAR ";
firstRow = false;
}
else {
create += " , " + "\"" + columnName + "\"" + " VARCHAR ";
}
}
// System.out.println("K:" + columnName + " V:" +columnValue);
counter++;
}
create += " ) ";
if( context.ROW_LEVEL_LOGGING ) {
System.out.println("Generated DDL: " + create );
}
context.CREATE_TABLE_STATEMENT = create;
If you're using Talend's Enterprise version, you can use the Dynamic column type to do what you want.
here's some sample code I use to generate table create statements for one of my dynamic table loaders:
in a tJavaFlex:
Begin:// start part of your Java code
int ncount=0;
String columnName="";
DynamicMetadata column;
Boolean firstRow = true;
String create = "CREATE TABLE " + "\"" + context.TABLENAME + "\"" + " ( ";
ncount=dynamic_tFileInputDelimited_2.getColumnCount();
int counter = 0;
Main:/* Empty */
End:
for( int columnIndex = 0; columnIndex < ncount; columnIndex++ ) {
column=dynamic_tFileInputDelimited_3.getColumnMetadata(columnIndex);
columnName=column.getName();
if( context.ROW_LEVEL_LOGGING ) {
System.out.println(columnName + " index: " + columnIndex + "counter: " + counter);
}
if( (null != columnName) && (!"".equals(columnName)) ) {
if( firstRow ) {
create += "\"" +columnName + "\"" + " VARCHAR ";
firstRow = false;
}
else {
create += " , " + "\"" + columnName + "\"" + " VARCHAR ";
}
}
// System.out.println("K:" + columnName + " V:" +columnValue);
counter++;
}
create += " ) ";
if( context.ROW_LEVEL_LOGGING ) {
System.out.println("Generated DDL: " + create );
}
context.CREATE_TABLE_STATEMENT = create;
If you're using Talend's Enterprise version, you can use the Dynamic column type to do what you want.
here's some sample code I use to generate table create statements for one of my dynamic table loaders:
in a tJavaFlex:
Begin:// start part of your Java code
int ncount=0;
String columnName="";
DynamicMetadata column;
Boolean firstRow = true;
String create = "CREATE TABLE " + "\"" + context.TABLENAME + "\"" + " ( ";
ncount=dynamic_tFileInputDelimited_2.getColumnCount();
int counter = 0;
Main:/* Empty */
End:
for( int columnIndex = 0; columnIndex < ncount; columnIndex++ ) {
column=dynamic_tFileInputDelimited_3.getColumnMetadata(columnIndex);
columnName=column.getName();
if( context.ROW_LEVEL_LOGGING ) {
System.out.println(columnName + " index: " + columnIndex + "counter: " + counter);
}
if( (null != columnName) && (!"".equals(columnName)) ) {
if( firstRow ) {
create += "\"" +columnName + "\"" + " VARCHAR ";
firstRow = false;
}
else {
create += " , " + "\"" + columnName + "\"" + " VARCHAR ";
}
}
// System.out.println("K:" + columnName + " V:" +columnValue);
counter++;
}
create += " ) ";
if( context.ROW_LEVEL_LOGGING ) {
System.out.println("Generated DDL: " + create );
}
context.CREATE_TABLE_STATEMENT = create;