org.apache.flink.api.java.typeutils.PojoField Java Examples
The following examples show how to use
org.apache.flink.api.java.typeutils.PojoField.
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: AbstractDynamicParallelSource.java From alibaba-flink-connectors with Apache License 2.0 | 6 votes |
@Override public void initializeState(FunctionInitializationContext context) throws Exception { LOG.info("initializeState"); ParameterizedType p = (ParameterizedType) this.getClass().getGenericSuperclass(); TypeInformation type0 = TypeExtractor.createTypeInfo(InputSplit.class); TypeInformation type1 = TypeExtractor.createTypeInfo(p.getActualTypeArguments()[1]); // TypeInformation<Tuple2<InputSplit, CURSOR>> stateTypeInfo = new TupleTypeInfo<>(type0, type1); List<PojoField> pojoFields = new ArrayList<>(); pojoFields.add(new PojoField(InnerProgress.class.getField("inputSplit"), type0)); pojoFields.add(new PojoField(InnerProgress.class.getField("cursor"), type1)); TypeInformation<InnerProgress> stateTypeInfo = new PojoTypeInfo<>(InnerProgress.class, pojoFields); // ListStateDescriptor<Tuple2<InputSplit, CURSOR>> descriptor = new ListStateDescriptor<>(SOURCE_STATE_NAME, stateTypeInfo); ListStateDescriptor<InnerProgress<CURSOR>> descriptor = new ListStateDescriptor(SOURCE_STATE_NAME, stateTypeInfo); unionInitialProgress = context.getOperatorStateStore().getUnionListState(descriptor); LOG.info("Restoring state: {}", unionInitialProgress); allSplitsInCP = new ArrayList<>(); if (context.isRestored()) { recoryFromState = true; for (InnerProgress progress: unionInitialProgress.get()){ allSplitsInCP.add(new InnerProgress(progress.inputSplit, progress.cursor)); } } }
Example #2
Source File: DataFormatConverters.java From flink with Apache License 2.0 | 5 votes |
public PojoConverter(PojoTypeInfo<T> t, DataType[] fieldTypes) { super(fieldTypes); this.fields = new PojoField[t.getArity()]; for (int i = 0; i < t.getArity(); i++) { fields[i] = t.getPojoFieldAt(i); fields[i].getField().setAccessible(true); } this.t = t; }
Example #3
Source File: MinWithRetractAggFunction.java From flink with Apache License 2.0 | 5 votes |
@Override public TypeInformation<MinWithRetractAccumulator<T>> getAccumulatorType() { PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MinWithRetractAccumulator.class); List<PojoField> pojoFields = new ArrayList<>(); for (int i = 0; i < pojoType.getTotalFields(); i++) { PojoField field = pojoType.getPojoFieldAt(i); if (field.getField().getName().equals("min")) { pojoFields.add(new PojoField(field.getField(), getValueTypeInfo())); } else { pojoFields.add(field); } } //noinspection unchecked return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields); }
Example #4
Source File: MaxWithRetractAggFunction.java From flink with Apache License 2.0 | 5 votes |
@Override public TypeInformation<MaxWithRetractAccumulator<T>> getAccumulatorType() { PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MaxWithRetractAccumulator.class); List<PojoField> pojoFields = new ArrayList<>(); for (int i = 0; i < pojoType.getTotalFields(); i++) { PojoField field = pojoType.getPojoFieldAt(i); if (field.getField().getName().equals("max")) { pojoFields.add(new PojoField(field.getField(), getValueTypeInfo())); } else { pojoFields.add(field); } } //noinspection unchecked return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields); }
Example #5
Source File: DataFormatConverters.java From flink with Apache License 2.0 | 5 votes |
public PojoConverter(PojoTypeInfo<T> t, DataType[] fieldTypes) { super(fieldTypes); this.fields = new PojoField[t.getArity()]; for (int i = 0; i < t.getArity(); i++) { fields[i] = t.getPojoFieldAt(i); fields[i].getField().setAccessible(true); } this.t = t; }
Example #6
Source File: FieldInfoUtilsTest.java From flink with Apache License 2.0 | 5 votes |
@Parameterized.Parameters(name = "{0}") public static Collection<TypeInformation> parameters() throws Exception { return Arrays.asList( new RowTypeInfo( new TypeInformation[]{Types.INT, Types.LONG, Types.SQL_TIMESTAMP}, new String[]{"f0", "f1", "f2"}), new PojoTypeInfo(MyPojo.class, Arrays.asList( new PojoField(MyPojo.class.getDeclaredField("f0"), Types.INT), new PojoField(MyPojo.class.getDeclaredField("f1"), Types.LONG), new PojoField(MyPojo.class.getDeclaredField("f2"), Types.SQL_TIMESTAMP)))); }
Example #7
Source File: MinWithRetractAggFunction.java From flink with Apache License 2.0 | 5 votes |
@Override public TypeInformation<MinWithRetractAccumulator<T>> getAccumulatorType() { PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MinWithRetractAccumulator.class); List<PojoField> pojoFields = new ArrayList<>(); for (int i = 0; i < pojoType.getTotalFields(); i++) { PojoField field = pojoType.getPojoFieldAt(i); if (field.getField().getName().equals("min")) { pojoFields.add(new PojoField(field.getField(), getValueTypeInfo())); } else { pojoFields.add(field); } } //noinspection unchecked return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields); }
Example #8
Source File: MaxWithRetractAggFunction.java From flink with Apache License 2.0 | 5 votes |
@Override public TypeInformation<MaxWithRetractAccumulator<T>> getAccumulatorType() { PojoTypeInfo pojoType = (PojoTypeInfo) TypeExtractor.createTypeInfo(MaxWithRetractAccumulator.class); List<PojoField> pojoFields = new ArrayList<>(); for (int i = 0; i < pojoType.getTotalFields(); i++) { PojoField field = pojoType.getPojoFieldAt(i); if (field.getField().getName().equals("max")) { pojoFields.add(new PojoField(field.getField(), getValueTypeInfo())); } else { pojoFields.add(field); } } //noinspection unchecked return new PojoTypeInfo(pojoType.getTypeClass(), pojoFields); }
Example #9
Source File: CollectAggFunction.java From flink with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public TypeInformation<CollectAccumulator<T>> getAccumulatorType() { try { Class<CollectAccumulator<T>> clazz = (Class<CollectAccumulator<T>>) (Class) CollectAccumulator.class; List<PojoField> pojoFields = new ArrayList<>(); pojoFields.add(new PojoField( clazz.getDeclaredField("map"), new MapViewTypeInfo<>(elementType, BasicTypeInfo.INT_TYPE_INFO))); return new PojoTypeInfo<>(clazz, pojoFields); } catch (NoSuchFieldException e) { throw new WrappingRuntimeException(e); } }
Example #10
Source File: Types.java From Flink-CEPplus with Apache License 2.0 | 3 votes |
/** * Returns type information for a POJO (Plain Old Java Object) and allows to specify all fields manually. * * <p>A POJO class is public and standalone (no non-static inner class). It has a public no-argument * constructor. All non-static, non-transient fields in the class (and all superclasses) are either public * (and non-final) or have a public getter and a setter method that follows the Java beans naming * conventions for getters and setters. * * <p>A POJO is a fixed-length, null-aware composite type with non-deterministic field order. Every field * can be null independent of the field's type. * * <p>The generic types for all fields of the POJO can be defined in a hierarchy of subclasses. * * <p>If Flink's type analyzer is unable to extract a POJO field, an * {@link org.apache.flink.api.common.functions.InvalidTypesException} is thrown. * * <p><strong>Note:</strong> In most cases the type information of fields can be determined automatically, * we recommend to use {@link Types#POJO(Class)}. * * @param pojoClass POJO class * @param fields map of fields that map a name to type information. The map key is the name of * the field and the value is its type. */ public static <T> TypeInformation<T> POJO(Class<T> pojoClass, Map<String, TypeInformation<?>> fields) { final List<PojoField> pojoFields = new ArrayList<>(fields.size()); for (Map.Entry<String, TypeInformation<?>> field : fields.entrySet()) { final Field f = TypeExtractor.getDeclaredField(pojoClass, field.getKey()); if (f == null) { throw new InvalidTypesException("Field '" + field.getKey() + "'could not be accessed."); } pojoFields.add(new PojoField(f, field.getValue())); } return new PojoTypeInfo<>(pojoClass, pojoFields); }
Example #11
Source File: Types.java From flink with Apache License 2.0 | 3 votes |
/** * Returns type information for a POJO (Plain Old Java Object) and allows to specify all fields manually. * * <p>A POJO class is public and standalone (no non-static inner class). It has a public no-argument * constructor. All non-static, non-transient fields in the class (and all superclasses) are either public * (and non-final) or have a public getter and a setter method that follows the Java beans naming * conventions for getters and setters. * * <p>A POJO is a fixed-length, null-aware composite type with non-deterministic field order. Every field * can be null independent of the field's type. * * <p>The generic types for all fields of the POJO can be defined in a hierarchy of subclasses. * * <p>If Flink's type analyzer is unable to extract a POJO field, an * {@link org.apache.flink.api.common.functions.InvalidTypesException} is thrown. * * <p><strong>Note:</strong> In most cases the type information of fields can be determined automatically, * we recommend to use {@link Types#POJO(Class)}. * * @param pojoClass POJO class * @param fields map of fields that map a name to type information. The map key is the name of * the field and the value is its type. */ public static <T> TypeInformation<T> POJO(Class<T> pojoClass, Map<String, TypeInformation<?>> fields) { final List<PojoField> pojoFields = new ArrayList<>(fields.size()); for (Map.Entry<String, TypeInformation<?>> field : fields.entrySet()) { final Field f = TypeExtractor.getDeclaredField(pojoClass, field.getKey()); if (f == null) { throw new InvalidTypesException("Field '" + field.getKey() + "'could not be accessed."); } pojoFields.add(new PojoField(f, field.getValue())); } return new PojoTypeInfo<>(pojoClass, pojoFields); }
Example #12
Source File: Types.java From flink with Apache License 2.0 | 3 votes |
/** * Returns type information for a POJO (Plain Old Java Object) and allows to specify all fields manually. * * <p>A POJO class is public and standalone (no non-static inner class). It has a public no-argument * constructor. All non-static, non-transient fields in the class (and all superclasses) are either public * (and non-final) or have a public getter and a setter method that follows the Java beans naming * conventions for getters and setters. * * <p>A POJO is a fixed-length, null-aware composite type with non-deterministic field order. Every field * can be null independent of the field's type. * * <p>The generic types for all fields of the POJO can be defined in a hierarchy of subclasses. * * <p>If Flink's type analyzer is unable to extract a POJO field, an * {@link org.apache.flink.api.common.functions.InvalidTypesException} is thrown. * * <p><strong>Note:</strong> In most cases the type information of fields can be determined automatically, * we recommend to use {@link Types#POJO(Class)}. * * @param pojoClass POJO class * @param fields map of fields that map a name to type information. The map key is the name of * the field and the value is its type. */ public static <T> TypeInformation<T> POJO(Class<T> pojoClass, Map<String, TypeInformation<?>> fields) { final List<PojoField> pojoFields = new ArrayList<>(fields.size()); for (Map.Entry<String, TypeInformation<?>> field : fields.entrySet()) { final Field f = TypeExtractor.getDeclaredField(pojoClass, field.getKey()); if (f == null) { throw new InvalidTypesException("Field '" + field.getKey() + "'could not be accessed."); } pojoFields.add(new PojoField(f, field.getValue())); } return new PojoTypeInfo<>(pojoClass, pojoFields); }