List of usage examples for org.apache.hadoop.mapreduce TaskAttemptID TaskAttemptID
public TaskAttemptID(TaskID taskId, int id)
From source file:org.apache.carbondata.sdk.file.AvroCarbonWriter.java
License:Apache License
AvroCarbonWriter(CarbonLoadModel loadModel, Configuration hadoopConf) throws IOException { CarbonTableOutputFormat.setLoadModel(hadoopConf, loadModel); CarbonTableOutputFormat format = new CarbonTableOutputFormat(); JobID jobId = new JobID(UUID.randomUUID().toString(), 0); Random random = new Random(); TaskID task = new TaskID(jobId, TaskType.MAP, random.nextInt()); TaskAttemptID attemptID = new TaskAttemptID(task, random.nextInt()); TaskAttemptContextImpl context = new TaskAttemptContextImpl(hadoopConf, attemptID); this.recordWriter = format.getRecordWriter(context); this.context = context; this.writable = new ObjectArrayWritable(); }
From source file:org.apache.carbondata.sdk.file.CSVCarbonWriter.java
License:Apache License
CSVCarbonWriter(CarbonLoadModel loadModel, Configuration hadoopConf) throws IOException { CarbonTableOutputFormat.setLoadModel(hadoopConf, loadModel); CarbonTableOutputFormat format = new CarbonTableOutputFormat(); JobID jobId = new JobID(UUID.randomUUID().toString(), 0); Random random = new Random(); TaskID task = new TaskID(jobId, TaskType.MAP, random.nextInt()); TaskAttemptID attemptID = new TaskAttemptID(task, random.nextInt()); TaskAttemptContextImpl context = new TaskAttemptContextImpl(hadoopConf, attemptID); this.recordWriter = format.getRecordWriter(context); this.context = context; this.writable = new ObjectArrayWritable(); }
From source file:org.apache.carbondata.sdk.file.JsonCarbonWriter.java
License:Apache License
JsonCarbonWriter(CarbonLoadModel loadModel, Configuration configuration) throws IOException { CarbonTableOutputFormat.setLoadModel(configuration, loadModel); CarbonTableOutputFormat outputFormat = new CarbonTableOutputFormat(); JobID jobId = new JobID(UUID.randomUUID().toString(), 0); Random random = new Random(); TaskID task = new TaskID(jobId, TaskType.MAP, random.nextInt()); TaskAttemptID attemptID = new TaskAttemptID(task, random.nextInt()); TaskAttemptContextImpl context = new TaskAttemptContextImpl(configuration, attemptID); this.recordWriter = outputFormat.getRecordWriter(context); this.context = context; this.writable = new ObjectArrayWritable(); }
From source file:org.apache.carbondata.stream.CarbonStreamRecordReaderTest.java
License:Apache License
@Override protected void setUp() throws Exception { tablePath = new File("target/stream_input").getCanonicalPath(); String dbName = "default"; String tableName = "stream_table_input"; identifier = AbsoluteTableIdentifier.from(tablePath, new CarbonTableIdentifier(dbName, tableName, UUID.randomUUID().toString())); JobID jobId = CarbonInputFormatUtil.getJobId(new Date(), 0); TaskID taskId = new TaskID(jobId, TaskType.MAP, 0); taskAttemptId = new TaskAttemptID(taskId, 0); hadoopConf = new Configuration(); taskAttemptContext = new TaskAttemptContextImpl(hadoopConf, taskAttemptId); }
From source file:org.apache.carbondata.streaming.CarbonStreamOutputFormatTest.java
License:Apache License
@Override protected void setUp() throws Exception { super.setUp(); JobID jobId = CarbonInputFormatUtil.getJobId(new Date(), 0); TaskID taskId = new TaskID(jobId, TaskType.MAP, 0); taskAttemptId = new TaskAttemptID(taskId, 0); hadoopConf = new Configuration(); hadoopConf.set("mapred.job.id", jobId.toString()); hadoopConf.set("mapred.tip.id", taskAttemptId.getTaskID().toString()); hadoopConf.set("mapred.task.id", taskAttemptId.toString()); hadoopConf.setBoolean("mapred.task.is.map", true); hadoopConf.setInt("mapred.task.partition", 0); tablePath = new File("target/stream_output").getCanonicalPath(); String dbName = "default"; String tableName = "stream_table_output"; AbsoluteTableIdentifier identifier = AbsoluteTableIdentifier.from(tablePath, new CarbonTableIdentifier(dbName, tableName, UUID.randomUUID().toString())); CarbonTable table = new StoreCreator(new File("target/store").getAbsolutePath(), new File("../hadoop/src/test/resources/data.csv").getCanonicalPath()).createTable(identifier); String factFilePath = new File("../hadoop/src/test/resources/data.csv").getCanonicalPath(); carbonLoadModel = StoreCreator.buildCarbonLoadModel(table, factFilePath, identifier); }
From source file:org.apache.hcatalog.data.transfer.impl.HCatOutputFormatWriter.java
License:Apache License
@Override public void write(Iterator<HCatRecord> recordItr) throws HCatException { int id = sp.getId(); setVarsInConf(id);/* www. ja v a 2s . c o m*/ HCatOutputFormat outFormat = new HCatOutputFormat(); TaskAttemptContext cntxt = HCatHadoopShims.Instance.get().createTaskAttemptContext(conf, new TaskAttemptID(HCatHadoopShims.Instance.get().createTaskID(), id)); OutputCommitter committer = null; RecordWriter<WritableComparable<?>, HCatRecord> writer; try { committer = outFormat.getOutputCommitter(cntxt); committer.setupTask(cntxt); writer = outFormat.getRecordWriter(cntxt); while (recordItr.hasNext()) { HCatRecord rec = recordItr.next(); writer.write(null, rec); } writer.close(cntxt); if (committer.needsTaskCommit(cntxt)) { committer.commitTask(cntxt); } } catch (IOException e) { if (null != committer) { try { committer.abortTask(cntxt); } catch (IOException e1) { throw new HCatException(ErrorType.ERROR_INTERNAL_EXCEPTION, e1); } } throw new HCatException("Failed while writing", e); } catch (InterruptedException e) { if (null != committer) { try { committer.abortTask(cntxt); } catch (IOException e1) { throw new HCatException(ErrorType.ERROR_INTERNAL_EXCEPTION, e1); } } throw new HCatException("Failed while writing", e); } }
From source file:org.apache.hive.hcatalog.data.transfer.impl.HCatOutputFormatWriter.java
License:Apache License
@Override public void write(Iterator<HCatRecord> recordItr) throws HCatException { int id = sp.getId(); setVarsInConf(id);/*ww w .j a v a2s .c o m*/ HCatOutputFormat outFormat = new HCatOutputFormat(); TaskAttemptContext cntxt = ShimLoader.getHadoopShims().getHCatShim().createTaskAttemptContext(conf, new TaskAttemptID(ShimLoader.getHadoopShims().getHCatShim().createTaskID(), id)); OutputCommitter committer = null; RecordWriter<WritableComparable<?>, HCatRecord> writer; try { committer = outFormat.getOutputCommitter(cntxt); committer.setupTask(cntxt); writer = outFormat.getRecordWriter(cntxt); while (recordItr.hasNext()) { HCatRecord rec = recordItr.next(); writer.write(null, rec); } writer.close(cntxt); if (committer.needsTaskCommit(cntxt)) { committer.commitTask(cntxt); } } catch (IOException e) { if (null != committer) { try { committer.abortTask(cntxt); } catch (IOException e1) { throw new HCatException(ErrorType.ERROR_INTERNAL_EXCEPTION, e1); } } throw new HCatException("Failed while writing", e); } catch (InterruptedException e) { if (null != committer) { try { committer.abortTask(cntxt); } catch (IOException e1) { throw new HCatException(ErrorType.ERROR_INTERNAL_EXCEPTION, e1); } } throw new HCatException("Failed while writing", e); } }
From source file:org.apache.parquet.hadoop.codec.CodecConfigTest.java
License:Apache License
public void shouldUseParquetFlagToSetCodec(String codecNameStr, CompressionCodecName expectedCodec) throws IOException { //Test mapreduce API Job job = new Job(); Configuration conf = job.getConfiguration(); conf.set(ParquetOutputFormat.COMPRESSION, codecNameStr); TaskAttemptContext task = ContextUtil.newTaskAttemptContext(conf, new TaskAttemptID(new TaskID(new JobID("test", 1), false, 1), 1)); Assert.assertEquals(CodecConfig.from(task).getCodec(), expectedCodec); //Test mapred API JobConf jobConf = new JobConf(); jobConf.set(ParquetOutputFormat.COMPRESSION, codecNameStr); Assert.assertEquals(CodecConfig.from(jobConf).getCodec(), expectedCodec); }
From source file:org.apache.parquet.hadoop.codec.CodecConfigTest.java
License:Apache License
public void shouldUseHadoopFlagToSetCodec(String codecClassStr, CompressionCodecName expectedCodec) throws IOException { //Test mapreduce API Job job = new Job(); Configuration conf = job.getConfiguration(); conf.setBoolean("mapred.output.compress", true); conf.set("mapred.output.compression.codec", codecClassStr); TaskAttemptContext task = ContextUtil.newTaskAttemptContext(conf, new TaskAttemptID(new TaskID(new JobID("test", 1), false, 1), 1)); Assert.assertEquals(expectedCodec, CodecConfig.from(task).getCodec()); //Test mapred API JobConf jobConf = new JobConf(); jobConf.setBoolean("mapred.output.compress", true); jobConf.set("mapred.output.compression.codec", codecClassStr); Assert.assertEquals(CodecConfig.from(jobConf).getCodec(), expectedCodec); }
From source file:org.apache.rya.accumulo.mr.GraphXEdgeInputFormatTest.java
License:Apache License
@SuppressWarnings("rawtypes") @Test/* w w w. jav a 2s .c om*/ public void testInputFormat() throws Exception { RyaStatement input = RyaStatement.builder().setSubject(new RyaURI("http://www.google.com")) .setPredicate(new RyaURI("http://some_other_uri")).setObject(new RyaURI("http://www.yahoo.com")) .setColumnVisibility(new byte[0]).setValue(new byte[0]).build(); apiImpl.add(input); Job jobConf = Job.getInstance(); GraphXEdgeInputFormat.setMockInstance(jobConf, instance.getInstanceName()); GraphXEdgeInputFormat.setConnectorInfo(jobConf, username, password); GraphXEdgeInputFormat.setTableLayout(jobConf, TABLE_LAYOUT.SPO); GraphXEdgeInputFormat.setInputTableName(jobConf, table); GraphXEdgeInputFormat.setInputTableName(jobConf, table); GraphXEdgeInputFormat.setScanIsolation(jobConf, false); GraphXEdgeInputFormat.setLocalIterators(jobConf, false); GraphXEdgeInputFormat.setOfflineTableScan(jobConf, false); GraphXEdgeInputFormat inputFormat = new GraphXEdgeInputFormat(); JobContext context = new JobContextImpl(jobConf.getConfiguration(), jobConf.getJobID()); List<InputSplit> splits = inputFormat.getSplits(context); Assert.assertEquals(1, splits.size()); TaskAttemptContext taskAttemptContext = new TaskAttemptContextImpl(context.getConfiguration(), new TaskAttemptID(new TaskID(), 1)); RecordReader reader = inputFormat.createRecordReader(splits.get(0), taskAttemptContext); RecordReader ryaStatementRecordReader = (RecordReader) reader; ryaStatementRecordReader.initialize(splits.get(0), taskAttemptContext); List<Edge> results = new ArrayList<Edge>(); while (ryaStatementRecordReader.nextKeyValue()) { Edge writable = (Edge) ryaStatementRecordReader.getCurrentValue(); long srcId = writable.srcId(); long destId = writable.dstId(); RyaTypeWritable rtw = null; Object text = ryaStatementRecordReader.getCurrentKey(); Edge<RyaTypeWritable> edge = new Edge<RyaTypeWritable>(srcId, destId, rtw); results.add(edge); System.out.println(text); } System.out.println(results.size()); System.out.println(results); Assert.assertTrue(results.size() == 2); }