• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java InvalidTypesException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.flink.api.common.functions.InvalidTypesException的典型用法代码示例。如果您正苦于以下问题:Java InvalidTypesException类的具体用法?Java InvalidTypesException怎么用?Java InvalidTypesException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InvalidTypesException类属于org.apache.flink.api.common.functions包,在下文中一共展示了InvalidTypesException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testUnboundedPojoSourceButReturnInvalidTupleType

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@Test(expected = InvalidTypesException.class)
public void testUnboundedPojoSourceButReturnInvalidTupleType() throws Exception {
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DataStream<Event> input = env.addSource(new RandomEventSource(5).closeDelay(1500));

    DataStream<Tuple5<Long, Integer, String, Double, Long>> output = SiddhiCEP
        .define("inputStream", input, "id", "name", "price", "timestamp")
        .cql("from inputStream select timestamp, id, name, price insert into  outputStream")
        .returns("outputStream");

    DataStream<Long> following = output.map(new MapFunction<Tuple5<Long, Integer, String, Double, Long>, Long>() {
        @Override
        public Long map(Tuple5<Long, Integer, String, Double, Long> value) throws Exception {
            return value.f0;
        }
    });

    String resultPath = tempFolder.newFile().toURI().toString();
    following.writeAsText(resultPath, FileSystem.WriteMode.OVERWRITE);
    env.execute();
    assertEquals(5, getLineCount(resultPath));
    env.execute();
}
 
开发者ID:apache,项目名称:bahir-flink,代码行数:24,代码来源:SiddhiCEPITCase.java


示例2: getTypeInformation

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private <OUT> TypeInformation<OUT> getTypeInformation(EsperSelectFunction<OUT> esperSelectFunction) {
    try {
        TypeExtractionUtils.LambdaExecutable lambdaExecutable = TypeExtractionUtils.checkAndExtractLambda(esperSelectFunction);
        if (esperSelectFunction instanceof ResultTypeQueryable) {
            return ((ResultTypeQueryable<OUT>) esperSelectFunction).getProducedType();
        }
        if (lambdaExecutable != null) {
            Type type = lambdaExecutable.getReturnType();
            return (TypeInformation<OUT>) TypeExtractor.createTypeInfo(type);
        }
        else {
            return TypeExtractor.createTypeInfo(esperSelectFunction, EsperSelectFunction.class, esperSelectFunction.getClass(), 0);
        }
    } catch (TypeExtractionException e) {
        throw new InvalidTypesException("Could not extract types.", e);
    }
}
 
开发者ID:phil3k3,项目名称:flink-esper,代码行数:19,代码来源:EsperStream.java


示例3: PravegaDeserializationSchema

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
/**
 * Creates a new PravegaDeserializationSchema using the given Pravega serializer, and the
 * type described by the type class.
 *
 * <p>Use this constructor if the produced type is not generic and can be fully described by
 * a class. If the type is generic, use the {@link #PravegaDeserializationSchema(TypeHint, Serializer)}
 * constructor instead.
 * 
 * @param typeClass  The class describing the deserialized type.
 * @param serializer The serializer to deserialize the byte messages.
 */
public PravegaDeserializationSchema(Class<T> typeClass, Serializer<T> serializer) {
    checkNotNull(typeClass);
    checkSerializer(serializer);

    this.serializer = serializer;

    try {
        this.typeInfo = TypeInformation.of(typeClass);
    } catch (InvalidTypesException e) {
        throw new IllegalArgumentException(
                "Due to Java's type erasure, the generic type information cannot be properly inferred. " + 
                "Please pass a 'TypeHint' instead of a class to describe the type. " +
                "For example, to describe 'Tuple2<String, String>' as a generic type, use " +
                "'new PravegaDeserializationSchema<>(new TypeHint<Tuple2<String, String>>(){}, serializer);'"
        );
    }
}
 
开发者ID:pravega,项目名称:flink-connectors,代码行数:29,代码来源:PravegaDeserializationSchema.java


示例4: testUnboundedPojoSourceButReturnInvalidTupleType

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@Test(expected = InvalidTypesException.class)
public void testUnboundedPojoSourceButReturnInvalidTupleType() throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
	DataStream<Event> input = env.addSource(new RandomEventSource(5).closeDelay(1500));

	DataStream<Tuple5<Long, Integer, String, Double, Long>> output = SiddhiCEP
		.define("inputStream", input, "id", "name", "price", "timestamp")
		.cql("from inputStream select timestamp, id, name, price insert into  outputStream")
		.returns("outputStream");

	DataStream<Long> following = output.map(new MapFunction<Tuple5<Long, Integer, String, Double, Long>, Long>() {
		@Override
		public Long map(Tuple5<Long, Integer, String, Double, Long> value) throws Exception {
			return value.f0;
		}
	});

	String resultPath = tempFolder.newFile().toURI().toString();
	following.writeAsText(resultPath, FileSystem.WriteMode.OVERWRITE);
	env.execute();
	assertEquals(5, getLineCount(resultPath));
	env.execute();
}
 
开发者ID:haoch,项目名称:flink-siddhi,代码行数:24,代码来源:SiddhiCEPITCase.java


示例5: testInputValidationError

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@Test
public void testInputValidationError() {

	RichMapFunction<Writable, String> function = new RichMapFunction<Writable, String>() {
		@Override
		public String map(Writable value) throws Exception {
			return null;
		}
	};

	@SuppressWarnings("unchecked")
	TypeInformation<Writable> inType =
			(TypeInformation<Writable>) (TypeInformation<?>) new WritableTypeInfo<>(DirectWritable.class);

	try {
		TypeExtractor.getMapReturnTypes(function, inType);
		fail("exception expected");
	}
	catch (InvalidTypesException e) {
		// right
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:WritableExtractionTest.java


示例6: getTypeInfoFactory

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
/**
 * Returns the type information factory for a type using the factory registry or annotations.
 */
@Internal
public static <OUT> TypeInfoFactory<OUT> getTypeInfoFactory(Type t) {
	final Class<?> factoryClass;
	if (registeredTypeInfoFactories.containsKey(t)) {
		factoryClass = registeredTypeInfoFactories.get(t);
	}
	else {
		if (!isClassType(t) || !typeToClass(t).isAnnotationPresent(TypeInfo.class)) {
			return null;
		}
		final TypeInfo typeInfoAnnotation = typeToClass(t).getAnnotation(TypeInfo.class);
		factoryClass = typeInfoAnnotation.value();
		// check for valid factory class
		if (!TypeInfoFactory.class.isAssignableFrom(factoryClass)) {
			throw new InvalidTypesException("TypeInfo annotation does not specify a valid TypeInfoFactory.");
		}
	}

	// instantiate
	return (TypeInfoFactory<OUT>) InstantiationUtil.instantiate(factoryClass);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:25,代码来源:TypeExtractor.java


示例7: getAllDeclaredFields

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
/**
 * Recursively determine all declared fields
 * This is required because class.getFields() is not returning fields defined
 * in parent classes.
 *
 * @param clazz class to be analyzed
 * @param ignoreDuplicates if true, in case of duplicate field names only the lowest one
 *                            in a hierarchy will be returned; throws an exception otherwise
 * @return list of fields
 */
@PublicEvolving
public static List<Field> getAllDeclaredFields(Class<?> clazz, boolean ignoreDuplicates) {
	List<Field> result = new ArrayList<Field>();
	while (clazz != null) {
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			if(Modifier.isTransient(field.getModifiers()) || Modifier.isStatic(field.getModifiers())) {
				continue; // we have no use for transient or static fields
			}
			if(hasFieldWithSameName(field.getName(), result)) {
				if (ignoreDuplicates) {
					continue;
				} else {
					throw new InvalidTypesException("The field "+field+" is already contained in the hierarchy of the "+clazz+"."
						+ "Please use unique field names through your classes hierarchy");
				}
			}
			result.add(field);
		}
		clazz = clazz.getSuperclass();
	}
	return result;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:34,代码来源:TypeExtractor.java


示例8: createTypeInfo

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@Override
public TypeInformation<Either<L, R>> createTypeInfo(Type t, Map<String, TypeInformation<?>> genericParameters) {
	TypeInformation<?> leftType = genericParameters.get("L");
	TypeInformation<?> rightType = genericParameters.get("R");

	if (leftType == null) {
		throw new InvalidTypesException("Type extraction is not possible on Either" +
			" type as it does not contain information about the 'left' type.");
	}

	if (rightType == null) {
		throw new InvalidTypesException("Type extraction is not possible on Either" +
			" type as it does not contain information about the 'right' type.");
	}

	return new EitherTypeInfo(leftType, rightType);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:EitherTypeInfoFactory.java


示例9: extractTypeArgument

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
/**
 * This method extracts the n-th type argument from the given type. An InvalidTypesException
 * is thrown if the type does not have any type arguments or if the index exceeds the number
 * of type arguments.
 *
 * @param t Type to extract the type arguments from
 * @param index Index of the type argument to extract
 * @return The extracted type argument
 * @throws InvalidTypesException if the given type does not have any type arguments or if the
 * index exceeds the number of type arguments.
 */
public static Type extractTypeArgument(Type t, int index) throws InvalidTypesException {
	if (t instanceof ParameterizedType) {
		Type[] actualTypeArguments = ((ParameterizedType) t).getActualTypeArguments();

		if (index < 0 || index >= actualTypeArguments.length) {
			throw new InvalidTypesException("Cannot extract the type argument with index " +
											index + " because the type has only " + actualTypeArguments.length +
											" type arguments.");
		} else {
			return actualTypeArguments[index];
		}
	} else {
		throw new InvalidTypesException("The given type " + t + " is not a parameterized type.");
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:TypeExtractionUtils.java


示例10: getSingleAbstractMethod

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
/**
 * Extracts a Single Abstract Method (SAM) as defined in Java Specification (4.3.2. The Class Object,
 * 9.8 Functional Interfaces, 9.4.3 Interface Method Body) from given class.
 *
 * @param baseClass a class that is a FunctionalInterface to retrieve a SAM from
 * @throws InvalidTypesException if the given class does not implement FunctionalInterface
 * @return single abstract method of the given class
 */
public static Method getSingleAbstractMethod(Class<?> baseClass) {

	if (!baseClass.isInterface()) {
		throw new InvalidTypesException("Given class: " + baseClass + "is not a FunctionalInterface.");
	}

	Method sam = null;
	for (Method method : baseClass.getMethods()) {
		if (Modifier.isAbstract(method.getModifiers())) {
			if (sam == null) {
				sam = method;
			} else {
				throw new InvalidTypesException("Given class: " + baseClass +
					" is not a FunctionalInterface. It has more than one abstract method.");
			}
		}
	}

	if (sam == null) {
		throw new InvalidTypesException(
			"Given class: " + baseClass + " is not a FunctionalInterface. It does not have any abstract methods.");
	}

	return sam;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:34,代码来源:TypeExtractionUtils.java


示例11: testMissingTupleGenerics

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testMissingTupleGenerics() {
	RichMapFunction<?, ?> function = new RichMapFunction<String, Tuple2>() {
		private static final long serialVersionUID = 1L;

		@Override
		public Tuple2 map(String value) throws Exception {
			return null;
		}
	};

	TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"), "name", true);
	Assert.assertTrue(ti instanceof MissingTypeInfo);
	
	try {
		TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"));
		Assert.fail("Expected an exception");
	}
	catch (InvalidTypesException e) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:TypeExtractorTest.java


示例12: testTupleSupertype

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTupleSupertype() {
	RichMapFunction<?, ?> function = new RichMapFunction<String, Tuple>() {
		private static final long serialVersionUID = 1L;

		@Override
		public Tuple map(String value) throws Exception {
			return null;
		}
	};

	TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"), "name", true);
	Assert.assertTrue(ti instanceof MissingTypeInfo);
	
	try {
		TypeExtractor.getMapReturnTypes(function, (TypeInformation) TypeInfoParser.parse("String"));
		Assert.fail("Expected an exception");
	}
	catch (InvalidTypesException e) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:TypeExtractorTest.java


示例13: testFunctionWithMissingGenerics

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testFunctionWithMissingGenerics() {
	RichMapFunction function = new RichMapFunction() {
		private static final long serialVersionUID = 1L;

		@Override
		public String map(Object value) throws Exception {
			return null;
		}
	};

	TypeInformation<?> ti = TypeExtractor.getMapReturnTypes(function, TypeInfoParser.parse("String"), "name", true);
	Assert.assertTrue(ti instanceof MissingTypeInfo);
	
	try {
		TypeExtractor.getMapReturnTypes(function, TypeInfoParser.parse("String"));
		Assert.fail("Expected an exception");
	}
	catch (InvalidTypesException e) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:TypeExtractorTest.java


示例14: testValueSupertypeException

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testValueSupertypeException() {
	RichMapFunction<?, ?> function = new RichMapFunction<StringValue, Value>() {
		private static final long serialVersionUID = 1L;

		@Override
		public Value map(StringValue value) throws Exception {
			return null;
		}
	};

	TypeInformation<?> ti =TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInfoParser.parse("StringValue"), "name", true);
	Assert.assertTrue(ti instanceof MissingTypeInfo);
	
	try {
		TypeExtractor.getMapReturnTypes(function, (TypeInformation)TypeInfoParser.parse("StringValue"));
		Assert.fail("Expected an exception");
	}
	catch (InvalidTypesException e) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:24,代码来源:TypeExtractorTest.java


示例15: testFunctionDependingOnInputWithTupleInputWithTypeMismatch

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@Test
public void testFunctionDependingOnInputWithTupleInputWithTypeMismatch() {
	IdentityMapper2<Boolean> function = new IdentityMapper2<Boolean>();

	TypeInformation<Tuple2<Boolean, String>> inputType = new TupleTypeInfo<Tuple2<Boolean, String>>(BasicTypeInfo.BOOLEAN_TYPE_INFO,
			BasicTypeInfo.INT_TYPE_INFO);
	
	// input is: Tuple2<Boolean, Integer>
	// allowed: Tuple2<?, String>

	try {
		TypeExtractor.getMapReturnTypes(function, inputType);
		Assert.fail("exception expected");
	} catch (InvalidTypesException e) {
		// right
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:TypeExtractorTest.java


示例16: testTypeErasure

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testTypeErasure() {
	TypeInformation<?> ti = TypeExtractor.getFlatMapReturnTypes(new DummyFlatMapFunction<String, Integer, String, Boolean>(), 
				(TypeInformation) TypeInfoParser.parse("Tuple2<String, Integer>"), "name", true);
	Assert.assertTrue(ti instanceof MissingTypeInfo);
	
	try {
		TypeExtractor.getFlatMapReturnTypes(new DummyFlatMapFunction<String, Integer, String, Boolean>(), 
				(TypeInformation) TypeInfoParser.parse("Tuple2<String, Integer>"));
		
		Assert.fail("Expected an exception");
	}
	catch (InvalidTypesException e) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:TypeExtractorTest.java


示例17: testInputValidationError

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
@Test
public void testInputValidationError() {

	RichMapFunction<Writable, String> function = new RichMapFunction<Writable, String>() {
		@Override
		public String map(Writable value) throws Exception {
			return null;
		}
	};

	@SuppressWarnings("unchecked")
	TypeInformation<Writable> inType = 
			(TypeInformation<Writable>) (TypeInformation<?>) new WritableTypeInfo<>(DirectWritable.class);
	
	try {
		TypeExtractor.getMapReturnTypes(function, inType);
		fail("exception expected");
	}
	catch (InvalidTypesException e) {
		// right
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:23,代码来源:WritableExtractionTest.java


示例18: getOutputType

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
/**
 * Returns the output type of this {@code StreamTransformation} as a {@link TypeInformation}. Once
 * this is used once the output type cannot be changed anymore using {@link #setOutputType}.
 *
 * @return The output type of this {@code StreamTransformation}
 */
public TypeInformation<T> getOutputType() {
	if (outputType instanceof MissingTypeInfo) {
		MissingTypeInfo typeInfo = (MissingTypeInfo) this.outputType;
		throw new InvalidTypesException(
				"The return type of function '"
						+ typeInfo.getFunctionName()
						+ "' could not be determined automatically, due to type erasure. "
						+ "You can give type information hints by using the returns(...) "
						+ "method on the result of the transformation call, or by letting "
						+ "your function implement the 'ResultTypeQueryable' "
						+ "interface.", typeInfo.getTypeException());
	}
	typeUsed = true;
	return this.outputType;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:StreamTransformation.java


示例19: getSelectorForKeys

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
public static <X> KeySelector<X, Tuple> getSelectorForKeys(Keys<X> keys, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) {
	if (!(typeInfo instanceof CompositeType)) {
		throw new InvalidTypesException(
				"This key operation requires a composite type such as Tuples, POJOs, or Case Classes.");
	}

	CompositeType<X> compositeType = (CompositeType<X>) typeInfo;

	int[] logicalKeyPositions = keys.computeLogicalKeyPositions();
	int numKeyFields = logicalKeyPositions.length;

	TypeInformation<?>[] typeInfos = keys.getKeyFieldTypes();
	// use ascending order here, the code paths for that are usually a slight bit faster
	boolean[] orders = new boolean[numKeyFields];
	for (int i = 0; i < numKeyFields; i++) {
		orders[i] = true;
	}

	TypeComparator<X> comparator = compositeType.createComparator(logicalKeyPositions, orders, 0, executionConfig);
	return new ComparableKeySelector<>(comparator, numKeyFields, new TupleTypeInfo<>(typeInfos));
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:KeySelectorUtil.java


示例20: getSelectorForOneKey

import org.apache.flink.api.common.functions.InvalidTypesException; //导入依赖的package包/类
public static <X, K> KeySelector<X, K> getSelectorForOneKey(
		Keys<X> keys, Partitioner<K> partitioner, TypeInformation<X> typeInfo, ExecutionConfig executionConfig) {
	if (!(typeInfo instanceof CompositeType)) {
		throw new InvalidTypesException(
				"This key operation requires a composite type such as Tuples, POJOs, case classes, etc");
	}
	if (partitioner != null) {
		keys.validateCustomPartitioner(partitioner, null);
	}

	CompositeType<X> compositeType = (CompositeType<X>) typeInfo;
	int[] logicalKeyPositions = keys.computeLogicalKeyPositions();
	if (logicalKeyPositions.length != 1) {
		throw new IllegalArgumentException("There must be exactly 1 key specified");
	}

	TypeComparator<X> comparator = compositeType.createComparator(
			logicalKeyPositions, new boolean[] { true }, 0, executionConfig);
	return new OneKeySelector<>(comparator);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:KeySelectorUtil.java



注:本文中的org.apache.flink.api.common.functions.InvalidTypesException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SignatureAlgorithmIdentifierFinder类代码示例发布时间:2022-05-23
下一篇:
Java VirtGraph类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap