/** * Returns the default coder for a given type descriptor. Coder Registry is queried for correct * coder, if not found in Coder Registry, then check if the type descriptor provided is of type * Writable, then WritableCoder is returned, else exception is thrown "Cannot find coder". */ @SuppressWarnings({"unchecked", "WeakerAccess"}) public <T> Coder<T> getDefaultCoder(TypeDescriptor<?> typeDesc, CoderRegistry coderRegistry) { Class classType = typeDesc.getRawType(); try { return (Coder<T>) coderRegistry.getCoder(typeDesc); } catch (CannotProvideCoderException e) { if (Writable.class.isAssignableFrom(classType)) { return (Coder<T>) WritableCoder.of(classType); } throw new IllegalStateException( String.format("Cannot find coder for %s : ", typeDesc) + e.getMessage(), e); } } }
/** * Returns the default coder for a given type descriptor. Coder Registry is queried for correct * coder, if not found in Coder Registry, then check if the type descriptor provided is of type * Writable, then WritableCoder is returned, else exception is thrown "Cannot find coder". */ @SuppressWarnings({"unchecked", "WeakerAccess"}) public <T> Coder<T> getDefaultCoder(TypeDescriptor<?> typeDesc, CoderRegistry coderRegistry) { Class classType = typeDesc.getRawType(); try { return (Coder<T>) coderRegistry.getCoder(typeDesc); } catch (CannotProvideCoderException e) { if (Writable.class.isAssignableFrom(classType)) { return (Coder<T>) WritableCoder.of(classType); } throw new IllegalStateException( String.format("Cannot find coder for %s : ", typeDesc) + e.getMessage(), e); } } }
/** * Returns a {@link Coder} to use for values of the given parameterized type, in a context where * the given types use the given {@link Coder Coders}. * * @throws CannotProvideCoderException if no coder can be provided */ private Coder<?> getCoderFromParameterizedType( ParameterizedType type, SetMultimap<Type, Coder<?>> typeCoderBindings) throws CannotProvideCoderException { List<Coder<?>> typeArgumentCoders = new ArrayList<>(); for (Type typeArgument : type.getActualTypeArguments()) { try { Coder<?> typeArgumentCoder = getCoderFromTypeDescriptor(TypeDescriptor.of(typeArgument), typeCoderBindings); typeArgumentCoders.add(typeArgumentCoder); } catch (CannotProvideCoderException exc) { throw new CannotProvideCoderException( String.format( "Cannot provide coder for parameterized type %s: %s", type, exc.getMessage()), exc); } } return getCoderFromFactories(TypeDescriptor.of(type), typeArgumentCoders); }
inferFromTokenException = new CannotProvideCoderException( exc.getMessage() + " If this error occurs for an output of the producing ParDo, verify that the " + "TupleTag for this output is constructed with proper type information (see " messageBuilder .append("\n Inferring a Coder from the CoderRegistry failed: ") .append(inferFromTokenException.getMessage()); messageBuilder .append("\n Using the default output Coder from the producing PTransform failed: ") .append(inputCoderException.getMessage());