-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMerge.java
More file actions
46 lines (43 loc) · 2.01 KB
/
Merge.java
File metadata and controls
46 lines (43 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.*;
import java.io.*;
public class Merge {
public static void main(String[] args) throws Exception {
String dataPath = args[0];
String metadataPath = args[1];
String outputPath = args[2];
Map<String, Map<String, String>> metadata = readAndIndexMetadata(metadataPath);
convertData(dataPath, outputPath, metadata);
}
private static Map<String, Map<String, String>> readAndIndexMetadata(String metadataPath) throws Exception {
Map<String, Map<String, String>> result = new HashMap<>();
BufferedReader reader = new BufferedReader(new FileReader(new File(metadataPath)));
String line = "";
while ((line = reader.readLine()) != null) {
String[] values = line.split(",");
if (!result.containsKey(values[0])) {
result.put(values[0], new HashMap<String, String>());
}
result.get(values[0]).put(values[1], values[2]);
}
reader.close();
return result;
}
private static void convertData(String dataPath, String outputPath, Map<String, Map<String, String>> metadata) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(new File(dataPath)));
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(outputPath)));
String line = "";
while ((line = reader.readLine()) != null) {
String[] values = line.split(",");
StringBuilder result = new StringBuilder("");
result.append(metadata.get("AWS-Billing-Account").get(values[0])).append(",");
result.append(metadata.get("AWS-Account").get(values[1])).append(",");
result.append(metadata.get("AWS-Service-Category").get(values[2])).append(",");
result.append(metadata.get("Past-12-Months").get(values[3])).append(",");
result.append(values[4]);
writer.write(result.toString());
}
writer.flush();
writer.close();
reader.close();
}
}