Java Code Examples for org.apache.flink.api.common.typeinfo.BasicTypeInfo#getInfoFor()
The following examples show how to use
org.apache.flink.api.common.typeinfo.BasicTypeInfo#getInfoFor() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TupleTypeInfo.java From flink with Apache License 2.0 | 6 votes |
@PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { throw new IllegalArgumentException("Type at position " + i + " is not a basic type."); } infos[i] = info; } @SuppressWarnings("unchecked") TupleTypeInfo<X> tupleInfo = (TupleTypeInfo<X>) new TupleTypeInfo<Tuple>(infos); return tupleInfo; }
Example 2
Source File: TupleTypeInfo.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { throw new IllegalArgumentException("Type at position " + i + " is not a basic type."); } infos[i] = info; } @SuppressWarnings("unchecked") TupleTypeInfo<X> tupleInfo = (TupleTypeInfo<X>) new TupleTypeInfo<Tuple>(infos); return tupleInfo; }
Example 3
Source File: GenericDataSinkBaseTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDataSourceWithRuntimeContext() { try { TestRichOutputFormat out = new TestRichOutputFormat(); GenericDataSinkBase<String> sink = new GenericDataSinkBase<String>( out, new UnaryOperatorInformation<String, Nothing>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.getInfoFor(Nothing.class)), "test_sink"); sink.setInput(source); ExecutionConfig executionConfig = new ExecutionConfig(); final HashMap<String, Accumulator<?, ?>> accumulatorMap = new HashMap<String, Accumulator<?, ?>>(); final HashMap<String, Future<Path>> cpTasks = new HashMap<>(); final TaskInfo taskInfo = new TaskInfo("test_sink", 1, 0, 1, 0); executionConfig.disableObjectReuse(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), new RuntimeUDFContext( taskInfo, null, executionConfig, cpTasks, accumulatorMap, new UnregisteredMetricsGroup()), executionConfig); assertEquals(out.output, asList(TestIOData.RICH_NAMES)); executionConfig.enableObjectReuse(); out.clear(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), new RuntimeUDFContext( taskInfo, null, executionConfig, cpTasks, accumulatorMap, new UnregisteredMetricsGroup()), executionConfig); assertEquals(out.output, asList(TestIOData.RICH_NAMES)); } catch(Exception e){ e.printStackTrace(); fail(e.getMessage()); } }
Example 4
Source File: BasicTypeInfoTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicTypeInfoEquality() { for (Class<?> clazz: classes) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz); assertEquals(tpeInfo1, tpeInfo2); assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); } }
Example 5
Source File: GenericDataSinkBaseTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDataSourceWithRuntimeContext() { try { TestRichOutputFormat out = new TestRichOutputFormat(); GenericDataSinkBase<String> sink = new GenericDataSinkBase<String>( out, new UnaryOperatorInformation<String, Nothing>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.getInfoFor(Nothing.class)), "test_sink"); sink.setInput(source); ExecutionConfig executionConfig = new ExecutionConfig(); final HashMap<String, Accumulator<?, ?>> accumulatorMap = new HashMap<String, Accumulator<?, ?>>(); final HashMap<String, Future<Path>> cpTasks = new HashMap<>(); final TaskInfo taskInfo = new TaskInfo("test_sink", 1, 0, 1, 0); executionConfig.disableObjectReuse(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), new RuntimeUDFContext( taskInfo, null, executionConfig, cpTasks, accumulatorMap, new UnregisteredMetricsGroup()), executionConfig); assertEquals(out.output, asList(TestIOData.RICH_NAMES)); executionConfig.enableObjectReuse(); out.clear(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), new RuntimeUDFContext( taskInfo, null, executionConfig, cpTasks, accumulatorMap, new UnregisteredMetricsGroup()), executionConfig); assertEquals(out.output, asList(TestIOData.RICH_NAMES)); } catch(Exception e){ e.printStackTrace(); fail(e.getMessage()); } }
Example 6
Source File: GenericDataSinkBaseTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDataSourcePlain() { try { TestNonRichOutputFormat out = new TestNonRichOutputFormat(); GenericDataSinkBase<String> sink = new GenericDataSinkBase<String>( out, new UnaryOperatorInformation<String, Nothing>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.getInfoFor(Nothing.class)), "test_sink"); sink.setInput(source); ExecutionConfig executionConfig = new ExecutionConfig(); executionConfig.disableObjectReuse(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig); assertEquals(out.output, asList(TestIOData.NAMES)); executionConfig.enableObjectReuse(); out.clear(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig); assertEquals(out.output, asList(TestIOData.NAMES)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 7
Source File: FieldAccessor.java From flink with Apache License 2.0 | 5 votes |
public ArrayFieldAccessor(int pos, TypeInformation typeInfo) { if (pos < 0) { throw new CompositeType.InvalidFieldReferenceException("The " + ((Integer) pos).toString() + ". field selected on" + " an array, which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); this.pos = pos; this.fieldType = BasicTypeInfo.getInfoFor(typeInfo.getTypeClass().getComponentType()); }
Example 8
Source File: FieldAccessor.java From flink with Apache License 2.0 | 5 votes |
public ArrayFieldAccessor(int pos, TypeInformation typeInfo) { if (pos < 0) { throw new CompositeType.InvalidFieldReferenceException("The " + ((Integer) pos).toString() + ". field selected on" + " an array, which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); this.pos = pos; this.fieldType = BasicTypeInfo.getInfoFor(typeInfo.getTypeClass().getComponentType()); }
Example 9
Source File: BasicTypeInfoTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicTypeInfoInequality() { for (Class<?> clazz1: classes) { for (Class<?> clazz2: classes) { if (!clazz1.equals(clazz2)) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz1); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz2); assertNotEquals(tpeInfo1, tpeInfo2); } } } }
Example 10
Source File: BasicTypeInfoTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicTypeInfoEquality() { for (Class<?> clazz: classes) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz); assertEquals(tpeInfo1, tpeInfo2); assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); } }
Example 11
Source File: GenericDataSinkBaseTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testDataSourcePlain() { try { TestNonRichOutputFormat out = new TestNonRichOutputFormat(); GenericDataSinkBase<String> sink = new GenericDataSinkBase<String>( out, new UnaryOperatorInformation<String, Nothing>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.getInfoFor(Nothing.class)), "test_sink"); sink.setInput(source); ExecutionConfig executionConfig = new ExecutionConfig(); executionConfig.disableObjectReuse(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig); assertEquals(out.output, asList(TestIOData.NAMES)); executionConfig.enableObjectReuse(); out.clear(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig); assertEquals(out.output, asList(TestIOData.NAMES)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 12
Source File: TupleTypeInfo.java From flink with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicAndBasicValueTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { try { info = ValueTypeInfo.getValueTypeInfo((Class<Value>) type); if (!((ValueTypeInfo<?>) info).isBasicValueType()) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type."); } } catch (ClassCastException | InvalidTypesException e) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type.", e); } } infos[i] = info; } return (TupleTypeInfo<X>) new TupleTypeInfo<>(infos); }
Example 13
Source File: BasicTypeInfoTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testBasicTypeInfoInequality() { for (Class<?> clazz1: classes) { for (Class<?> clazz2: classes) { if (!clazz1.equals(clazz2)) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz1); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz2); assertNotEquals(tpeInfo1, tpeInfo2); } } } }
Example 14
Source File: FieldAccessor.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
public ArrayFieldAccessor(int pos, TypeInformation typeInfo) { if (pos < 0) { throw new CompositeType.InvalidFieldReferenceException("The " + ((Integer) pos).toString() + ". field selected on" + " an array, which is an invalid index."); } checkNotNull(typeInfo, "typeInfo must not be null."); this.pos = pos; this.fieldType = BasicTypeInfo.getInfoFor(typeInfo.getTypeClass().getComponentType()); }
Example 15
Source File: BasicTypeInfoTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testBasicTypeInfoInequality() { for (Class<?> clazz1: classes) { for (Class<?> clazz2: classes) { if (!clazz1.equals(clazz2)) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz1); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz2); assertNotEquals(tpeInfo1, tpeInfo2); } } } }
Example 16
Source File: BasicTypeInfoTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testBasicTypeInfoEquality() { for (Class<?> clazz: classes) { BasicTypeInfo<?> tpeInfo1 = BasicTypeInfo.getInfoFor(clazz); BasicTypeInfo<?> tpeInfo2 = BasicTypeInfo.getInfoFor(clazz); assertEquals(tpeInfo1, tpeInfo2); assertEquals(tpeInfo1.hashCode(), tpeInfo2.hashCode()); } }
Example 17
Source File: GenericDataSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testDataSourceWithRuntimeContext() { try { TestRichOutputFormat out = new TestRichOutputFormat(); GenericDataSinkBase<String> sink = new GenericDataSinkBase<String>( out, new UnaryOperatorInformation<String, Nothing>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.getInfoFor(Nothing.class)), "test_sink"); sink.setInput(source); ExecutionConfig executionConfig = new ExecutionConfig(); final HashMap<String, Accumulator<?, ?>> accumulatorMap = new HashMap<String, Accumulator<?, ?>>(); final HashMap<String, Future<Path>> cpTasks = new HashMap<>(); final TaskInfo taskInfo = new TaskInfo("test_sink", 1, 0, 1, 0); executionConfig.disableObjectReuse(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), new RuntimeUDFContext( taskInfo, null, executionConfig, cpTasks, accumulatorMap, new UnregisteredMetricsGroup()), executionConfig); assertEquals(out.output, asList(TestIOData.RICH_NAMES)); executionConfig.enableObjectReuse(); out.clear(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), new RuntimeUDFContext( taskInfo, null, executionConfig, cpTasks, accumulatorMap, new UnregisteredMetricsGroup()), executionConfig); assertEquals(out.output, asList(TestIOData.RICH_NAMES)); } catch(Exception e){ e.printStackTrace(); fail(e.getMessage()); } }
Example 18
Source File: GenericDataSinkBaseTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testDataSourcePlain() { try { TestNonRichOutputFormat out = new TestNonRichOutputFormat(); GenericDataSinkBase<String> sink = new GenericDataSinkBase<String>( out, new UnaryOperatorInformation<String, Nothing>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.getInfoFor(Nothing.class)), "test_sink"); sink.setInput(source); ExecutionConfig executionConfig = new ExecutionConfig(); executionConfig.disableObjectReuse(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig); assertEquals(out.output, asList(TestIOData.NAMES)); executionConfig.enableObjectReuse(); out.clear(); in.reset(); sink.executeOnCollections(asList(TestIOData.NAMES), null, executionConfig); assertEquals(out.output, asList(TestIOData.NAMES)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
Example 19
Source File: TupleTypeInfo.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @PublicEvolving public static <X extends Tuple> TupleTypeInfo<X> getBasicAndBasicValueTupleTypeInfo(Class<?>... basicTypes) { if (basicTypes == null || basicTypes.length == 0) { throw new IllegalArgumentException(); } TypeInformation<?>[] infos = new TypeInformation<?>[basicTypes.length]; for (int i = 0; i < infos.length; i++) { Class<?> type = basicTypes[i]; if (type == null) { throw new IllegalArgumentException("Type at position " + i + " is null."); } TypeInformation<?> info = BasicTypeInfo.getInfoFor(type); if (info == null) { try { info = ValueTypeInfo.getValueTypeInfo((Class<Value>) type); if (!((ValueTypeInfo<?>) info).isBasicValueType()) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type."); } } catch (ClassCastException | InvalidTypesException e) { throw new IllegalArgumentException("Type at position " + i + " is not a basic or value type.", e); } } infos[i] = info; } return (TupleTypeInfo<X>) new TupleTypeInfo<>(infos); }
Example 20
Source File: SimpleAVROSchema.java From jMetalSP with MIT License | 3 votes |
@Override public TypeInformation<T> getProducedType() { // return TypeExtractor.getForClass(avroType); return BasicTypeInfo.getInfoFor(avroType); }