org.apache.hadoop.io.VIntWritable Java Examples

The following examples show how to use org.apache.hadoop.io.VIntWritable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IndexInfo.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void readFields(DataInput in) throws IOException {
    VLongWritable count = new VLongWritable();
    count.readFields(in);
    this.count = count.get();
    
    VIntWritable nUidsReader = new VIntWritable();
    nUidsReader.readFields(in);
    final int nUids = nUidsReader.get();
    
    ImmutableSortedSet.Builder<IndexMatch> setBuilder = ImmutableSortedSet.naturalOrder();
    
    for (int i = 0; i < nUids; ++i) {
        IndexMatch index = new IndexMatch();
        index.readFields(in);
        setBuilder.add(index);
    }
    this.uids = setBuilder.build();
}
 
Example #2
Source File: TypedBytesWritableInput.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public Class<? extends Writable> readType() throws IOException {
  Type type = in.readType();
  if (type == null) {
    return null;
  }
  switch (type) {
  case BYTES:
    return BytesWritable.class;
  case BYTE:
    return ByteWritable.class;
  case BOOL:
    return BooleanWritable.class;
  case INT:
    return VIntWritable.class;
  case LONG:
    return VLongWritable.class;
  case FLOAT:
    return FloatWritable.class;
  case DOUBLE:
    return DoubleWritable.class;
  case STRING:
    return Text.class;
  case VECTOR:
    return ArrayWritable.class;
  case MAP:
    return MapWritable.class;
  case WRITABLE:
    return Writable.class;
  default:
    throw new RuntimeException("unknown type");
  }
}
 
Example #3
Source File: WritableUtils.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
public static Writable toWritable(Object object) {
    if (object == null) {
        return null; //return NullWritable.get();
    }
    if (object instanceof Writable) {
        return (Writable) object;
    }
    if (object instanceof String) {
        return new Text((String) object);
    }
    if (object instanceof Long) {
        return new VLongWritable((Long) object);
    }
    if (object instanceof Integer) {
        return new VIntWritable((Integer) object);
    }
    if (object instanceof Byte) {
        return new ByteWritable((Byte) object);
    }
    if (object instanceof Double) {
        return new DoubleWritable((Double) object);
    }
    if (object instanceof Float) {
        return new FloatWritable((Float) object);
    }
    if (object instanceof Boolean) {
        return new BooleanWritable((Boolean) object);
    }
    if (object instanceof byte[]) {
        return new BytesWritable((byte[]) object);
    }
    return new BytesWritable(object.toString().getBytes());
}
 
Example #4
Source File: TypedBytesWritableInput.java    From big-c with Apache License 2.0 5 votes vote down vote up
public Class<? extends Writable> readType() throws IOException {
  Type type = in.readType();
  if (type == null) {
    return null;
  }
  switch (type) {
  case BYTES:
    return BytesWritable.class;
  case BYTE:
    return ByteWritable.class;
  case BOOL:
    return BooleanWritable.class;
  case INT:
    return VIntWritable.class;
  case LONG:
    return VLongWritable.class;
  case FLOAT:
    return FloatWritable.class;
  case DOUBLE:
    return DoubleWritable.class;
  case STRING:
    return Text.class;
  case VECTOR:
    return ArrayWritable.class;
  case MAP:
    return MapWritable.class;
  case WRITABLE:
    return Writable.class;
  default:
    throw new RuntimeException("unknown type");
  }
}
 
Example #5
Source File: TypedBytesWritableOutput.java    From big-c with Apache License 2.0 5 votes vote down vote up
public void write(Writable w) throws IOException {
  if (w instanceof TypedBytesWritable) {
    writeTypedBytes((TypedBytesWritable) w);
  } else if (w instanceof BytesWritable) {
    writeBytes((BytesWritable) w);
  } else if (w instanceof ByteWritable) {
    writeByte((ByteWritable) w);
  } else if (w instanceof BooleanWritable) {
    writeBoolean((BooleanWritable) w);
  } else if (w instanceof IntWritable) {
    writeInt((IntWritable) w);
  } else if (w instanceof VIntWritable) {
    writeVInt((VIntWritable) w);
  } else if (w instanceof LongWritable) {
    writeLong((LongWritable) w);
  } else if (w instanceof VLongWritable) {
    writeVLong((VLongWritable) w);
  } else if (w instanceof FloatWritable) {
    writeFloat((FloatWritable) w);
  } else if (w instanceof DoubleWritable) {
    writeDouble((DoubleWritable) w);
  } else if (w instanceof Text) {
    writeText((Text) w);
  } else if (w instanceof ArrayWritable) {
    writeArray((ArrayWritable) w);
  } else if (w instanceof MapWritable) {
    writeMap((MapWritable) w);
  } else if (w instanceof SortedMapWritable) {
    writeSortedMap((SortedMapWritable) w);
  } else if (w instanceof Record) {
    writeRecord((Record) w);
  } else {
    writeWritable(w); // last resort
  }
}
 
Example #6
Source File: InternalUtilities.java    From marklogic-contentpump with Apache License 2.0 5 votes vote down vote up
/**
 * Create new XdmValue from value type and Writables.
 *  
 */
public static XdmValue newValue(ValueType valueType, Object value) {
    if (value instanceof Text) {
        return ValueFactory.newValue(valueType, ((Text)value).toString());
    } else if (value instanceof BytesWritable) {
        return ValueFactory.newValue(valueType, ((BytesWritable)value).getBytes());
    } else if (value instanceof IntWritable) {
        return ValueFactory.newValue(valueType, ((IntWritable)value).get());
    } else if (value instanceof LongWritable) {
        return ValueFactory.newValue(valueType, ((LongWritable)value).get());
    } else if (value instanceof VIntWritable) {
        return ValueFactory.newValue(valueType, ((VIntWritable)value).get());
    } else if (value instanceof VLongWritable) {
        return ValueFactory.newValue(valueType, ((VLongWritable)value).get());
    } else if (value instanceof BooleanWritable) {
        return ValueFactory.newValue(valueType, ((BooleanWritable)value).get());
    } else if (value instanceof FloatWritable) {
        return ValueFactory.newValue(valueType, ((FloatWritable)value).get());
    } else if (value instanceof DoubleWritable) {
        return ValueFactory.newValue(valueType, ((DoubleWritable)value).get());
    } else if (value instanceof MarkLogicNode) {
        return ValueFactory.newValue(valueType, ((MarkLogicNode)value).get());
    } else {
        throw new UnsupportedOperationException("Value " +  
                value.getClass().getName() + " is unsupported.");
    }
}
 
Example #7
Source File: IndexInfo.java    From datawave with Apache License 2.0 5 votes vote down vote up
@Override
public void write(DataOutput out) throws IOException {
    new VLongWritable(count).write(out);
    new VIntWritable(uids.size()).write(out);
    for (IndexMatch uid : uids)
        uid.write(out);
}
 
Example #8
Source File: TypedBytesWritableOutput.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public void write(Writable w) throws IOException {
  if (w instanceof TypedBytesWritable) {
    writeTypedBytes((TypedBytesWritable) w);
  } else if (w instanceof BytesWritable) {
    writeBytes((BytesWritable) w);
  } else if (w instanceof ByteWritable) {
    writeByte((ByteWritable) w);
  } else if (w instanceof BooleanWritable) {
    writeBoolean((BooleanWritable) w);
  } else if (w instanceof IntWritable) {
    writeInt((IntWritable) w);
  } else if (w instanceof VIntWritable) {
    writeVInt((VIntWritable) w);
  } else if (w instanceof LongWritable) {
    writeLong((LongWritable) w);
  } else if (w instanceof VLongWritable) {
    writeVLong((VLongWritable) w);
  } else if (w instanceof FloatWritable) {
    writeFloat((FloatWritable) w);
  } else if (w instanceof DoubleWritable) {
    writeDouble((DoubleWritable) w);
  } else if (w instanceof Text) {
    writeText((Text) w);
  } else if (w instanceof ArrayWritable) {
    writeArray((ArrayWritable) w);
  } else if (w instanceof MapWritable) {
    writeMap((MapWritable) w);
  } else if (w instanceof SortedMapWritable) {
    writeSortedMap((SortedMapWritable) w);
  } else if (w instanceof Record) {
    writeRecord((Record) w);
  } else {
    writeWritable(w); // last resort
  }
}
 
Example #9
Source File: StatsCounters.java    From datawave with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a shard stats for a field name/datatype pair.
 *
 * @param sumCount
 *            total number of values
 * @param unique
 *            total number of unique values
 */
StatsCounters(long sumCount, long unique) {
    this.count = new VLongWritable(sumCount);
    int selVal;
    // hyperlog unique count could be greater than total count
    if (unique < sumCount) {
        this.uniqueCount = new VLongWritable(unique);
        selVal = (int) ((float) unique / (float) sumCount * SELECTIVITY_MULTIPLIER);
    } else {
        // use total count if unique is > total
        this.uniqueCount = new VLongWritable(sumCount);
        selVal = SELECTIVITY_MULTIPLIER;
    }
    this.selectivity = new VIntWritable(selVal);
}
 
Example #10
Source File: TypedBytesWritableOutput.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public void writeVInt(VIntWritable viw) throws IOException {
  out.writeInt(viw.get());
}
 
Example #11
Source File: TypedBytesWritableInput.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public VIntWritable readVInt() throws IOException {
  return readVInt(null);
}
 
Example #12
Source File: StatsHyperLogSummary.java    From datawave with Apache License 2.0 4 votes vote down vote up
StatsHyperLogSummary() {
    this.count = new VLongWritable();
    this.hyperLog = new BytesWritable();
    this.uniqueCount = new VIntWritable();
}
 
Example #13
Source File: TypedBytesWritableOutput.java    From big-c with Apache License 2.0 4 votes vote down vote up
public void writeVInt(VIntWritable viw) throws IOException {
  out.writeInt(viw.get());
}
 
Example #14
Source File: TypedBytesWritableInput.java    From big-c with Apache License 2.0 4 votes vote down vote up
public VIntWritable readVInt() throws IOException {
  return readVInt(null);
}
 
Example #15
Source File: StatsCounters.java    From datawave with Apache License 2.0 4 votes vote down vote up
public StatsCounters() {
    this.count = new VLongWritable();
    this.uniqueCount = new VLongWritable();
    this.selectivity = new VIntWritable();
}
 
Example #16
Source File: WritableTypeToJsonTest.java    From elasticsearch-hadoop with Apache License 2.0 4 votes vote down vote up
@Test
public void testVInteger() {
    writableTypeToJson(new VIntWritable(Integer.MAX_VALUE));
}
 
Example #17
Source File: StatsHyperLogSummary.java    From datawave with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a stats HyperLog summary object.
 * 
 * @param sumCount
 *            total number of field name/dataype pair entries
 * @param logPlus
 *            populated hyperlog object
 * @param uniqueCount
 *            actual count of unique values (debug only)
 * @throws IOException
 *             serialization error
 */
StatsHyperLogSummary(long sumCount, HyperLogLogPlus logPlus, int uniqueCount) throws IOException {
    this.count = new VLongWritable(sumCount);
    this.hyperLog = new BytesWritable(logPlus.getBytes());
    this.uniqueCount = new VIntWritable(uniqueCount);
}