public Text evaluate(IntWritable i) { if (i == null) { return null; } else { out.reset(); LazyInteger.writeUTF8NoException(out, i.get()); t.set(out.getData(), 0, out.getLength()); return t; } }
/** * Parses the string argument as if it was an int value and returns the * result. Throws NumberFormatException if the string does not represent an * int quantity. * * @param bytes * @param start * @param length * a UTF-8 encoded string representation of an int quantity. * @return int the value represented by the argument * @exception NumberFormatException * if the argument could not be parsed as an int quantity. */ public static int parseInt(byte[] bytes, int start, int length) { return parseInt(bytes, start, length, 10); }
@Override public Object copyObject(Object o) { return o == null ? null : new LazyInteger((LazyInteger) o); }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { data.set(parseInt(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "INT"); } }
@Test public void testLazy() throws HiveException { GenericUDFNullif udf = new GenericUDFNullif(); ObjectInspector[] inputOIs = { LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR, LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR }; LazyInteger a1 = new LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR); LazyInteger a2 = new LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR); a1.getWritableObject().set(1); a2.getWritableObject().set(1); DeferredObject[] args = { new DeferredJavaObject(a1), new DeferredJavaObject(a2) }; PrimitiveObjectInspector oi = (PrimitiveObjectInspector) udf.initialize(inputOIs); Assert.assertEquals(TypeInfoFactory.intTypeInfo, oi.getTypeInfo()); Assert.assertEquals(null, udf.evaluate(args)); } }
public static void writeUTF8NoException(OutputStream out, int i) { try { writeUTF8(out, i); } catch (IOException e) { throw new RuntimeException(e); } } }
return parse(bytes, start, length, offset, radix, negative);
throw new RuntimeException("Expected LazyInteger"); int value = ((LazyInteger) primitiveObject).getWritableObject().get(); int expected = ((IntWritable) expectedObject).get(); if (value != expected) {
@Override public void writeShort(short v) throws IOException { beginPrimitive(); LazyInteger.writeUTF8(output, v); finishPrimitive(); }
@Override public void init(ByteArrayRef bytes, int start, int length) { try { data.set(parseInt(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "INT"); } }
@Nonnull public static LazyInteger lazyInteger(@Nonnull final int v) { LazyInteger lazy = new LazyInteger(LazyPrimitiveObjectInspectorFactory.LAZY_INT_OBJECT_INSPECTOR); lazy.getWritableObject().set(v); return lazy; }
return parse(bytes, start, length, offset, radix, negative);
public static int asJavaInt(@Nullable final Object o) { if (o == null) { throw new IllegalArgumentException(); } if (o instanceof Integer) { return ((Integer) o).intValue(); } if (o instanceof LazyInteger) { IntWritable i = ((LazyInteger) o).getWritableObject(); return i.get(); } if (o instanceof IntWritable) { return ((IntWritable) o).get(); } String s = o.toString(); return Integer.parseInt(s); }
public Text evaluate(ByteWritable i) { if (i == null) { return null; } else { out.reset(); LazyInteger.writeUTF8NoException(out, i.get()); t.set(out.getData(), 0, out.getLength()); return t; } }
/** * Parses the string argument as if it was an int value and returns the * result. Throws NumberFormatException if the string does not represent an * int quantity. The second argument specifies the radix to use when parsing * the value. * * @param bytes * @param start * @param length * a UTF-8 encoded string representation of an int quantity. * @param radix * the base to use for conversion. * @return the value represented by the argument * @exception NumberFormatException * if the argument could not be parsed as an int quantity. */ public static int parseInt(byte[] bytes, int start, int length, int radix) { return parseInt(bytes, start, length, radix, false); }
@Override public void writeInt(int v) throws IOException { beginPrimitive(); LazyInteger.writeUTF8(output, v); finishPrimitive(); }
@Override public void init(ByteArrayRef bytes, int start, int length) { try { data.set(parseInt(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "INT"); } }
return new LazyShort((LazyShortObjectInspector) oi); case INT: return new LazyInteger((LazyIntObjectInspector) oi); case LONG: return new LazyLong((LazyLongObjectInspector) oi);
return parse(bytes, start, length, offset, radix, negative);
public static int asJavaInt(@Nullable final Object o) { if(o == null) { throw new IllegalArgumentException(); } if(o instanceof Integer) { return ((Integer) o).intValue(); } if(o instanceof LazyInteger) { IntWritable i = ((LazyInteger) o).getWritableObject(); return i.get(); } if(o instanceof IntWritable) { return ((IntWritable) o).get(); } String s = o.toString(); return Integer.parseInt(s); }