Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[resolved] how to get the column names in a data flow?

Hi 0683p000009MACn.png ,
I'd like to know how to get the column names of a table in a flow of data: excel, delimited or postgresql.
I have to compare them to the ones I should use. It could be via a tMap component.
I must follow a strict naming plan for files and their fields...
Would you know how to get that?
Thanks,
Mathieu
Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Hi Feroz,
Following code you can use in your tJavaRow...to get the column names to the context variable.
for (java.lang.reflect.Field field: row1.getClass().getDeclaredFields()) {
context.columnName = field.getName();
      System.out.println("Field name is " + context.columnName );      
           }
You can extend this code for your design...
Vaibhav

View solution in original post

12 Replies
Anonymous
Not applicable
Author

Hello Mathieu
Try the code
String columnName=null;
for (java.lang.reflect.Field field: row1.getClass().getDeclaredFields()) {
columnName=field.getName().toLowerCase();
System.out.println(columnName);
}

Best regards
shong
Anonymous
Not applicable
Author

thanks shong,
It works well, I get the column names.
They're printed out in the system.
But how to export them in a delimited file?
or make a column name a data flow so that it can be compared to a reference table via a tMap component?
Thanks again 0683p000009MACn.png,
Mathieu
Anonymous
Not applicable
Author

Hello
But how to export them in a delimited file?
or make a column name a data flow so that it can be compared to a reference table via a tMap component?

Define context variables to store the column name.
Best regards

shong
Anonymous
Not applicable
Author

OK thanks 0683p000009MACn.png
Anonymous
Not applicable
Author

Hi,
It works correctly but I would to have access to the value or at least I would like to know if the value is null/blank. It can be a problem because I will have different type. Do you have an answer?
Thanks.
alevy
Specialist
Specialist

Use tJavaRow instead of tJava, then:
Object objValue = field.get(input_row);
String fldType = field.getType().getName();
Once you know the field type you can convert the value to the appropriate type for comparisons.
_AnonymousUser
Specialist III
Specialist III

plz can u tell me how to assign column names to context variable
thanks and regards
syed
Anonymous
Not applicable
Author

plz can u tell me how to assign column names to context variable
thanks and regards
syed
Anonymous
Not applicable
Author

plz can u tell me how to assign column names to context variable
thanks and regards
syed

Plz Give me a quick reply