org.apache.beam.sdk.values.TypeDescriptor.resolveType()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(79)

本文整理了Java中org.apache.beam.sdk.values.TypeDescriptor.resolveType()方法的一些代码示例,展示了TypeDescriptor.resolveType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeDescriptor.resolveType()方法的具体详情如下:
包路径:org.apache.beam.sdk.values.TypeDescriptor
类名称:TypeDescriptor
方法名:resolveType

TypeDescriptor.resolveType介绍

[英]Returns a TypeDescriptor representing the given type, with type variables resolved according to the specialization in this type.

For example, consider the following class:

class MyList implements List { ... } 
}

The TypeDescriptor returned by

TypeDescriptor.of(MyList.class)

will represent the type String.
[中]

代码示例

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Nullable
private static TypeDescriptor<? extends BoundedWindow> getWindowType(
  TypeDescriptor<?> fnClass, Method method) {
 Type[] params = method.getGenericParameterTypes();
 for (Type param : params) {
  TypeDescriptor<?> paramT = fnClass.resolveType(param);
  if (BoundedWindow.class.isAssignableFrom(paramT.getRawType())) {
   return (TypeDescriptor<? extends BoundedWindow>) paramT;
  }
 }
 return null;
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@Nullable
private static TypeDescriptor<?> getTrackerType(TypeDescriptor<?> fnClass, Method method) {
 Type[] params = method.getGenericParameterTypes();
 for (Type param : params) {
  TypeDescriptor<?> paramT = fnClass.resolveType(param);
  if (RestrictionTracker.class.isAssignableFrom(paramT.getRawType())) {
   return paramT;
  }
 }
 return null;
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@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()));
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

private void checkMap(String context, TypeDescriptor<?> type, Schema schema) {
 if (!isSubtypeOf(type, SortedMap.class)) {
  reportError(context, "%s may not be deterministically ordered", type);
 }
 // Avro (currently) asserts that all keys are strings.
 // In case that changes, we double check that the key was a string:
 Class<?> keyType = type.resolveType(Map.class.getTypeParameters()[0]).getRawType();
 if (!String.class.equals(keyType)) {
  reportError(context, "map keys should be Strings, but was %s", keyType);
 }
 recurse(context, type.resolveType(Map.class.getTypeParameters()[1]), schema.getValueType());
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

private void checkRecord(TypeDescriptor<?> type, Schema schema) {
 // For a record, we want to make sure that all the fields are deterministic.
 Class<?> clazz = type.getRawType();
 for (Schema.Field fieldSchema : schema.getFields()) {
  Field field = getField(clazz, fieldSchema.name());
  String fieldContext = field.getDeclaringClass().getName() + "#" + field.getName();
  if (field.isAnnotationPresent(AvroEncode.class)) {
   reportError(
     fieldContext, "Custom encoders may be non-deterministic -- remove @AvroEncode");
   continue;
  }
  if (!IndexedRecord.class.isAssignableFrom(field.getType())
    && field.isAnnotationPresent(AvroSchema.class)) {
   // TODO: We should be able to support custom schemas on POJO fields, but we shouldn't
   // need to, so we just allow it in the case of IndexedRecords.
   reportError(
     fieldContext, "Custom schemas are only supported for subtypes of IndexedRecord.");
   continue;
  }
  TypeDescriptor<?> fieldType = type.resolveType(field.getGenericType());
  recurse(fieldContext, fieldType, fieldSchema.schema());
 }
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

/** Returns the {@link TypeDescriptor} for the type encoded. */
@Experimental(Kind.CODER_TYPE_ENCODING)
public TypeDescriptor<T> getEncodedTypeDescriptor() {
 return (TypeDescriptor<T>)
   TypeDescriptor.of(getClass()).resolveType(new TypeDescriptor<T>() {}.getType());
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@VisibleForTesting
static DoFnSignature.GetRestrictionCoderMethod analyzeGetRestrictionCoderMethod(
  ErrorReporter errors, TypeDescriptor<? extends DoFn> fnT, Method m) {
 errors.checkArgument(m.getParameterTypes().length == 0, "Must have zero arguments");
 TypeDescriptor<?> resT = fnT.resolveType(m.getGenericReturnType());
 errors.checkArgument(
   resT.isSubtypeOf(TypeDescriptor.of(Coder.class)),
   "Must return a Coder, but returns %s",
   formatType(resT));
 return DoFnSignature.GetRestrictionCoderMethod.create(m, resT);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@VisibleForTesting
static DoFnSignature.NewTrackerMethod analyzeNewTrackerMethod(
  ErrorReporter errors, TypeDescriptor<? extends DoFn> fnT, Method m) {
 // Method is of the form:
 // @NewTracker
 // TrackerT newTracker(RestrictionT restriction);
 Type[] params = m.getGenericParameterTypes();
 errors.checkArgument(params.length == 1, "Must have a single argument");
 TypeDescriptor<?> restrictionT = fnT.resolveType(params[0]);
 TypeDescriptor<?> trackerT = fnT.resolveType(m.getGenericReturnType());
 TypeDescriptor<?> expectedTrackerT = restrictionTrackerTypeOf(restrictionT);
 errors.checkArgument(
   trackerT.isSubtypeOf(expectedTrackerT),
   "Returns %s, but must return a subtype of %s",
   formatType(trackerT),
   formatType(expectedTrackerT));
 return DoFnSignature.NewTrackerMethod.create(m, restrictionT, trackerT);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@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);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@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);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-hadoop-format

outputFormatValueClass.getRawType(),
TypeDescriptor.class.getSimpleName(),
inputTypeDescriptor.resolveType(KV.class.getTypeParameters()[0]),
inputTypeDescriptor.resolveType(KV.class.getTypeParameters()[1]));

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

m,
  i,
  fnClass.resolveType(params[i]),
  Arrays.asList(m.getParameterAnnotations()[i])),
inputT,

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

m,
  i,
  fnClass.resolveType(params[i]),
  Arrays.asList(m.getParameterAnnotations()[i])),
inputT,

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

@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);
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

TypeDescriptor.of(fnClazz).resolveType(unresolvedStateType);

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

m,
  i,
  fnClass.resolveType(params[i]),
  Arrays.asList(m.getParameterAnnotations()[i])),
inputT,

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

Coder<?> typeArgumentCoder = typeArgumentCoders.get(i);
 verifyCompatible(
   typeArgumentCoder, candidateDescriptor.resolveType(typeArguments[i]).getType());
} catch (IncompatibleCoderException exn) {
 throw new IncompatibleCoderException(

代码示例来源:origin: org.apache.beam/beam-sdks-java-core

private void checkArray(String context, TypeDescriptor<?> type, Schema schema) {
 TypeDescriptor<?> elementType = null;
 if (type.isArray()) {
  // The type is an array (with ordering)-> deterministic iff the element is deterministic.
  elementType = type.getComponentType();
 } else if (isSubtypeOf(type, Collection.class)) {
  if (isSubtypeOf(type, List.class, SortedSet.class)) {
   // Ordered collection -> deterministic iff the element is deterministic
   elementType = type.resolveType(Collection.class.getTypeParameters()[0]);
  } else {
   // Not an ordered collection -> not deterministic
   reportError(context, "%s may not be deterministically ordered", type);
   return;
  }
 } else {
  // If it was an unknown type encoded as an array, be conservative and assume
  // that we don't know anything about the order.
  reportError(context, "encoding %s as an ARRAY was unexpected", type);
  return;
 }
 // If we get here, it's either a deterministically-ordered Collection, or
 // an array. Either way, the type is deterministic iff the element type is
 // deterministic.
 recurse(context, elementType, schema.getElementType());
}

相关文章