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

Java GenericTypeInfo类代码示例

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

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



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

示例1: toWarningStream

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
private static <TWarningType extends IWarning> DataStream<TWarningType> toWarningStream(DataStream<LocalWeatherData> localWeatherDataDataStream, IWarningPattern<LocalWeatherData, TWarningType> warningPattern) {
    PatternStream<LocalWeatherData> tempPatternStream = CEP.pattern(
            localWeatherDataDataStream.keyBy(new KeySelector<LocalWeatherData, String>() {
                @Override
                public String getKey(LocalWeatherData localWeatherData) throws Exception {
                    return localWeatherData.getStation().getWban();
                }
            }),
            warningPattern.getEventPattern());

    DataStream<TWarningType> warnings = tempPatternStream.select(new PatternSelectFunction<LocalWeatherData, TWarningType>() {
        @Override
        public TWarningType select(Map<String, List<LocalWeatherData>> map) throws Exception {
            return warningPattern.create(map);
        }
    }, new GenericTypeInfo<TWarningType>(warningPattern.getWarningTargetType()));

    return warnings;
}
 
开发者ID:bytefish,项目名称:FlinkExperiments,代码行数:20,代码来源:WeatherDataComplexEventProcessingExample2.java


示例2: createStateInternals

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Override
protected StateInternals createStateInternals() {
  MemoryStateBackend backend = new MemoryStateBackend();
  try {
    AbstractKeyedStateBackend<ByteBuffer> keyedStateBackend = backend.createKeyedStateBackend(
        new DummyEnvironment("test", 1, 0),
        new JobID(),
        "test_op",
        new GenericTypeInfo<>(ByteBuffer.class).createSerializer(new ExecutionConfig()),
        1,
        new KeyGroupRange(0, 0),
        new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));

    keyedStateBackend.setCurrentKey(
        ByteBuffer.wrap(CoderUtils.encodeToByteArray(StringUtf8Coder.of(), "Hello")));

    return new FlinkStateInternals<>(keyedStateBackend, StringUtf8Coder.of());
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:22,代码来源:FlinkStateInternalsTest.java


示例3: getKeyedStateBackend

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
private static KeyedStateBackend<ByteBuffer> getKeyedStateBackend(int numberOfKeyGroups,
                                                 KeyGroupRange keyGroupRange) {
  MemoryStateBackend backend = new MemoryStateBackend();
  try {
    AbstractKeyedStateBackend<ByteBuffer> keyedStateBackend = backend.createKeyedStateBackend(
        new DummyEnvironment("test", 1, 0),
        new JobID(),
        "test_op",
        new GenericTypeInfo<>(ByteBuffer.class).createSerializer(new ExecutionConfig()),
        numberOfKeyGroups,
        keyGroupRange,
        new KvStateRegistry().createTaskRegistry(new JobID(), new JobVertexID()));
    keyedStateBackend.setCurrentKey(ByteBuffer.wrap(
        CoderUtils.encodeToByteArray(StringUtf8Coder.of(), "1")));
    return keyedStateBackend;
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:20,代码来源:FlinkKeyGroupStateInternalsTest.java


示例4: convertToTypeInformation

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
/**
 * Recursively converts extracted AvroTypeInfo into a RowTypeInfo nested structure with deterministic field order.
 * Replaces generic Utf8 with basic String type information.
 */
private static TypeInformation<?> convertToTypeInformation(TypeInformation<?> extracted, Schema schema) {
	if (schema.getType() == Schema.Type.RECORD) {
		final List<Schema.Field> fields = schema.getFields();
		final AvroTypeInfo<?> avroTypeInfo = (AvroTypeInfo<?>) extracted;

		final TypeInformation<?>[] types = new TypeInformation<?>[fields.size()];
		final String[] names = new String[fields.size()];
		for (int i = 0; i < fields.size(); i++) {
			final Schema.Field field = fields.get(i);
			types[i] = convertToTypeInformation(avroTypeInfo.getTypeAt(field.name()), field.schema());
			names[i] = field.name();
		}
		return new RowTypeInfo(types, names);
	} else if (extracted instanceof GenericTypeInfo<?>) {
		final GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) extracted;
		if (genericTypeInfo.getTypeClass() == Utf8.class) {
			return BasicTypeInfo.STRING_TYPE_INFO;
		}
	}
	return extracted;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:26,代码来源:KafkaAvroTableSource.java


示例5: getSerializerTree

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
private static <T> String getSerializerTree(TypeInformation<T> ti, int indent) {
	String ret = "";
	if (ti instanceof CompositeType) {
		ret += StringUtils.repeat(' ', indent) + ti.getClass().getSimpleName() + "\n";
		CompositeType<T> cti = (CompositeType<T>) ti;
		String[] fieldNames = cti.getFieldNames();
		for (int i = 0; i < cti.getArity(); i++) {
			TypeInformation<?> fieldType = cti.getTypeAt(i);
			ret += StringUtils.repeat(' ', indent + 2) + fieldNames[i] + ":" + getSerializerTree(fieldType, indent);
		}
	} else {
		if (ti instanceof GenericTypeInfo) {
			ret += StringUtils.repeat(' ', indent) + "GenericTypeInfo (" + ti.getTypeClass().getSimpleName() + ")\n";
			ret += getGenericTypeTree(ti.getTypeClass(), indent + 4);
		} else {
			ret += StringUtils.repeat(' ', indent) + ti.toString() + "\n";
		}
	}
	return ret;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:21,代码来源:Utils.java


示例6: recursivelyRegisterType

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
public static void recursivelyRegisterType(TypeInformation<?> typeInfo, ExecutionConfig config, Set<Class<?>> alreadySeen) {
	if (typeInfo instanceof GenericTypeInfo) {
		GenericTypeInfo<?> genericTypeInfo = (GenericTypeInfo<?>) typeInfo;
		Serializers.recursivelyRegisterType(genericTypeInfo.getTypeClass(), config, alreadySeen);
	}
	else if (typeInfo instanceof CompositeType) {
		List<GenericTypeInfo<?>> genericTypesInComposite = new ArrayList<>();
		getContainedGenericTypes((CompositeType<?>)typeInfo, genericTypesInComposite);
		for (GenericTypeInfo<?> gt : genericTypesInComposite) {
			Serializers.recursivelyRegisterType(gt.getTypeClass(), config, alreadySeen);
		}
	}
	else if (typeInfo instanceof ObjectArrayTypeInfo) {
		ObjectArrayTypeInfo<?, ?> objectArrayTypeInfo = (ObjectArrayTypeInfo<?, ?>) typeInfo;
		recursivelyRegisterType(objectArrayTypeInfo.getComponentInfo(), config, alreadySeen);
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:Serializers.java


示例7: validateCustomPartitioner

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Override
public <E> void validateCustomPartitioner(Partitioner<E> partitioner, TypeInformation<E> typeInfo) {

	if (keyFields.size() != 1) {
		throw new InvalidProgramException("Custom partitioners can only be used with keys that have one key field.");
	}
	
	if (typeInfo == null) {
		// try to extract key type from partitioner
		try {
			typeInfo = TypeExtractor.getPartitionerTypes(partitioner);
		}
		catch (Throwable t) {
			// best effort check, so we ignore exceptions
		}
	}

	// only check if type is known and not a generic type
	if (typeInfo != null && !(typeInfo instanceof GenericTypeInfo)) {
		// check equality of key and partitioner type
		if (!keyType.equals(typeInfo)) {
			throw new InvalidProgramException("The partitioner is incompatible with the key type. "
				+ "Partitioner type: " + typeInfo + " , key type: " + keyType);
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:27,代码来源:Keys.java


示例8: testTypeRegistrationFromTypeInfo

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Test
public void testTypeRegistrationFromTypeInfo() {
	ExecutionConfig conf = new ExecutionConfig();
	Serializers.recursivelyRegisterType(new GenericTypeInfo<>(ClassWithNested.class), conf, new HashSet<Class<?>>());

	KryoSerializer<String> kryo = new KryoSerializer<>(String.class, conf); // we create Kryo from another type.

	assertTrue(kryo.getKryo().getRegistration(FromNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(ClassWithNested.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Path.class).getId() > 0);

	// check if the generic type from one field is also registered (its very likely that
	// generic types are also used as fields somewhere.
	assertTrue(kryo.getKryo().getRegistration(FromGeneric1.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(FromGeneric2.class).getId() > 0);
	assertTrue(kryo.getKryo().getRegistration(Node.class).getId() > 0);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:SerializersTest.java


示例9: testDisableGenericTypes

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Test
public void testDisableGenericTypes() {
	ExecutionConfig conf = new ExecutionConfig();
	TypeInformation<Object> typeInfo = new GenericTypeInfo<Object>(Object.class);

	// by default, generic types are supported
	TypeSerializer<Object> serializer = typeInfo.createSerializer(conf);
	assertTrue(serializer instanceof KryoSerializer);

	// expect an exception when generic types are disabled
	conf.disableGenericTypes();
	try {
		typeInfo.createSerializer(conf);
		fail("should have failed with an exception");
	}
	catch (UnsupportedOperationException e) {
		// expected
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:20,代码来源:ExecutionConfigTest.java


示例10: testObjectArrayKeyRejection

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Test
public void testObjectArrayKeyRejection() {

	KeySelector<Tuple2<Integer[], String>, Object[]> keySelector =
			new KeySelector<Tuple2<Integer[], String>, Object[]>() {

				@Override
				public Object[] getKey(Tuple2<Integer[], String> value) throws Exception {
					Object[] ks = new Object[value.f0.length];
					for (int i = 0; i < ks.length; i++) {
						ks[i] = new Object();
					}
					return ks;
				}
			};

	ObjectArrayTypeInfo<Object[], Object> keyTypeInfo = ObjectArrayTypeInfo.getInfoFor(
			Object[].class, new GenericTypeInfo<>(Object.class));

	testKeyRejection(keySelector, keyTypeInfo);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:22,代码来源:DataStreamTest.java


示例11: testPojoWithGenericsSomeFieldsGeneric

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
/**
 * Test if the TypeExtractor is accepting untyped generics,
 * making them GenericTypes
 */
@Test
@Ignore // kryo needed.
public void testPojoWithGenericsSomeFieldsGeneric() {
	TypeInformation<?> typeForClass = TypeExtractor.createTypeInfo(PojoWithGenerics.class);
	Assert.assertTrue(typeForClass instanceof PojoTypeInfo<?>);
	PojoTypeInfo<?> pojoTypeForClass = (PojoTypeInfo<?>) typeForClass;
	for(int i = 0; i < pojoTypeForClass.getArity(); i++) {
		PojoField field = pojoTypeForClass.getPojoFieldAt(i);
		String name = field.field.getName();
		if(name.equals("field1")) {
			Assert.assertEquals(new GenericTypeInfo<Object>(Object.class), field.type);
		} else if (name.equals("field2")) {
			Assert.assertEquals(new GenericTypeInfo<Object>(Object.class), field.type);
		} else if (name.equals("key")) {
			Assert.assertEquals(BasicTypeInfo.INT_TYPE_INFO, field.type);
		} else {
			Assert.fail("Unexpected field "+field);
		}
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:25,代码来源:PojoTypeExtractionTest.java


示例12: getFieldType

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
private TypeInformation getFieldType(HCatFieldSchema fieldSchema) {

		switch(fieldSchema.getType()) {
			case INT:
				return BasicTypeInfo.INT_TYPE_INFO;
			case TINYINT:
				return BasicTypeInfo.BYTE_TYPE_INFO;
			case SMALLINT:
				return BasicTypeInfo.SHORT_TYPE_INFO;
			case BIGINT:
				return BasicTypeInfo.LONG_TYPE_INFO;
			case BOOLEAN:
				return BasicTypeInfo.BOOLEAN_TYPE_INFO;
			case FLOAT:
				return BasicTypeInfo.FLOAT_TYPE_INFO;
			case DOUBLE:
				return BasicTypeInfo.DOUBLE_TYPE_INFO;
			case STRING:
				return BasicTypeInfo.STRING_TYPE_INFO;
			case BINARY:
				return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;
			case ARRAY:
				return new GenericTypeInfo(List.class);
			case MAP:
				return new GenericTypeInfo(Map.class);
			case STRUCT:
				return new GenericTypeInfo(List.class);
			default:
				throw new IllegalArgumentException("Unknown data type \"" + fieldSchema.getType() + "\" encountered.");
		}
	}
 
开发者ID:axbaretto,项目名称:flink,代码行数:32,代码来源:HCatInputFormatBase.java


示例13: getContainedGenericTypes

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
/**
 * Returns all GenericTypeInfos contained in a composite type.
 *
 * @param typeInfo {@link CompositeType}
 */
private static void getContainedGenericTypes(CompositeType<?> typeInfo, List<GenericTypeInfo<?>> target) {
	for (int i = 0; i < typeInfo.getArity(); i++) {
		TypeInformation<?> type = typeInfo.getTypeAt(i);
		if (type instanceof CompositeType) {
			getContainedGenericTypes((CompositeType<?>) type, target);
		} else if (type instanceof GenericTypeInfo) {
			if (!target.contains(type)) {
				target.add((GenericTypeInfo<?>) type);
			}
		}
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:18,代码来源:Serializers.java


示例14: createSerializer

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Override
protected <T> TypeSerializer<T> createSerializer(Class<T> type) {
	ExecutionConfig conf = new ExecutionConfig();
	conf.registerTypeWithKryoSerializer(LocalDate.class, LocalDateSerializer.class);
	TypeInformation<T> typeInfo = new GenericTypeInfo<T>(type);
	return typeInfo.createSerializer(conf);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:8,代码来源:KryoWithCustomSerializersTest.java


示例15: testKeyGenericType

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Test
public void testKeyGenericType() {

	TypeInformation<GenericKeyType> genericType = new GenericTypeInfo<>(GenericKeyType.class);
	ExpressionKeys<GenericKeyType> ek = new ExpressionKeys<>("*", genericType);

	Assert.assertArrayEquals(new int[] {0}, ek.computeLogicalKeyPositions());
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:9,代码来源:ExpressionKeysTest.java


示例16: getFieldType

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
private TypeInformation getFieldType(HCatFieldSchema fieldSchema) {

		switch(fieldSchema.getType()) {
			case INT:
				return BasicTypeInfo.INT_TYPE_INFO;
			case TINYINT:
				return BasicTypeInfo.BYTE_TYPE_INFO;
			case SMALLINT:
				return BasicTypeInfo.SHORT_TYPE_INFO;
			case BIGINT:
				return BasicTypeInfo.LONG_TYPE_INFO;
			case BOOLEAN:
				return BasicTypeInfo.BOOLEAN_TYPE_INFO;
			case FLOAT:
				return BasicTypeInfo.FLOAT_TYPE_INFO;
			case DOUBLE:
				return BasicTypeInfo.DOUBLE_TYPE_INFO;
			case STRING:
				return BasicTypeInfo.STRING_TYPE_INFO;
			case BINARY:
				return PrimitiveArrayTypeInfo.BYTE_PRIMITIVE_ARRAY_TYPE_INFO;
			case ARRAY:
				return new GenericTypeInfo(List.class);
			case MAP:
				return new GenericTypeInfo(Map.class);
			case STRUCT:
				return new GenericTypeInfo(List.class);
			default:
				throw new IllegalArgumentException("Unknown data type \""+fieldSchema.getType()+"\" encountered.");
		}
	}
 
开发者ID:axbaretto,项目名称:flink,代码行数:32,代码来源:HCatInputFormatBase.java


示例17: testGenericRow

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Test(expected = TableException.class)
public void testGenericRow() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());

	// use null value the enforce GenericType
	DataSet<Row> dataSet = env.fromElements(Row.of(1, 2L, "Hello", null));
	assertTrue(dataSet.getType() instanceof GenericTypeInfo);
	assertTrue(dataSet.getType().getTypeClass().equals(Row.class));

	// Must fail. Cannot import DataSet<Row> with GenericTypeInfo.
	tableEnv.fromDataSet(dataSet);
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:TableEnvironmentITCase.java


示例18: testGenericRowWithAlias

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
@Test(expected = TableException.class)
public void testGenericRowWithAlias() throws Exception {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	BatchTableEnvironment tableEnv = TableEnvironment.getTableEnvironment(env, config());

	// use null value the enforce GenericType
	DataSet<Row> dataSet = env.fromElements(Row.of((Integer) null));
	assertTrue(dataSet.getType() instanceof GenericTypeInfo);
	assertTrue(dataSet.getType().getTypeClass().equals(Row.class));

	// Must fail. Cannot import DataSet<Row> with GenericTypeInfo.
	tableEnv.fromDataSet(dataSet, "nullField");
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:14,代码来源:TableEnvironmentITCase.java


示例19: main

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {

		// BasicConfigurator.configure(new ConsoleAppender(new
		// PatternLayout()));

		ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();

		OSMPBFWayInputFormat iformat = new OSMPBFWayInputFormat();

		iformat.setFilePath("C:/projets/OSMImport/france-latest.osm.pbf");

		// iformat.setFilePath("C:/projets/OSMImport/rhone-alpes-latest.osm.pbf");

		FileInputSplit[] s = iformat.createInputSplits(4);

		DataSource<WayEntity> r = env.createInput(iformat, new GenericTypeInfo<WayEntity>(WayEntity.class));
		r.flatMap(new FlatMapFunction<WayEntity, Tuple2<Long, String>>() {
			@Override
			public void flatMap(WayEntity value, Collector<Tuple2<Long, String>> out)
					throws Exception {
				if (value.fields != null) {
					if (value.fields.containsKey("type")) {
						out.collect(new Tuple2<>(value.id, (String) value.fields.get("type")));
					}
				}
			}
		}).writeAsCsv("test.csv");

		env.execute();

	}
 
开发者ID:frett27,项目名称:osm-flink-tools,代码行数:32,代码来源:TestPBFWayInputStream.java


示例20: main

import org.apache.flink.api.java.typeutils.GenericTypeInfo; //导入依赖的package包/类
public static void main(String[] argv) throws Exception {

		// BasicConfigurator.configure(new ConsoleAppender(new
		// PatternLayout()));

		ExecutionEnvironment env = ExecutionEnvironment.createLocalEnvironment();

		OSMPBFRelationInputFormat iformat = new OSMPBFRelationInputFormat();

		//iformat.setFilePath("C:/projets/OSMImport/france-latest.osm.pbf");

		iformat.setFilePath("C:/projets/OSMImport/rhone-alpes-latest.osm.pbf");

		FileInputSplit[] s = iformat.createInputSplits(4);

		DataSource<Relation> r = env.createInput(iformat, new GenericTypeInfo<Relation>(Relation.class));
		r.flatMap(new FlatMapFunction<Relation, Tuple2<Long, String>>() {
			@Override
			public void flatMap(Relation value, Collector<Tuple2<Long, String>> out)
					throws Exception {
				if (value.fields != null) {
					if (value.fields.containsKey("type")) {
						out.collect(new Tuple2<>(value.id, (String) value.fields.get("type")));
					}
				}
			}
		}).writeAsCsv("test.csv");

		env.execute();

	}
 
开发者ID:frett27,项目名称:osm-flink-tools,代码行数:32,代码来源:TestPBFRelationInputStream.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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