FieldsTypeUtils { static PredicateLeaf.Type toType(Fields fields) { Type type = fields.getType(0); if (type.equals(Double.class)) { return PredicateLeaf.Type.FLOAT; } else if (type.equals(Long.class)) { return PredicateLeaf.Type.LONG; } else if (type.equals(Integer.class)) { return PredicateLeaf.Type.LONG; } else if (type.equals(Date.class)) { return PredicateLeaf.Type.DATE; } else if (type.equals(String.class)) { return PredicateLeaf.Type.STRING; } else if (type.equals(HiveChar.class)){ return PredicateLeaf.Type.STRING; } else if (type.equals(HiveVarchar.class)){ return PredicateLeaf.Type.STRING; } else if(type.equals(HiveDecimalWritable.class)) { return PredicateLeaf.Type.DECIMAL; } else if (type.equals(Timestamp.class)) { return PredicateLeaf.Type.TIMESTAMP; } else if (type.equals(Boolean.class)) { return PredicateLeaf.Type.BOOLEAN; } throw new IllegalStateException("Can't map Fields.Type to PredicateLeaf.Type:" + fields); } private  FieldsTypeUtils();   }
@Test public void intToLongType(){ Fields fields = new Fields("A", Integer.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.LONG)); }
@Test public void longToLongType(){ Fields fields = new Fields("A", Long.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.LONG)); }
@Test public void doubleToFloatType(){ Fields fields = new Fields("A", Double.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.FLOAT)); }
@Test public void dateToDateType(){ Fields fields = new Fields("A", Date.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.DATE)); }
@Test public void stringToStringType(){ Fields fields = new Fields("A", String.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.STRING)); }
@Test public void hiveCharToStringType(){ Fields fields = new Fields("A", HiveChar.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.STRING)); }
@Test public void hiveVarcharToStringType(){ Fields fields = new Fields("A", HiveVarchar.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.STRING)); }
@Test public void hiveDecimalWritableToDecimalType(){ Fields fields = new Fields("A", HiveDecimalWritable.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.DECIMAL)); }
@Test public void timestampToTimestampType(){ Fields fields = new Fields("A", Timestamp.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.TIMESTAMP)); }
@Test public void booleanToBooleanType(){ Fields fields = new Fields("A", Boolean.class); PredicateLeaf.Type fieldsType = toType(fields); assertThat(fieldsType, is (PredicateLeaf.Type.BOOLEAN)); }
@Test (expected = IllegalStateException.class) public void incorrectDecimalType(){ Fields fields = new Fields("A", BigDecimal.class); PredicateLeaf.Type fieldsType = toType(fields); }