@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; }
/** Validates translation function given for key/value translation. */ private void validateTranslationFunction( TypeDescriptor<?> inputType, SimpleFunction<?, ?> simpleFunction, String errorMsg) { if (simpleFunction != null && !simpleFunction.getInputTypeDescriptor().equals(inputType)) { throw new IllegalArgumentException( String.format(errorMsg, getinputFormatClass().getRawType(), inputType.getRawType())); } }
/** Validates translation function given for key/value translation. */ private void validateTranslationFunction( TypeDescriptor<?> inputType, SimpleFunction<?, ?> simpleFunction, String errorMsg) { if (simpleFunction != null && !simpleFunction.getInputTypeDescriptor().equals(inputType)) { throw new IllegalArgumentException( String.format(errorMsg, getinputFormatClass().getRawType(), inputType.getRawType())); } }
@Override public <T> Schema schemaFor(TypeDescriptor<T> typeDescriptor) { if (typeDescriptor.equals(TypeDescriptor.of(TestDefaultSchemaClass.class))) { return EMPTY_SCHEMA; } return null; }
@VisibleForTesting static DoFnSignature.GetInitialRestrictionMethod analyzeGetInitialRestrictionMethod( ErrorReporter errors, TypeDescriptor<? extends DoFn> fnT, Method m, TypeDescriptor<?> inputT) { // Method is of the form: // @GetInitialRestriction // RestrictionT getInitialRestriction(InputT element); Type[] params = m.getGenericParameterTypes(); errors.checkArgument( params.length == 1 && fnT.resolveType(params[0]).equals(inputT), "Must take a single argument of type %s", formatType(inputT)); return DoFnSignature.GetInitialRestrictionMethod.create( m, fnT.resolveType(m.getGenericReturnType())); }
@Override public <T> Schema schemaFor(TypeDescriptor<T> typeDescriptor) { if (typeDescriptor.equals(TypeDescriptor.of(TestSchemaClass.class))) { return EMPTY_SCHEMA; } return null; }
@VisibleForTesting static DoFnSignature.BundleMethod analyzeStartBundleMethod( ErrorReporter errors, TypeDescriptor<? extends DoFn<?, ?>> fnT, Method m, TypeDescriptor<?> inputT, TypeDescriptor<?> outputT) { errors.checkArgument(void.class.equals(m.getReturnType()), "Must return void"); TypeDescriptor<?> expectedContextT = doFnStartBundleContextTypeOf(inputT, outputT); Type[] params = m.getGenericParameterTypes(); errors.checkArgument( params.length == 0 || (params.length == 1 && fnT.resolveType(params[0]).equals(expectedContextT)), "Must take a single argument of type %s", formatType(expectedContextT)); return DoFnSignature.BundleMethod.create(m); }
@VisibleForTesting static DoFnSignature.BundleMethod analyzeFinishBundleMethod( ErrorReporter errors, TypeDescriptor<? extends DoFn<?, ?>> fnT, Method m, TypeDescriptor<?> inputT, TypeDescriptor<?> outputT) { errors.checkArgument(void.class.equals(m.getReturnType()), "Must return void"); TypeDescriptor<?> expectedContextT = doFnFinishBundleContextTypeOf(inputT, outputT); Type[] params = m.getGenericParameterTypes(); errors.checkArgument( params.length == 0 || (params.length == 1 && fnT.resolveType(params[0]).equals(expectedContextT)), "Must take a single argument of type %s", formatType(expectedContextT)); return DoFnSignature.BundleMethod.create(m); }
@Override @SuppressWarnings("unchecked") public <T> SerializableFunction<Row, T> fromRowFunction(TypeDescriptor<T> typeDescriptor) { if (typeDescriptor.equals(TypeDescriptor.of(TestDefaultSchemaClass.class))) { return r -> (T) new TestSchemaClass(); } return null; } }
KV.class); checkArgument( inputTypeDescriptor.equals( TypeDescriptors.kvs(outputFormatKeyClass, outputFormatValueClass)), "%s expects following %ss: KV(Key: %s, Value: %s) but following %ss are set: KV(Key: %s, Value: %s)",
@Override @SuppressWarnings("unchecked") public <T> SerializableFunction<Row, T> fromRowFunction(TypeDescriptor<T> typeDescriptor) { if (typeDescriptor.equals(TypeDescriptor.of(TestSchemaClass.class))) { return r -> (T) new TestSchemaClass(); } return null; } }
@VisibleForTesting static DoFnSignature.SplitRestrictionMethod analyzeSplitRestrictionMethod( ErrorReporter errors, TypeDescriptor<? extends DoFn> fnT, Method m, TypeDescriptor<?> inputT) { // Method is of the form: // @SplitRestriction // void splitRestriction(InputT element, RestrictionT restriction); errors.checkArgument(void.class.equals(m.getReturnType()), "Must return void"); Type[] params = m.getGenericParameterTypes(); errors.checkArgument(params.length == 3, "Must have exactly 3 arguments"); errors.checkArgument( fnT.resolveType(params[0]).equals(inputT), "First argument must be the element type %s", formatType(inputT)); TypeDescriptor<?> restrictionT = fnT.resolveType(params[1]); TypeDescriptor<?> receiverT = fnT.resolveType(params[2]); TypeDescriptor<?> expectedReceiverT = outputReceiverTypeOf(restrictionT); errors.checkArgument( receiverT.equals(expectedReceiverT), "Third argument must be %s, but is %s", formatType(expectedReceiverT), formatType(receiverT)); return DoFnSignature.SplitRestrictionMethod.create(m, restrictionT); }
@Override public <T> SerializableFunction<T, Row> toRowFunction(TypeDescriptor<T> typeDescriptor) { if (typeDescriptor.equals(TypeDescriptor.of(TestSchemaClass.class))) { return v -> Row.withSchema(EMPTY_SCHEMA).build(); } return null; }
@Override public <T> SerializableFunction<T, Row> toRowFunction(TypeDescriptor<T> typeDescriptor) { if (typeDescriptor.equals(TypeDescriptor.of(TestDefaultSchemaClass.class))) { return v -> Row.withSchema(EMPTY_SCHEMA).build(); } return null; }
if (paramT.equals(TypeDescriptor.of(Row.class)) && !paramT.equals(inputT)) { } else { methodErrors.checkArgument( paramT.equals(inputT), "@Element argument must have type %s", inputT); return Parameter.elementParameter(paramT); } else if (rawType.equals(DoFn.ProcessContext.class)) { paramErrors.checkArgument( paramT.equals(expectedProcessContextT), "ProcessContext argument must have type %s", formatType(expectedProcessContextT)); } else if (rawType.equals(DoFn.OnTimerContext.class)) { paramErrors.checkArgument( paramT.equals(expectedOnTimerContextT), "OnTimerContext argument must have type %s", formatType(expectedOnTimerContextT)); paramT.equals(outputReceiverTypeOf(TypeDescriptor.of(Row.class))) && !outputT.equals(TypeDescriptor.of(Row.class)); if (!schemaRowReceiver) { TypeDescriptor<?> expectedReceiverT = outputReceiverTypeOf(outputT); paramErrors.checkArgument( paramT.equals(expectedReceiverT), "OutputReceiver should be parameterized by %s", outputT);
TypeDescriptor<?> restrictionT = getInitialRestriction.restrictionT(); getInitialRestrictionErrors.checkArgument( restrictionT.equals(newTracker.restrictionT()), "Uses restriction type %s, but @%s method %s uses restriction type %s", formatType(restrictionT), splitRestriction.restrictionT().equals(restrictionT), "Uses restriction type %s, but @%s method %s uses restriction type %s", formatType(restrictionT),
boolean toRow = outputTypeDescriptor.equals(TypeDescriptor.of(Row.class)); if (toRow) {