EvaluatorFactory { static Comparable<?> toComparable(PrimitiveCategory category, Object literal) { String stringLiteral; switch (category) { case STRING: return new Text((String) literal); case BOOLEAN: return new BooleanWritable((Boolean) literal); case BYTE: return new ByteWritable(((Long) literal).byteValue()); case SHORT: return new ShortWritable(((Long) literal).shortValue()); case INT: return new IntWritable(((Long) literal).intValue()); case LONG: return new LongWritable((Long) literal); case FLOAT: return new FloatWritable(((Double) literal).floatValue()); case DOUBLE: return new DoubleWritable((Double) literal); case TIMESTAMP: return new TimestampWritable((Timestamp) literal); case DATE: if (literal instanceof Timestamp) { long timeStampMillis = ((Timestamp)literal).getTime(); int days = DateWritable.millisToDays(timeStampMillis); return new DateWritable(days); } else if(literal instanceof Date) { return new DateWritable((Date)literal); } else { throw new IllegalArgumentException("Unsupported date type: " + literal); } case CHAR: stringLiteral = (String) literal; return new HiveCharWritable(new HiveChar(stringLiteral, stringLiteral.length())); case VARCHAR: stringLiteral = (String) literal; return new HiveVarcharWritable(new HiveVarchar(stringLiteral, stringLiteral.length())); case DECIMAL: return new HiveDecimalWritable(HiveDecimal.create(literal.toString())); default: throw new IllegalArgumentException("Unsupported category: " + category); } } EvaluatorFactory(StructTypeInfo structTypeInfo);   }
@Test(expected = ClassCastException.class) public void intWithIntInput() { toComparable(INT, 0); }
@SuppressWarnings("rawtypes") @Test public void longTypical() { assertThat(toComparable(LONG, 0L), is((Comparable) new LongWritable(0L))); }
@SuppressWarnings("rawtypes") @Test public void floatTypical() { assertThat(toComparable(FLOAT, 0.0D), is((Comparable) new FloatWritable(0.0F))); }
@Test(expected = ClassCastException.class) public void floatWithFloatInput() { toComparable(FLOAT, 0.0F); }
@SuppressWarnings("rawtypes") @Test public void doubleTypical() { assertThat(toComparable(DOUBLE, 0.0D), is((Comparable) new DoubleWritable(0.0D))); }
@SuppressWarnings("rawtypes") @Test public void timestampTypical() { assertThat(toComparable(TIMESTAMP, new Timestamp(0L)), is((Comparable) new TimestampWritable(new Timestamp(0L)))); }
@SuppressWarnings("rawtypes") @Test public void dateTypical() { assertThat(toComparable(DATE, new Date(0L)), is((Comparable) new DateWritable(new Date(0L)))); }
@SuppressWarnings("rawtypes") @Test public void dateAsTimestamp() { assertThat(toComparable(DATE, new Timestamp(0L)), is((Comparable) new DateWritable(new Date(0L)))); }
@SuppressWarnings("rawtypes") @Test(expected = IllegalArgumentException.class) public void unsupportedDateType() { assertThat(toComparable(DATE, new Long(0L)), is((Comparable) new DateWritable(new Date(0L)))); }
@SuppressWarnings("rawtypes") @Test public void charTypical() { assertThat(toComparable(CHAR, "foo"), is((Comparable) new HiveCharWritable(new HiveChar("foo", 3)))); }
@Test(expected = ClassCastException.class) public void charWithCharInput() { toComparable(CHAR, new HiveChar("foo", 3)); }
@SuppressWarnings("rawtypes") @Test public void varcharTypical() { assertThat(toComparable(VARCHAR, "foo"), is((Comparable) new HiveVarcharWritable(new HiveVarchar("foo", 3)))); }
@Test(expected = ClassCastException.class) public void varcharWithVarcharInput() { toComparable(VARCHAR, new HiveVarchar("foo", 3)); }
@SuppressWarnings("rawtypes") @Test public void decimalTypical() { assertThat(toComparable(DECIMAL, new BigDecimal("0.0")), is((Comparable) new HiveDecimalWritable(HiveDecimal.create(new BigDecimal("0.0"))))); }
@Test(expected = IllegalArgumentException.class) public void binaryTypical() { toComparable(BINARY, new byte[] {}); }
@SuppressWarnings("rawtypes") @Test public void stringTypical() { assertThat(toComparable(STRING, "foo"), is((Comparable) new Text("foo"))); }
@Test(expected = ClassCastException.class) public void stringWithTextThrowsException() { toComparable(STRING, new Text("foo")); }
@SuppressWarnings("rawtypes") @Test public void booleanTypical() { assertThat(toComparable(BOOLEAN, true), is((Comparable) new BooleanWritable(true))); }
@SuppressWarnings("rawtypes") @Test public void byteTypical() { assertThat(toComparable(BYTE, 0L), is((Comparable) new ByteWritable((byte) 0))); }
@Test(expected = ClassCastException.class) public void byteWithByteInput() { toComparable(BYTE, (byte) 0); }
@SuppressWarnings("rawtypes") @Test public void shortTypical() { assertThat(toComparable(SHORT, 0L), is((Comparable) new ShortWritable((short) 0))); }
@Test(expected = ClassCastException.class) public void shortWithShortInput() { toComparable(SHORT, (short) 0); }
@SuppressWarnings("rawtypes") @Test public void intTypical() { assertThat(toComparable(INT, 0L), is((Comparable) new IntWritable(0))); }