use of org.apache.hadoop.io.BooleanWritable in project hive by apache.
the class RecordReaderImpl method nextBoolean.
/* Routines for stubbing into Writables */
static BooleanWritable nextBoolean(ColumnVector vector, int row, Object previous) {
if (vector.isRepeating) {
row = 0;
}
if (vector.noNulls || !vector.isNull[row]) {
BooleanWritable result;
if (previous == null || previous.getClass() != BooleanWritable.class) {
result = new BooleanWritable();
} else {
result = (BooleanWritable) previous;
}
result.set(((LongColumnVector) vector).vector[row] != 0);
return result;
} else {
return null;
}
}
use of org.apache.hadoop.io.BooleanWritable in project hive by apache.
the class GenericUDFReflect2 method evaluate.
@Override
public Object evaluate(DeferredObject[] arguments) throws HiveException {
Object targetObject = targetOI.getPrimitiveJavaObject(arguments[0].get());
if (targetObject == null) {
return null;
}
Object result = null;
try {
result = method.invoke(targetObject, setupParameters(arguments, 2));
} catch (InvocationTargetException e) {
throw new HiveException(e.getCause());
} catch (Exception e) {
throw new HiveException(e);
}
if (result == null) {
return null;
}
switch(returnOI.getPrimitiveCategory()) {
case VOID:
return null;
case BOOLEAN:
((BooleanWritable) returnObj).set((Boolean) result);
return returnObj;
case BYTE:
((ByteWritable) returnObj).set((Byte) result);
return returnObj;
case SHORT:
((ShortWritable) returnObj).set((Short) result);
return returnObj;
case INT:
((IntWritable) returnObj).set((Integer) result);
return returnObj;
case LONG:
((LongWritable) returnObj).set((Long) result);
return returnObj;
case FLOAT:
((FloatWritable) returnObj).set((Float) result);
return returnObj;
case DOUBLE:
((DoubleWritable) returnObj).set((Double) result);
return returnObj;
case STRING:
((Text) returnObj).set((String) result);
return returnObj;
case TIMESTAMP:
((TimestampWritable) returnObj).set((Timestamp) result);
return returnObj;
case BINARY:
((BytesWritable) returnObj).set((byte[]) result, 0, ((byte[]) result).length);
return returnObj;
case DECIMAL:
((HiveDecimalWritable) returnObj).set((HiveDecimal) result);
return returnObj;
}
throw new HiveException("Invalid type " + returnOI.getPrimitiveCategory());
}
use of org.apache.hadoop.io.BooleanWritable in project hive by apache.
the class TypedBytesSerDe method serializeField.
private void serializeField(Object o, ObjectInspector oi, Object reuse) throws IOException {
switch(oi.getCategory()) {
case PRIMITIVE:
{
PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi;
switch(poi.getPrimitiveCategory()) {
case VOID:
{
return;
}
case BOOLEAN:
{
BooleanObjectInspector boi = (BooleanObjectInspector) poi;
BooleanWritable r = reuse == null ? new BooleanWritable() : (BooleanWritable) reuse;
r.set(boi.get(o));
tbOut.write(r);
return;
}
case BYTE:
{
ByteObjectInspector boi = (ByteObjectInspector) poi;
ByteWritable r = reuse == null ? new ByteWritable() : (ByteWritable) reuse;
r.set(boi.get(o));
tbOut.write(r);
return;
}
case SHORT:
{
ShortObjectInspector spoi = (ShortObjectInspector) poi;
ShortWritable r = reuse == null ? new ShortWritable() : (ShortWritable) reuse;
r.set(spoi.get(o));
tbOut.write(r);
return;
}
case INT:
{
IntObjectInspector ioi = (IntObjectInspector) poi;
IntWritable r = reuse == null ? new IntWritable() : (IntWritable) reuse;
r.set(ioi.get(o));
tbOut.write(r);
return;
}
case LONG:
{
LongObjectInspector loi = (LongObjectInspector) poi;
LongWritable r = reuse == null ? new LongWritable() : (LongWritable) reuse;
r.set(loi.get(o));
tbOut.write(r);
return;
}
case FLOAT:
{
FloatObjectInspector foi = (FloatObjectInspector) poi;
FloatWritable r = reuse == null ? new FloatWritable() : (FloatWritable) reuse;
r.set(foi.get(o));
tbOut.write(r);
return;
}
case DOUBLE:
{
DoubleObjectInspector doi = (DoubleObjectInspector) poi;
DoubleWritable r = reuse == null ? new DoubleWritable() : (DoubleWritable) reuse;
r.set(doi.get(o));
tbOut.write(r);
return;
}
case STRING:
{
StringObjectInspector soi = (StringObjectInspector) poi;
Text t = soi.getPrimitiveWritableObject(o);
tbOut.write(t);
return;
}
default:
{
throw new RuntimeException("Unrecognized type: " + poi.getPrimitiveCategory());
}
}
}
case LIST:
case MAP:
case STRUCT:
{
// For complex object, serialize to JSON format
String s = SerDeUtils.getJSONString(o, oi);
Text t = reuse == null ? new Text() : (Text) reuse;
// convert to Text and write it
t.set(s);
tbOut.write(t);
}
default:
{
throw new RuntimeException("Unrecognized type: " + oi.getCategory());
}
}
}
use of org.apache.hadoop.io.BooleanWritable in project hive by apache.
the class TypedBytesSerDe method deserializeField.
static Object deserializeField(TypedBytesWritableInput in, TypeInfo type, Object reuse) throws IOException {
// read the type
Class<? extends Writable> writableType = in.readType();
if (writableType != null && writableType.isAssignableFrom(NullWritable.class)) {
// indicates that the recorded value is null
return null;
}
switch(type.getCategory()) {
case PRIMITIVE:
{
PrimitiveTypeInfo ptype = (PrimitiveTypeInfo) type;
switch(ptype.getPrimitiveCategory()) {
case VOID:
{
return null;
}
case BOOLEAN:
{
BooleanWritable r = reuse == null ? new BooleanWritable() : (BooleanWritable) reuse;
r = in.readBoolean(r);
return r;
}
case BYTE:
{
ByteWritable r = reuse == null ? new ByteWritable() : (ByteWritable) reuse;
r = in.readByte(r);
return r;
}
case SHORT:
{
ShortWritable r = reuse == null ? new ShortWritable() : (ShortWritable) reuse;
r = in.readShort(r);
return r;
}
case INT:
{
IntWritable r = reuse == null ? new IntWritable() : (IntWritable) reuse;
r = in.readInt(r);
return r;
}
case LONG:
{
LongWritable r = reuse == null ? new LongWritable() : (LongWritable) reuse;
r = in.readLong(r);
return r;
}
case FLOAT:
{
FloatWritable r = reuse == null ? new FloatWritable() : (FloatWritable) reuse;
r = in.readFloat(r);
return r;
}
case DOUBLE:
{
DoubleWritable r = reuse == null ? new DoubleWritable() : (DoubleWritable) reuse;
r = in.readDouble(r);
return r;
}
case STRING:
{
Text r = reuse == null ? new Text() : (Text) reuse;
r = in.readText(r);
return r;
}
default:
{
throw new RuntimeException("Unrecognized type: " + ptype.getPrimitiveCategory());
}
}
}
// Currently, deserialization of complex types is not supported
case LIST:
case MAP:
case STRUCT:
default:
{
throw new RuntimeException("Unsupported category: " + type.getCategory());
}
}
}
use of org.apache.hadoop.io.BooleanWritable in project hive by apache.
the class ColumnarStorageBench method getPrimitiveWritable.
private Writable getPrimitiveWritable(final PrimitiveTypeInfo typeInfo) {
Random rand = new Random();
switch(typeInfo.getPrimitiveCategory()) {
case INT:
return new IntWritable(rand.nextInt());
case DOUBLE:
return new DoubleWritable(rand.nextDouble());
case BOOLEAN:
return new BooleanWritable(rand.nextBoolean());
case CHAR:
case VARCHAR:
case STRING:
byte[] b = new byte[30];
rand.nextBytes(b);
return new BytesWritable(b);
default:
throw new IllegalArgumentException("Invalid primitive type: " + typeInfo.getTypeName());
}
}
Aggregations