@Override public Type getOwnerType() { return this.enclosingType == null ? null : this.enclosingType.toType(); } } // TypeRepresentation
public Type getRecordType() { return typeRep.toType(); }
public Type getRecordType() { return typeRep.toType(); }
@SuppressWarnings("unchecked") private ReflectionDatumReader<T> getReflectionDatumReader() { if (datumReader == null) { datumReader = new ReflectionDatumReader<>(schema, (TypeToken<T>) TypeToken.of(this.typeRep.toType())); } return datumReader; }
@SuppressWarnings("unchecked") private ReflectionDatumReader<T> getReflectionDatumReader() { if (datumReader == null) { datumReader = new ReflectionDatumReader<>(schema, (TypeToken<T>) TypeToken.of(this.typeRep.toType())); } return datumReader; }
@SuppressWarnings("unchecked") private ReflectionRowReader<T> getReflectionRowReader() { if (rowReader == null) { try { // this can throw a runtime exception from a ClassNotFoundException Type type = typeRepresentation.toType(); rowReader = new ReflectionRowReader<>(objectSchema, (TypeToken<T>) TypeToken.of(type)); } catch (RuntimeException e) { String missingClass = isClassNotFoundException(e); if (missingClass != null) { LOG.error("Cannot load dataset because class {} could not be found. This is probably because the " + "type parameter of the dataset is not present in the dataset's jar file. See the developer " + "guide for more information.", missingClass); } throw e; } } return rowReader; }
@SuppressWarnings("unchecked") private ReflectionRowReader<T> getReflectionRowReader() { if (rowReader == null) { try { // this can throw a runtime exception from a ClassNotFoundException Type type = typeRepresentation.toType(); rowReader = new ReflectionRowReader<>(objectSchema, (TypeToken<T>) TypeToken.of(type)); } catch (RuntimeException e) { String missingClass = isClassNotFoundException(e); if (missingClass != null) { LOG.error("Cannot load dataset because class {} could not be found. This is probably because the " + "type parameter of the dataset is not present in the dataset's jar file. See the developer " + "guide for more information.", missingClass); } throw e; } } return rowReader; }
@Test public void testEmptyValue() throws UnsupportedTypeException, IOException { Schema schema = new ReflectionSchemaGenerator().generate(RecordWithString.class); TypeRepresentation typeRep = new TypeRepresentation(RecordWithString.class); DatumWriter<RecordWithString> datumWriter = new ReflectionDatumWriter<>(schema); @SuppressWarnings("unchecked") ReflectionDatumReader<RecordWithString> datumReader = new ReflectionDatumReader<>( schema, (TypeToken<RecordWithString>) TypeToken.of(typeRep.toType())); RecordWithString record = new RecordWithString(); record.setA(42); record.setTheString(""); ByteArrayOutputStream bos = new ByteArrayOutputStream(); BinaryEncoder encoder = new BinaryEncoder(bos); datumWriter.encode(record, encoder); byte[] bytes = bos.toByteArray(); ByteArrayInputStream bis = new ByteArrayInputStream(bytes); BinaryDecoder decoder = new BinaryDecoder(bis); RecordWithString rec = datumReader.read(decoder, schema); Assert.assertEquals(record.getA(), rec.getA()); Assert.assertEquals(record.getTheString(), rec.getTheString()); } }