public Text evaluate(LongWritable i) { if (i == null) { return null; } else { out.reset(); LazyLong.writeUTF8NoException(out, i.get()); t.set(out.getData(), 0, out.getLength()); return t; } }
/** * Parses the string argument as if it was a long value and returns the * result. Throws NumberFormatException if the string does not represent a * long quantity. * * @param bytes * @param start * @param length * a UTF-8 encoded string representation of a long quantity. * @return long the value represented by the argument * @exception NumberFormatException * if the argument could not be parsed as a long quantity. */ public static long parseLong(byte[] bytes, int start, int length) { return parseLong(bytes, start, length, 10); }
@Override public Object copyObject(Object o) { return o == null ? null : new LazyLong((LazyLong) o); }
@Override public void init(ByteArrayRef bytes, int start, int length) { if (!LazyUtils.isNumberMaybe(bytes.getData(), start, length)) { isNull = true; return; } try { data.set(parseLong(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "BIGINT"); } }
public static void writeUTF8NoException(OutputStream out, long i) { try { writeUTF8(out, i); } catch (IOException e) { throw new RuntimeException(e); } }
@Nonnull public static LazyLong lazyLong(@Nonnull final long v) { LazyLong lazy = new LazyLong(LazyPrimitiveObjectInspectorFactory.LAZY_LONG_OBJECT_INSPECTOR); lazy.getWritableObject().set(v); return lazy; }
return parse(bytes, start, length, offset, radix, negative);
throw new RuntimeException("Expected LazyLong"); long value = ((LazyLong) primitiveObject).getWritableObject().get(); long expected = ((LongWritable) expectedObject).get(); if (value != expected) {
@Override public void init(ByteArrayRef bytes, int start, int length) { try { data.set(parseLong(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "BIGINT"); } }
@Override public void writeLong(long v) throws IOException { beginPrimitive(); LazyLong.writeUTF8(output, v); finishPrimitive(); }
return parse(bytes, start, length, offset, radix, negative);
Timestamp.ofEpochMilli(timestamp)); } else { ((LazyLong) lz).getWritableObject().set(timestamp);
/** * Parses the string argument as if it was an long value and returns the * result. Throws NumberFormatException if the string does not represent an * long 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 a long 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 long quantity. */ public static long parseLong(byte[] bytes, int start, int length, int radix) { return parseLong(bytes, start, length, radix, false); }
case LONG: out.reset(); LazyLong.writeUTF8NoException(out, ((LongObjectInspector) inputOI).get(input)); t.set(out.getData(), 0, out.getLength()); return t;
@Override public void init(ByteArrayRef bytes, int start, int length) { try { data.set(parseLong(bytes.getData(), start, length, 10)); isNull = false; } catch (NumberFormatException e) { isNull = true; logExceptionMessage(bytes, start, length, "BIGINT"); } }
LazyLong.writeUTF8(out, ((LongObjectInspector) oi).get(o)); break;
return new LazyInteger((LazyIntObjectInspector) oi); case LONG: return new LazyLong((LazyLongObjectInspector) oi); case FLOAT: return new LazyFloat((LazyFloatObjectInspector) oi);
return parse(bytes, start, length, offset, radix, negative);
throw new RuntimeException("Expected LazyLong"); long value = ((LazyLong) primitiveObject).getWritableObject().get(); long expected = ((LongWritable) expectedObject).get(); if (value != expected) {
/** * Convert from string to a long. This is called for CAST(... AS BIGINT) * * @param i * The string value to convert * @return LongWritable */ public LongWritable evaluate(Text i) { if (i == null) { return null; } else { if (!LazyUtils.isNumberMaybe(i.getBytes(), 0, i.getLength())) { return null; } try { longWritable .set(LazyLong.parseLong(i.getBytes(), 0, i.getLength(), 10, true)); return longWritable; } catch (NumberFormatException e) { // MySQL returns 0 if the string is not a well-formed numeric value. // return LongWritable.valueOf(0); // But we decided to return NULL instead, which is more conservative. return null; } } }