List of usage examples for org.apache.hadoop.io LongWritable LongWritable
public LongWritable(long value)
From source file:com.hotels.corc.DefaultConverterFactoryTest.java
License:Apache License
@Test public void longJava() throws UnexpectedTypeException { Converter converter = factory.newConverter(PrimitiveObjectInspectorFactory.javaLongObjectInspector); assertThat(converter.toJavaObject(new LongWritable(1L)), is((Object) 1L)); }
From source file:com.hotels.corc.DefaultConverterFactoryTest.java
License:Apache License
@Test public void longWritable() throws UnexpectedTypeException { Converter converter = factory.newConverter(PrimitiveObjectInspectorFactory.javaLongObjectInspector); assertThat(converter.toWritableObject(1L), is((Object) new LongWritable(1L))); }
From source file:com.hotels.corc.DefaultConverterFactoryTest.java
License:Apache License
@Test public void unionStringLongJava() throws UnexpectedTypeException { List<TypeInfo> typeInfos = Arrays.asList((TypeInfo) TypeInfoFactory.stringTypeInfo, TypeInfoFactory.longTypeInfo); TypeInfo typeInfo = TypeInfoFactory.getUnionTypeInfo(typeInfos); Converter converter = getConverter(typeInfo); assertThat(converter.toJavaObject(null), is(nullValue())); assertThat(converter.toJavaObject(new StandardUnion((byte) 0, new Text("a"))), is((Object) "a")); assertThat(converter.toJavaObject(new StandardUnion((byte) 1, new LongWritable(1L))), is((Object) 1L)); try {//from w w w . j av a2s . c o m converter.toJavaObject(new StandardUnion((byte) 1, new IntWritable(1))); } catch (UnexpectedTypeException e) { return; } fail(); }
From source file:com.hotels.corc.DefaultConverterFactoryTest.java
License:Apache License
@Test public void unionStringLongWritable() throws UnexpectedTypeException { List<TypeInfo> typeInfos = Arrays.asList((TypeInfo) TypeInfoFactory.stringTypeInfo, TypeInfoFactory.longTypeInfo); TypeInfo typeInfo = TypeInfoFactory.getUnionTypeInfo(typeInfos); Converter converter = getConverter(typeInfo); assertThat(converter.toWritableObject(null), is(nullValue())); UnionObject union;// w ww . ja v a 2s . co m union = (UnionObject) converter.toWritableObject("a"); assertThat(union.getTag(), is((byte) 0)); assertThat(union.getObject(), is((Object) new Text("a"))); union = (UnionObject) converter.toWritableObject(1L); assertThat(union.getTag(), is((byte) 1)); assertThat(union.getObject(), is((Object) new LongWritable(1L))); try { converter.toWritableObject(1); } catch (UnexpectedTypeException e) { return; } fail(); }
From source file:com.hotels.corc.sarg.EvaluatorFactory.java
License:Apache License
static Comparable<?> toComparable(PrimitiveCategory category, Object literal) { String stringLiteral;/*from w w w . j ava2s. c o m*/ switch (category) { case STRING: return new Text((String) literal); case BOOLEAN: return new BooleanWritable((Boolean) literal); case BYTE: return new ByteWritable(((Long) literal).byteValue()); case SHORT: return new ShortWritable(((Long) literal).shortValue()); case INT: return new IntWritable(((Long) literal).intValue()); case LONG: return new LongWritable((Long) literal); case FLOAT: return new FloatWritable(((Double) literal).floatValue()); case DOUBLE: return new DoubleWritable((Double) literal); case TIMESTAMP: return new TimestampWritable((Timestamp) literal); case DATE: return (DateWritable) literal; case CHAR: stringLiteral = (String) literal; return new HiveCharWritable(new HiveChar(stringLiteral, stringLiteral.length())); case VARCHAR: stringLiteral = (String) literal; return new HiveVarcharWritable(new HiveVarchar(stringLiteral, stringLiteral.length())); case DECIMAL: return new HiveDecimalWritable(HiveDecimal.create((BigDecimal) literal)); default: throw new IllegalArgumentException("Unsupported category: " + category); } }
From source file:com.hotels.corc.sarg.EvaluatorFactoryTest.java
License:Apache License
@SuppressWarnings("rawtypes") @Test public void longTypical() { assertThat(toComparable(LONG, 0L), is((Comparable) new LongWritable(0L))); }
From source file:com.htuple.SecondarySortTest.java
License:Apache License
@Test public void testSecondarySort() throws IOException { Configuration conf = mapReduceDriver.getConfiguration(); SecondarySort.setupSecondarySort(conf); LongWritable dummyMapKey = new LongWritable(1); mapReduceDriver.withInput(dummyMapKey, new Text("Smith\tJohn\n")) .withInput(dummyMapKey, new Text("Smith\tAnne\n")).withInput(dummyMapKey, new Text("Smith\tKen\n")) .withOutput(new Text("Smith\tAnne\n"), NullWritable.get()) .withOutput(new Text("Smith\tJohn\n"), NullWritable.get()) .withOutput(new Text("Smith\tKen\n"), NullWritable.get()).runTest(true); }
From source file:com.huayu.metis.flume.sink.hdfs.HDFSTextSerializer.java
License:Apache License
private Object getKey(Event e) { // Write the data to HDFS String timestamp = e.getHeaders().get("timestamp"); long eventStamp; if (timestamp == null) { eventStamp = System.currentTimeMillis(); } else {//from www .j a v a 2 s.com eventStamp = Long.valueOf(timestamp); } return new LongWritable(eventStamp); }
From source file:com.huayu.metis.flume.sink.hdfs.HDFSWritableSerializer.java
License:Apache License
private Object getKey(Event e) { String timestamp = e.getHeaders().get("timestamp"); long eventStamp; if (timestamp == null) { eventStamp = System.currentTimeMillis(); } else {//from w w w . j ava 2s .co m eventStamp = Long.valueOf(timestamp); } return new LongWritable(eventStamp); }
From source file:com.ibm.bi.dml.runtime.controlprogram.parfor.RemoteParForUtils.java
License:Open Source License
/** * For remote MR parfor workers./*from ww w .ja v a 2 s . com*/ * * @param workerID * @param vars * @param resultVars * @param rvarFnames * @param out * @throws DMLRuntimeException * @throws IOException */ public static void exportResultVariables(long workerID, LocalVariableMap vars, ArrayList<String> resultVars, HashMap<String, String> rvarFnames, OutputCollector<Writable, Writable> out) throws DMLRuntimeException, IOException { //create key and value for reuse LongWritable okey = new LongWritable(workerID); Text ovalue = new Text(); //foreach result variables probe if export necessary for (String rvar : resultVars) { Data dat = vars.get(rvar); //export output variable to HDFS (see RunMRJobs) if (dat != null && dat.getDataType() == DataType.MATRIX) { MatrixObject mo = (MatrixObject) dat; if (mo.isDirty()) { if (ParForProgramBlock.ALLOW_REUSE_MR_PAR_WORKER && rvarFnames != null) { String fname = rvarFnames.get(rvar); if (fname != null) mo.setFileName(fname); //export result var (iff actually modified in parfor) mo.exportData(); //note: this is equivalent to doing it in close (currently not required because 1 Task=1Map tasks, hence only one map invocation) rvarFnames.put(rvar, mo.getFileName()); } else { //export result var (iff actually modified in parfor) mo.exportData(); //note: this is equivalent to doing it in close (currently not required because 1 Task=1Map tasks, hence only one map invocation) } //pass output vars (scalars by value, matrix by ref) to result //(only if actually exported, hence in check for dirty, otherwise potential problems in result merge) String datStr = ProgramConverter.serializeDataObject(rvar, mo); ovalue.set(datStr); out.collect(okey, ovalue); } } } }