this.enclosingType = owner == null ? null : new TypeRepresentation(owner); Type[] typeArgs = pType.getActualTypeArguments(); this.parameters = new TypeRepresentation[typeArgs.length]; for (int i = 0; i < typeArgs.length; i++) { this.parameters[i] = new TypeRepresentation(typeArgs[i]);
/** * Sets the type of object stored in the table. The schema of the Hive table for an ObjectMappedTable * is derived from the object type set here and the row key explore name set by * {@link #setRowKeyExploreName(String)}. * * For example, if the type set here has three fields - "id", "name", and "price", the corresponding Hive table * for this Dataset will contain four columns - "rowkey", "id", "name", and "price". */ public Builder setType(Type type) throws UnsupportedTypeException { add(OBJECT_TYPE, gson.toJson(new TypeRepresentation(type))); add(OBJECT_SCHEMA, schemaGenerator.generate(type, false).toString()); return this; }
public IntegerStore(String name, KeyValueTable kvTable) throws UnsupportedTypeException { super(name, kvTable, new TypeRepresentation(Integer.class), new ReflectionSchemaGenerator().generate(Integer.class)); }
/** * Creates properties for {@link ObjectStore} dataset instance. * * @param type type of objects to be stored in dataset * @return {@link DatasetProperties} for the dataset * @throws UnsupportedTypeException */ public static DatasetProperties objectStoreProperties(Type type, DatasetProperties props) throws UnsupportedTypeException { Schema schema = new ReflectionSchemaGenerator().generate(type); TypeRepresentation typeRep = new TypeRepresentation(type); return DatasetProperties.builder() .add("schema", schema.toString()) .add("type", new Gson().toJson(typeRep)) .addAll(props.getProperties()) .build(); }
@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()); } }
TypeRepresentation typeRep = new TypeRepresentation(type); Schema schema = new ReflectionSchemaGenerator().generate(type);