Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
since_1995
Contributor III
Contributor III

Talend tjava code for tfilelist filesnames

Hi team,

below is the code which i'm implementing after tfilelist using tjava to pick the files based on the conditions

Files in folder:

TEST_1415_1617.csv,

TEST_1515_1617.csv,

retry1_TEST_1515_1617.csv,

TEST_91011_1213.csv,

retry1_TEST_91011_1213.csv,

retry2_TEST_91011_1213.csv,

TEST_20011_1213.csv,

retry1_TEST_20011_1213.csv,

 

Pick only these

TEST_1415_1617.csv,

retry1_TEST_1515_1617.csv,

retry2_TEST_91011_1213.csv,

retry1_TEST_20011_1213.csv,

structure of job

tfilelist--->itertae--->tjava--->main--->trunjob

im getting an error with conversion of string to string[], but will tjava able to list all the files or it shows current files in each iteration, so will the below code work in my scenario

 

system.out.println((string.globalMap.get("tfleList_1_CURRENT_FILE"));

String[] fileNames = ((string.globalMap.get("tfleList_1_CURRENT_FILE"));

    Map<String, Integer> map = new HashMap<>();

    List<String> filesToProcess = new ArrayList<>();

    for (int i = 0; i < fileNames.length; i++) {

      if (fileNames[i].contains("retry")) {

        Integer number = Integer.parseInt(fileNames[i].substring(5, 6));

        if (map.get(fileNames[i].substring(7)) == null) {

          map.put(fileNames[i].substring(7), number);

        } else {

          if (number > map.get(fileNames[i].substring(7))) {

            map.put(fileNames[i].substring(7), number);

          }

        }

      } else {

        if (map.get(fileNames[i]) == null)

          map.put(fileNames[i], 0);

      }

    }

    for (Map.Entry<String, Integer> entry : map.entrySet()) {

      if (entry.getValue() > 0) {

        filesToProcess.add("retry" + entry.getValue() + "_" + entry.getKey());

      } else {

        filesToProcess.add(entry.getKey());

      }

    }

    System.out.println(filesToProcess);

Labels (4)
1 Solution

Accepted Solutions
Anonymous
Not applicable

Hi

The error occurs on this line

String[] fileNames = ((string.globalMap.get("tfleList_1_CURRENT_FILE"));

Can't convert string to string[], to new a String array, should be:

String variableName[] = new String[capacity];

String variableName[] = {comma-delimited values};

 

Regards

Shong

 

View solution in original post

2 Replies
Anonymous
Not applicable

Hi

The error occurs on this line

String[] fileNames = ((string.globalMap.get("tfleList_1_CURRENT_FILE"));

Can't convert string to string[], to new a String array, should be:

String variableName[] = new String[capacity];

String variableName[] = {comma-delimited values};

 

Regards

Shong

 

since_1995
Contributor III
Contributor III
Author

Thanks