} catch (HIHOException e1) {
e1.printStackTrace();
throw new IOException(e1);
}
Job job = new Job(conf);
for (Entry<String, String> entry : conf) {
logger.warn("key, value " + entry.getKey() + "=" + entry.getValue());
}
// logger.debug("Number of maps " +
// conf.getInt("mapred.map.tasks", 1));
// conf.setInt(JobContext.NUM_MAPS,
// conf.getInt("mapreduce.job.maps", 1));
// job.getConfiguration().setInt("mapred.map.tasks", 4);
job.getConfiguration().setInt(MRJobConfig.NUM_MAPS,
conf.getInt(HIHOConf.NUMBER_MAPPERS, 1));
logger.warn("Number of maps " + conf.getInt(MRJobConfig.NUM_MAPS, 1));
job.setJobName("Import job");
job.setJarByClass(DBQueryInputJob.class);
String strategy = conf.get(HIHOConf.INPUT_OUTPUT_STRATEGY);
OutputStrategyEnum os = OutputStrategyEnum.value(strategy);
if (os == null) {
throw new IllegalArgumentException(
"Wrong value of output strategy. Please correct");
}
if (os != OutputStrategyEnum.AVRO) {
switch (os) {
case DUMP: {
// job.setMapperClass(DBImportMapper.class);
break;
}
/*
* case AVRO: { job.setMapperClass(DBInputAvroMapper.class); //
* need avro in cp // job.setJarByClass(Schema.class); // need
* jackson which is needed by avro - ugly! //
* job.setJarByClass(ObjectMapper.class);
* job.setMapOutputKeyClass(NullWritable.class);
* job.setMapOutputValueClass(AvroValue.class);
* job.setOutputKeyClass(NullWritable.class);
* job.setOutputValueClass(AvroValue.class);
* job.setOutputFormatClass(AvroOutputFormat.class);
*
* AvroOutputFormat.setOutputPath(job, new
* Path(getConf().get(HIHOConf.INPUT_OUTPUT_PATH))); break; }
*/
case DELIMITED: {
job.setMapperClass(DBInputDelimMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setOutputFormatClass(NoKeyOnlyValueOutputFormat.class);
NoKeyOnlyValueOutputFormat.setOutputPath(job, new Path(
getConf().get(HIHOConf.INPUT_OUTPUT_PATH)));
}
case JSON: {
// job.setMapperClass(DBImportJsonMapper.class);
// job.setJarByClass(ObjectMapper.class);
break;
}
default: {
job.setMapperClass(DBInputDelimMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setOutputFormatClass(NoKeyOnlyValueOutputFormat.class);
NoKeyOnlyValueOutputFormat.setOutputPath(job, new Path(
getConf().get(HIHOConf.INPUT_OUTPUT_PATH)));
break;
}
}
String inputQuery = conf.get(DBConfiguration.INPUT_QUERY);
String inputBoundingQuery = conf
.get(DBConfiguration.INPUT_BOUNDING_QUERY);
logger.debug("About to set the params");
DBQueryInputFormat.setInput(job, inputQuery, inputBoundingQuery,
params);
logger.debug("Set the params");
job.setNumReduceTasks(0);
try {
// job.setJarByClass(Class.forName(conf.get(
// org.apache.hadoop.mapred.lib.db.DBConfiguration.DRIVER_CLASS_PROPERTY)));
logger.debug("OUTPUT format class is "
+ job.getOutputFormatClass());
/*
* org.apache.hadoop.mapreduce.OutputFormat<?, ?> output =
* ReflectionUtils.newInstance(job.getOutputFormatClass(),
* job.getConfiguration()); output.checkOutputSpecs(job);
*/
logger.debug("Class is "
+ ReflectionUtils
.newInstance(job.getOutputFormatClass(),
job.getConfiguration()).getClass()
.getName());
job.waitForCompletion(false);
if (conf.get(HIHOConf.INPUT_OUTPUT_LOADTO) != null) {
generateHiveScript(conf, job, jobCounter);
generatePigScript(conf, job);
}