本文整理了Java中org.apache.beam.sdk.values.TypeDescriptor.isSubtypeOf()
方法的一些代码示例,展示了TypeDescriptor.isSubtypeOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeDescriptor.isSubtypeOf()
方法的具体详情如下:
包路径:org.apache.beam.sdk.values.TypeDescriptor
类名称:TypeDescriptor
方法名:isSubtypeOf
[英]Return true if this type is a subtype of the given type.
[中]如果此类型是给定类型的子类型,则返回true。
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
/** Return true if the given type token is a subtype of *any* of the listed parents. */
private static boolean isSubtypeOf(TypeDescriptor<?> type, Class<?>... parents) {
for (Class<?> parent : parents) {
if (type.isSubtypeOf(TypeDescriptor.of(parent))) {
return true;
}
}
return false;
}
代码示例来源:origin: org.apache.beam/beam-runners-google-cloud-dataflow-java
static void verifyStateSupported(DoFn<?, ?> fn) {
DoFnSignature signature = DoFnSignatures.getSignature(fn.getClass());
for (DoFnSignature.StateDeclaration stateDecl : signature.stateDeclarations().values()) {
// https://issues.apache.org/jira/browse/BEAM-1474
if (stateDecl.stateType().isSubtypeOf(TypeDescriptor.of(MapState.class))) {
throw new UnsupportedOperationException(
String.format(
"%s does not currently support %s",
DataflowRunner.class.getSimpleName(), MapState.class.getSimpleName()));
}
// https://issues.apache.org/jira/browse/BEAM-1479
if (stateDecl.stateType().isSubtypeOf(TypeDescriptor.of(SetState.class))) {
throw new UnsupportedOperationException(
String.format(
"%s does not currently support %s",
DataflowRunner.class.getSimpleName(), SetState.class.getSimpleName()));
}
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-hbase
@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);
}
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-hadoop-common
@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);
}
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-protobuf
@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);
}
}
}
代码示例来源: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
/** Get a {@link FieldType} from a {@link TypeDescriptor}. */
public static FieldType fieldTypeForJavaType(TypeDescriptor typeDescriptor) {
if (typeDescriptor.isArray()
|| typeDescriptor.isSubtypeOf(TypeDescriptor.of(Collection.class))) {
return getArrayFieldType(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Map.class))) {
return getMapFieldType(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Row.class))) {
throw new IllegalArgumentException(
"Cannot automatically determine a field type from a Row class"
+ " as we cannot determine the schema. You should set a field type explicitly.");
} else {
TypeName typeName = PRIMITIVE_MAPPING.inverse().get(typeDescriptor);
if (typeName == null) {
throw new RuntimeException("Couldn't find field type for " + typeDescriptor);
}
FieldType fieldType = FieldType.of(typeName);
return fieldType;
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@SuppressWarnings("unchecked")
private static Implementation getMapType(TypeDescriptor valueType, int index) {
if (valueType.isSubtypeOf(TypeDescriptor.of(Map.class))) {
TypeDescriptor<Collection<?>> map = valueType.getSupertype(Map.class);
if (map.getType() instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) map.getType();
java.lang.reflect.Type[] params = ptype.getActualTypeArguments();
return FixedValue.reference(params[index]);
} else {
throw new RuntimeException("Map type is not parameterized! " + map);
}
}
return FixedValue.nullValue();
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
public T convert(TypeDescriptor typeDescriptor) {
if (typeDescriptor.isArray()
&& !typeDescriptor.getComponentType().getRawType().equals(byte.class)) {
// Byte arrays are special, so leave those alone.
return convertArray(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Collection.class))) {
return convertCollection(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Map.class))) {
return convertMap(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(ReadableInstant.class))) {
return convertDateTime(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(ByteBuffer.class))) {
return convertByteBuffer(typeDescriptor);
} else if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(CharSequence.class))) {
return convertCharSequence(typeDescriptor);
} else if (typeDescriptor.getRawType().isPrimitive()) {
return convertPrimitive(typeDescriptor);
} else {
return convertDefault(typeDescriptor);
}
}
代码示例来源: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
if (!(TypeDescriptor.of(stateSpecRawType).isSubtypeOf(TypeDescriptor.of(StateSpec.class)))) {
errors.throwIllegalArgument(
"%s annotation on non-%s field [%s] that has class %s",
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@SuppressWarnings("unchecked")
static Implementation getArrayComponentType(TypeDescriptor valueType) {
if (valueType.isArray()) {
Type component = valueType.getComponentType().getType();
if (!component.equals(byte.class)) {
return FixedValue.reference(component);
}
} else if (valueType.isSubtypeOf(TypeDescriptor.of(Collection.class))) {
TypeDescriptor<Collection<?>> collection = valueType.getSupertype(Collection.class);
if (collection.getType() instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) collection.getType();
java.lang.reflect.Type[] params = ptype.getActualTypeArguments();
checkArgument(params.length == 1);
return FixedValue.reference(params[0]);
} else {
throw new RuntimeException("Collection parameter is not parameterized!");
}
}
return FixedValue.nullValue();
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
} else if (type.isSubtypeOf(TypeDescriptor.of(Collection.class))) {
TypeDescriptor<Collection<?>> collection = type.getSupertype(Collection.class);
if (collection.getType() instanceof ParameterizedType) {
throw new RuntimeException("Cannot infer schema from unparameterized collection.");
} else if (type.isSubtypeOf(TypeDescriptor.of(Map.class))) {
TypeDescriptor<Collection<?>> map = type.getSupertype(Map.class);
if (map.getType() instanceof ParameterizedType) {
throw new RuntimeException("Cannot infer schema from unparameterized map.");
} else if (type.isSubtypeOf(TypeDescriptor.of(CharSequence.class))) {
return FieldType.STRING;
} else if (type.isSubtypeOf(TypeDescriptor.of(ReadableInstant.class))) {
return FieldType.DATETIME;
} else if (type.isSubtypeOf(TypeDescriptor.of(ByteBuffer.class))) {
return FieldType.BYTES;
} else {
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
private static FieldType getArrayFieldType(TypeDescriptor typeDescriptor) {
if (typeDescriptor.isArray()) {
if (typeDescriptor.getComponentType().getType().equals(byte.class)) {
return FieldType.BYTES;
} else {
return FieldType.array(fieldTypeForJavaType(typeDescriptor.getComponentType()));
}
}
if (typeDescriptor.isSubtypeOf(TypeDescriptor.of(Collection.class))) {
TypeDescriptor<Collection<?>> collection = typeDescriptor.getSupertype(Collection.class);
if (collection.getType() instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) collection.getType();
java.lang.reflect.Type[] params = ptype.getActualTypeArguments();
checkArgument(params.length == 1);
return FieldType.array(fieldTypeForJavaType(TypeDescriptor.of(params[0])));
}
}
throw new RuntimeException("Could not determine array parameter type for field.");
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
@Override
protected StackManipulation convertCharSequence(TypeDescriptor<?> type) {
// If the member is a String, then return it.
if (type.isSubtypeOf(TypeDescriptor.of(String.class))) {
return readValue;
}
// Otherwise, generate the following code:
// return value.toString();
return new Compound(
readValue,
MethodInvocation.invoke(
CHAR_SEQUENCE_TYPE
.getDeclaredMethods()
.filter(ElementMatchers.named("toString"))
.getOnly()));
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
stateDecl.stateType().isSubtypeOf(stateType),
"data type of reference to %s %s must be a supertype of %s",
StateId.class.getSimpleName(),
代码示例来源:origin: org.apache.beam/beam-sdks-java-core
&& getInitialRestriction
.restrictionT()
.isSubtypeOf(TypeDescriptor.of(HasDefaultTracker.class))) {
getRestrictionCoder.coderT().isSubtypeOf(coderTypeOf(restrictionT)),
"Uses restriction type %s, but @%s method %s returns %s "
+ "which is not a subtype of %s",
内容来源于网络,如有侵权,请联系作者删除!