protected StringDelegateCoder(final Class<T> clazz, TypeDescriptor<T> typeDescriptor) { delegateCoder = DelegateCoder.of( StringUtf8Coder.of(), Object::toString, input -> clazz.getConstructor(String.class).newInstance(input), typeDescriptor); this.clazz = clazz; }
@Override protected long getEncodedElementByteSize(Integer value) throws Exception { if (value == null) { throw new CoderException("cannot encode a null Integer"); } String textualValue = value.toString(); return StringUtf8Coder.of().getEncodedElementByteSize(textualValue); } }
@Override public TimerData decode(InputStream inStream) throws CoderException, IOException { String timerId = STRING_CODER.decode(inStream); StateNamespace namespace = StateNamespaces.fromString(STRING_CODER.decode(inStream), windowCoder); Instant timestamp = INSTANT_CODER.decode(inStream); TimeDomain domain = TimeDomain.valueOf(STRING_CODER.decode(inStream)); return TimerData.of(timerId, namespace, timestamp, domain); }
@Override public void encode(String value, OutputStream outStream) throws CoderException, IOException { realCoder.encode(value, outStream); }
@Override public Result<DestinationT> decode(InputStream inStream) throws IOException { String filename = stringCoder.decode(inStream); long fileByteSize = longCoder.decode(inStream); DestinationT destination = destinationCoder.decode(inStream); return new Result<>(filename, fileByteSize, destination); }
@Override public void encode(KafkaRecord<K, V> value, OutputStream outStream) throws IOException { stringCoder.encode(value.getTopic(), outStream); intCoder.encode(value.getPartition(), outStream); longCoder.encode(value.getOffset(), outStream); longCoder.encode(value.getTimestamp(), outStream); intCoder.encode(value.getTimestampType().ordinal(), outStream); headerCoder.encode(toIterable(value), outStream); kvCoder.encode(value.getKV(), outStream); }
public static HDFSFileSource<String, LongWritable, Text> fromText(String filepattern) { SerializableFunction<KV<LongWritable, Text>, String> inputConverter = new SerializableFunction<KV<LongWritable, Text>, String>() { @Override public String apply(KV<LongWritable, Text> input) { return input.getValue().toString(); } }; return from(filepattern, TextInputFormat.class, StringUtf8Coder.of(), inputConverter); }
@Override public Integer decode(InputStream inStream, Context context) throws IOException, CoderException { String textualValue = StringUtf8Coder.of().decode(inStream, context); try { return Integer.valueOf(textualValue); } catch (NumberFormatException exn) { throw new CoderException("error when decoding a textual integer", exn); } }
@Override public KafkaRecord<K, V> decode(InputStream inStream) throws IOException { return new KafkaRecord<>( stringCoder.decode(inStream), intCoder.decode(inStream), longCoder.decode(inStream), longCoder.decode(inStream), KafkaTimestampType.forOrdinal(intCoder.decode(inStream)), (Headers) toHeaders(headerCoder.decode(inStream)), kvCoder.decode(inStream)); }
@Override public Coder<String> getOutputCoder() { return StringUtf8Coder.of(); }
@Override public void encode(Integer value, OutputStream outStream, Context context) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null Integer"); } String textualValue = value.toString(); StringUtf8Coder.of().encode(textualValue, outStream, context); }
@Override public BigQueryInsertError decode(InputStream inStream) throws IOException { TableDataInsertAllResponse.InsertErrors err = MAPPER.readValue( StringUtf8Coder.of().decode(inStream), TableDataInsertAllResponse.InsertErrors.class); TableRow row = TableRowJsonCoder.of().decode(inStream); TableReference ref = BigQueryHelpers.parseTableSpec(StringUtf8Coder.of().decode(inStream)); return new BigQueryInsertError(row, err, ref); }
@Override public Coder<String> getOutputCoder() { return StringUtf8Coder.of(); } }
@Override public Coder<String> getOutputCoder() { return StringUtf8Coder.of(); } }