-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchwithspecificReqDriver.java
226 lines (166 loc) · 5.26 KB
/
searchwithspecificReqDriver.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import java.net.URI;
import java.util.ArrayList;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
public class searchwithspecificReqDriver extends Configured implements Tool{
public void getfilewiththisconstraints(String category, String year, String month, String date, String fileformat,String username, String size, String timestmp) throws Exception {
// TODO Auto-generated method stub
String[] args = {category,year,month,date,fileformat,username,size,timestmp};
int res = ToolRunner.run(new Configuration(), new searchwithspecificReqDriver(), args);
}
@Override
public int run(String[] arg0) throws Exception {
// TODO Auto-generated method stub
String pathtoSearch = "";
//get all files of metadaa first
Configuration configuration = new Configuration();
FileSystem hdfs = FileSystem.get(new URI("hdfs://172.50.88.17:54310"), configuration);
FileStatus[] status= hdfs.listStatus(new Path("/metadata/"));
ArrayList<String> filePathtobeSearched = new ArrayList<String>();
for(FileStatus filenamee: status)
{
String filename = filenamee.getPath().getName().toString();
if(!filename.contains("category.txt"))
{
filePathtobeSearched.add(filename);
}
System.out.println(filename);
}
ArrayList<String> filewhichContainsconstraint = new ArrayList<String>();
String pathtofind;
if(((arg0[0].equals("NA"))) && ((arg0[1].equals("NA"))) && ((arg0[2].equals("NA"))) )
{
for(String fn:filePathtobeSearched)
{
filewhichContainsconstraint.add(fn);
}
}
else if(((arg0[0].equals("NA"))) && ((arg0[1].equals("NA"))) && (!(arg0[2].equals("NA"))))
{
String psd =arg0[2];
for(String fn:filePathtobeSearched)
{
if(fn.contains(psd))
{
filewhichContainsconstraint.add(fn);
}
}
}
else if(((arg0[0].equals("NA"))) && (!(arg0[1].equals("NA"))) && ((arg0[2].equals("NA"))))
{
String psd =arg0[1];
for(String fn:filePathtobeSearched)
{
if(fn.contains(psd))
{
filewhichContainsconstraint.add(fn);
}
}
}
else if((!(arg0[0].equals("NA"))) && ((arg0[1].equals("NA"))) && ((arg0[2].equals("NA"))))
{
String psd =arg0[0];
for(String fn:filePathtobeSearched)
{
if(fn.startsWith(psd))
{
filewhichContainsconstraint.add(fn);
}
}
}
else if(((arg0[0].equals("NA"))) && (!(arg0[1].equals("NA"))) && (!(arg0[2].equals("NA"))))
{
String psd =arg0[1];
String psd1 =arg0[2];
for(String fn:filePathtobeSearched)
{
if(fn.startsWith(psd) && fn.contains(psd1))
{
filewhichContainsconstraint.add(fn);
}
}
}
else if((!(arg0[0].equals("NA"))) && ((arg0[1].equals("NA"))) && (!(arg0[2].equals("NA"))))
{
String psd =arg0[0];
String psd1 =arg0[2];
for(String fn:filePathtobeSearched)
{
if(fn.startsWith(psd) && fn.contains(psd1))
{
filewhichContainsconstraint.add(fn);
}
}
}
else if((!(arg0[0].equals("NA"))) && (!(arg0[1].equals("NA"))) && ((arg0[2].equals("NA"))))
{
String psd =arg0[0];
String psd1 =arg0[1];
for(String fn:filePathtobeSearched)
{
if(fn.startsWith(psd) && fn.contains(psd1))
{
filewhichContainsconstraint.add(fn);
}
}
}
else if((!(arg0[0].equals("NA"))) && (!(arg0[1].equals("NA"))) && (!(arg0[2].equals("NA"))))
{
String psd =arg0[0];
String psd1 =arg0[1];
String psd2 =arg0[2];
for(String fn:filePathtobeSearched)
{
if(fn.startsWith(psd) && fn.contains(psd1) && fn.contains(psd2))
{
filewhichContainsconstraint.add(fn);
}
}
}
if(filewhichContainsconstraint.size()>0)
{
for(String fds:filewhichContainsconstraint)
{
System.out.println(fds);
}
JobConf conf = new JobConf(getConf(), WordCount.class);
conf.setJobName("WordCount");
conf.set("date", arg0[3]);
conf.set("fileformat", arg0[4]);
conf.set("username", arg0[5]);
conf.set("size", arg0[6]);
conf.set("timestmp", arg0[7]);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(Text.class);
conf.setMapperClass(searchwithspecificReqMapper.class);
String outputtopn = "/searchwithspecificReq";
if(hdfs.exists(new Path(outputtopn)))
{
hdfs.delete(new Path(outputtopn));
}
Path out = new Path(outputtopn);
for(String inputPathh: filewhichContainsconstraint)
{
FileInputFormat.addInputPath(conf, new Path("/metadata/"+inputPathh));
}
FileOutputFormat.setOutputPath(conf, out);
JobClient.runJob(conf);
}
else
{
System.out.println("Sorry No files matching to your Query");
}
//creating path for metastore selection file
return 0;
}
}