/** * Returns the default {@code Coder} to use for the output of this single-output {@code * PTransform}. * * <p>By default, always throws * * @throws CannotProvideCoderException if no coder can be inferred * @deprecated Instead, the PTransform should explicitly call {@link PCollection#setCoder} on the * returned PCollection. */ @Deprecated protected Coder<?> getDefaultOutputCoder() throws CannotProvideCoderException { throw new CannotProvideCoderException("PTransform.getOutputCoder called."); }
.append(" See suppressed exceptions for detailed failures."); CannotProvideCoderException exceptionOnFailure = new CannotProvideCoderException(messageBuilder.toString()); for (CannotProvideCoderException suppressedException : suppressedExceptions) { exceptionOnFailure.addSuppressed(suppressedException);
/** * Returns the inner-most {@link CannotProvideCoderException} when they are deeply nested. * * <p>For example, if a coder for {@code List<KV<Integer, Whatsit>>} cannot be provided because * there is no known coder for {@code Whatsit}, the root cause of the exception should be a * CannotProvideCoderException with details pertinent to {@code Whatsit}, suppressing the * intermediate layers. */ public Throwable getRootCause() { Throwable cause = getCause(); if (cause == null) { return this; } else if (!(cause instanceof CannotProvideCoderException)) { return cause; } else { return ((CannotProvideCoderException) cause).getRootCause(); } }
if (transform instanceof ParDo.MultiOutput && exc.getReason() == ReasonCode.TYPE_ERASURE) { 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());
/** * 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); }
/** * 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); } } }
@Override public <T> Coder<T> coderFor( TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { try { return AvroCoder.of(typeDescriptor); } catch (AvroRuntimeException e) { throw new CannotProvideCoderException( String.format("%s is not compatible with Avro", typeDescriptor), e); } } }
@Override public <T> Coder<T> coderFor(TypeDescriptor<T> type, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { if (!this.type.equals(type)) { throw new CannotProvideCoderException( String.format( "Unable to provide coder for %s, this factory can only provide coders for %s", type, this.type)); } return (Coder) coder; }
@Override public <T> Coder<T> coderFor(TypeDescriptor<T> type, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { if (!this.rawType.equals(type.getRawType())) { throw new CannotProvideCoderException( String.format( "Unable to provide coder for %s, this factory can only provide coders for %s", type, this.rawType)); } try { return (Coder) factoryMethod.invoke(null /* static */, componentCoders.toArray()); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NullPointerException | ExceptionInInitializerError exn) { throw new IllegalStateException( "error when invoking Coder factory method " + factoryMethod, exn); } }
@Override public <T> Coder<T> coderFor( TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { CoderProvider factory = commonTypesToCoderProviders.get(typeDescriptor.getRawType()); if (factory == null) { throw new CannotProvideCoderException( String.format("%s is not one of the common types.", typeDescriptor)); } return factory.coderFor(typeDescriptor, componentCoders); } }
@Override public <T> Coder<T> coderFor( TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { if (!typeDescriptor.isSubtypeOf(HBASE_MUTATION_TYPE_DESCRIPTOR)) { throw new CannotProvideCoderException( String.format( "Cannot provide %s because %s is not a subclass of %s", HBaseMutationCoder.class.getSimpleName(), typeDescriptor, Mutation.class.getName())); } try { @SuppressWarnings("unchecked") Coder<T> coder = (Coder<T>) HBaseMutationCoder.of(); return coder; } catch (IllegalArgumentException e) { throw new CannotProvideCoderException(e); } } }
@Override public <T> Coder<T> coderFor( TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { if (!typeDescriptor.isSubtypeOf(MESSAGE_TYPE)) { throw new CannotProvideCoderException( String.format( "Cannot provide %s because %s is not a subclass of %s", ProtoCoder.class.getSimpleName(), typeDescriptor, Message.class.getName())); } @SuppressWarnings("unchecked") TypeDescriptor<? extends Message> messageType = (TypeDescriptor<? extends Message>) typeDescriptor; try { @SuppressWarnings("unchecked") Coder<T> coder = (Coder<T>) ProtoCoder.of(messageType); return coder; } catch (IllegalArgumentException e) { throw new CannotProvideCoderException(e); } } }
@Override public <T> Coder<T> coderFor( TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { if (Serializable.class.isAssignableFrom(typeDescriptor.getRawType())) { return SerializableCoder.of((TypeDescriptor) typeDescriptor); } throw new CannotProvideCoderException( "Cannot provide SerializableCoder because " + typeDescriptor + " does not implement Serializable"); } }
@Override public <T> Coder<T> coderFor(TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { Type t = typeDescriptor.getType(); if (IndexedRecord.class.isAssignableFrom(typeDescriptor.getRawType())) { Coder<T> c = LazyAvroCoder.<T> of(); return c; } throw new CannotProvideCoderException(String.format("Cannot provide %s because %s is not implement IndexedRecord", LazyAvroCoder.class.getSimpleName(), typeDescriptor)); } }
@Override public <T> Coder<T> coderFor( TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { if (!typeDescriptor.isSubtypeOf(WRITABLE_TYPE)) { throw new CannotProvideCoderException( String.format( "Cannot provide %s because %s does not implement the interface %s", WritableCoder.class.getSimpleName(), typeDescriptor, Writable.class.getName())); } try { @SuppressWarnings("unchecked") Coder<T> coder = WritableCoder.of((Class) typeDescriptor.getRawType()); return coder; } catch (IllegalArgumentException e) { throw new CannotProvideCoderException(e); } } }
@Override public <T> Coder<T> coderFor(TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders) throws CannotProvideCoderException { Type t = typeDescriptor.getType(); if (IndexedRecord.class.isAssignableFrom(typeDescriptor.getRawType())) { Coder<T> c = LazyAvroCoder.<T> of(); return c; } throw new CannotProvideCoderException(String.format("Cannot provide %s because %s is not implement IndexedRecord", LazyAvroCoder.class.getSimpleName(), typeDescriptor)); } }
DefaultCoder defaultAnnotation = clazz.getAnnotation(DefaultCoder.class); if (defaultAnnotation == null) { throw new CannotProvideCoderException( String.format("Class %s does not have a @DefaultCoder annotation.", clazz.getName())); throw new CannotProvideCoderException( String.format( "Class %s has a @DefaultCoder annotation with a null value.", clazz.getName())); coderProviderMethod = defaultAnnotationValue.getMethod("getCoderProvider"); } catch (NoSuchMethodException e) { throw new CannotProvideCoderException( String.format( "Unable to find 'public static CoderProvider getCoderProvider()' on %s", | NullPointerException | ExceptionInInitializerError e) { throw new CannotProvideCoderException( String.format( "Unable to invoke 'public static CoderProvider getCoderProvider()' on %s",
/** * Returns the {@link Coder} to use for the specified type parameter specialization of the * subclass, given {@link Coder Coders} to use for all other type parameters (if any). * * @throws CannotProvideCoderException if a {@link Coder} cannot be provided * @deprecated This method is to change in an unknown backwards incompatible way once support for * this functionality is refined. */ @Deprecated @Internal public <T, OutputT> Coder<OutputT> getCoder( Class<? extends T> subClass, Class<T> baseClass, Map<Type, ? extends Coder<?>> knownCoders, TypeVariable<?> param) throws CannotProvideCoderException { Map<Type, Coder<?>> inferredCoders = getDefaultCoders(subClass, baseClass, knownCoders); @SuppressWarnings("unchecked") Coder<OutputT> paramCoderOrNull = (Coder<OutputT>) inferredCoders.get(param); if (paramCoderOrNull != null) { return paramCoderOrNull; } else { throw new CannotProvideCoderException("Cannot infer coder for type parameter " + param); } }
final Coder<DestinationT> getDestinationCoderWithDefault(CoderRegistry registry) throws CannotProvideCoderException { Coder<DestinationT> destinationCoder = getDestinationCoder(); if (destinationCoder != null) { return destinationCoder; } // If dynamicDestinations doesn't provide a coder, try to find it in the coder registry. @Nullable TypeDescriptor<DestinationT> descriptor = extractFromTypeParameters( this, DynamicDestinations.class, new TypeVariableExtractor< DynamicDestinations<UserT, DestinationT, OutputT>, DestinationT>() {}); try { return registry.getCoder(descriptor); } catch (CannotProvideCoderException e) { throw new CannotProvideCoderException( "Failed to infer coder for DestinationT from type " + descriptor + ", please provide it explicitly by overriding getDestinationCoder()", e); } } }