public void testCrc32Bin() throws HiveException { UDFCrc32 udf = new UDFCrc32(); runAndVerifyBin(new byte[] { 65, 66, 67 }, 2743272264L, udf); runAndVerifyBin(new byte[0], 0L, udf); // repeat again runAndVerifyBin(new byte[] { 65, 66, 67 }, 2743272264L, udf); runAndVerifyBin(new byte[0], 0L, udf); // null runAndVerifyBin(null, null, udf); }
public void testCrc32Str() throws HiveException { UDFCrc32 udf = new UDFCrc32(); runAndVerifyStr("ABC", 2743272264L, udf); runAndVerifyStr("", 0L, udf); // repeat again runAndVerifyStr("ABC", 2743272264L, udf); runAndVerifyStr("", 0L, udf); // null runAndVerifyStr(null, null, udf); }
private void runAndVerifyStr(String str, Long expResult, UDFCrc32 udf) throws HiveException { Text t = str != null ? new Text(str) : null; LongWritable output = (LongWritable) udf.evaluate(t); if (expResult == null) { assertNull(output); } else { assertNotNull(output); assertEquals("crc32() test ", expResult.longValue(), output.get()); } }
private void runAndVerifyBin(byte[] binV, Long expResult, UDFCrc32 udf) throws HiveException { BytesWritable binWr = binV != null ? new BytesWritable(binV) : null; LongWritable output = (LongWritable) udf.evaluate(binWr); if (expResult == null) { assertNull(output); } else { assertNotNull(output); assertEquals("crc32() test ", expResult.longValue(), output.get()); } } }