Search in sources :

Example 1 with StringWriter

use of org.apache.drill.exec.store.pojo.Writers.StringWriter in project drill by apache.

the class PojoRecordReader method setup.

@Override
public void setup(OperatorContext context, OutputMutator output) throws ExecutionSetupException {
    operatorContext = context;
    try {
        Field[] fields = pojoClass.getDeclaredFields();
        List<PojoWriter> writers = Lists.newArrayList();
        for (int i = 0; i < fields.length; i++) {
            Field f = fields[i];
            if (Modifier.isStatic(f.getModifiers())) {
                continue;
            }
            Class<?> type = f.getType();
            PojoWriter w = null;
            if (type == int.class) {
                w = new IntWriter(f);
            } else if (type == Integer.class) {
                w = new NIntWriter(f);
            } else if (type == Long.class) {
                w = new NBigIntWriter(f);
            } else if (type == Boolean.class) {
                w = new NBooleanWriter(f);
            } else if (type == double.class) {
                w = new DoubleWriter(f);
            } else if (type == Double.class) {
                w = new NDoubleWriter(f);
            } else if (type.isEnum()) {
                w = new EnumWriter(f, output.getManagedBuffer());
            } else if (type == boolean.class) {
                w = new BitWriter(f);
            } else if (type == long.class) {
                w = new LongWriter(f);
            } else if (type == String.class) {
                w = new StringWriter(f, output.getManagedBuffer());
            } else if (type == Timestamp.class) {
                w = new NTimeStampWriter(f);
            } else {
                throw new ExecutionSetupException(String.format("PojoRecord reader doesn't yet support conversions from type [%s].", type));
            }
            writers.add(w);
            w.init(output);
        }
        this.writers = writers.toArray(new PojoWriter[writers.size()]);
    } catch (SchemaChangeException e) {
        throw new ExecutionSetupException("Failure while setting up schema for PojoRecordReader.", e);
    }
    currentIterator = pojoObjects.iterator();
}
Also used : BitWriter(org.apache.drill.exec.store.pojo.Writers.BitWriter) ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) EnumWriter(org.apache.drill.exec.store.pojo.Writers.EnumWriter) LongWriter(org.apache.drill.exec.store.pojo.Writers.LongWriter) IntWriter(org.apache.drill.exec.store.pojo.Writers.IntWriter) NIntWriter(org.apache.drill.exec.store.pojo.Writers.NIntWriter) NBigIntWriter(org.apache.drill.exec.store.pojo.Writers.NBigIntWriter) NBigIntWriter(org.apache.drill.exec.store.pojo.Writers.NBigIntWriter) NTimeStampWriter(org.apache.drill.exec.store.pojo.Writers.NTimeStampWriter) Field(java.lang.reflect.Field) NIntWriter(org.apache.drill.exec.store.pojo.Writers.NIntWriter) SchemaChangeException(org.apache.drill.exec.exception.SchemaChangeException) StringWriter(org.apache.drill.exec.store.pojo.Writers.StringWriter) NDoubleWriter(org.apache.drill.exec.store.pojo.Writers.NDoubleWriter) NDoubleWriter(org.apache.drill.exec.store.pojo.Writers.NDoubleWriter) DoubleWriter(org.apache.drill.exec.store.pojo.Writers.DoubleWriter) NBooleanWriter(org.apache.drill.exec.store.pojo.Writers.NBooleanWriter)

Aggregations

Field (java.lang.reflect.Field)1 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)1 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)1 BitWriter (org.apache.drill.exec.store.pojo.Writers.BitWriter)1 DoubleWriter (org.apache.drill.exec.store.pojo.Writers.DoubleWriter)1 EnumWriter (org.apache.drill.exec.store.pojo.Writers.EnumWriter)1 IntWriter (org.apache.drill.exec.store.pojo.Writers.IntWriter)1 LongWriter (org.apache.drill.exec.store.pojo.Writers.LongWriter)1 NBigIntWriter (org.apache.drill.exec.store.pojo.Writers.NBigIntWriter)1 NBooleanWriter (org.apache.drill.exec.store.pojo.Writers.NBooleanWriter)1 NDoubleWriter (org.apache.drill.exec.store.pojo.Writers.NDoubleWriter)1 NIntWriter (org.apache.drill.exec.store.pojo.Writers.NIntWriter)1 NTimeStampWriter (org.apache.drill.exec.store.pojo.Writers.NTimeStampWriter)1 StringWriter (org.apache.drill.exec.store.pojo.Writers.StringWriter)1