public static ObjectEncoder createEncoder(Type type, ObjectInspector inspector)
    {
        String base = type.getTypeSignature().getBase();
        switch (base) {
            case BIGINT:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Long) o));
            case INTEGER:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Integer) o).longValue());
            case SMALLINT:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Short) o).longValue());
            case TINYINT:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Byte) o).longValue());
            case BOOLEAN:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Boolean) o));
            case DATE:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Date) o).getTime());
            case DECIMAL:
                if (Decimals.isShortDecimal(type)) {
                    DecimalType decimalType = (DecimalType) type;
                    return compose(decimal(inspector), o -> DecimalUtils.encodeToLong((BigDecimal) o, decimalType));
                }
                else if (Decimals.isLongDecimal(type)) {
                    DecimalType decimalType = (DecimalType) type;
                    return compose(decimal(inspector), o -> DecimalUtils.encodeToSlice((BigDecimal) o, decimalType));
                }
                break;
            case REAL:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> floatToRawIntBits(((Number) o).floatValue()));
            case DOUBLE:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> (Double) o);
            case TIMESTAMP:
                checkArgument(inspector instanceof PrimitiveObjectInspector);
                return compose(primitive(inspector), o -> ((Timestamp) o).getTime());
            case VARBINARY:
                if (inspector instanceof BinaryObjectInspector) {
                    return compose(primitive(inspector), o -> Slices.wrappedBuffer(((byte[]) o)));
                }
                break;
            case VARCHAR:
                if (inspector instanceof StringObjectInspector) {
                    return compose(primitive(inspector), o -> Slices.utf8Slice(o.toString()));
                }
                else if (inspector instanceof HiveVarcharObjectInspector) {
                    return compose(o -> ((HiveVarcharObjectInspector) inspector).getPrimitiveJavaObject(o).getValue(),
                            o -> Slices.utf8Slice(((String) o)));
                }
                break;
            case CHAR:
                if (inspector instanceof StringObjectInspector) {
                    return compose(primitive(inspector), o -> Slices.utf8Slice(o.toString()));
                }
                else if (inspector instanceof HiveCharObjectInspector) {
                    return compose(o -> ((HiveCharObjectInspector) inspector).getPrimitiveJavaObject(o).getValue(),
                            o -> Slices.utf8Slice(((String) o)));
                }
                break;
            case ROW:
                return StructObjectEncoder.create(type, inspector);
            case ARRAY:
                return ListObjectEncoder.create(type, inspector);
            case MAP:
                return MapObjectEncoder.create(type, inspector);
        }
        throw unsupportedType(type);
    }
@Test
    public void testTextObjectEncoders()
    {
        ObjectInspector inspector;
        ObjectEncoder encoder;

        inspector = writableBinaryObjectInspector;
        encoder = createEncoder(VARBINARY, inspector);
        assertTrue(encoder.encode(new BytesWritable(new byte[] {12, 34, 56})) instanceof Slice);

        inspector = writableStringObjectInspector;
        encoder = createEncoder(VARCHAR, inspector);
        assertTrue(encoder.encode(new Text("test_varchar")) instanceof Slice);

        inspector = writableStringObjectInspector;
        encoder = createEncoder(createCharType(10), inspector);
        assertTrue(encoder.encode(new Text("test_char")) instanceof Slice);
    }