flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fhueske <...@git.apache.org>
Subject [GitHub] flink pull request: [FLINK-1512] Add CsvReader for reading into PO...
Date Wed, 11 Mar 2015 11:57:49 GMT
Github user fhueske commented on a diff in the pull request:

    https://github.com/apache/flink/pull/426#discussion_r26205969
  
    --- Diff: flink-java/src/main/java/org/apache/flink/api/java/io/CsvInputFormat.java ---
    @@ -152,6 +177,38 @@ public void setFields(boolean[] sourceFieldMask, Class<?>[]
fieldTypes) {
     	public Class<?>[] getFieldTypes() {
     		return super.getGenericFieldTypes();
     	}
    +
    +	public void setFieldsMap(String[] fieldsMap) {
    +		Preconditions.checkNotNull(fieldsMap);
    +		Preconditions.checkState(typeInformation instanceof PojoTypeInfo);
    +
    +		PojoTypeInfo<OUT> pojoTypeInfo = (PojoTypeInfo<OUT>) typeInformation;
    +
    +		String[] fields = pojoTypeInfo.getFieldNames();
    +		Class<?>[] fieldTypes = getFieldTypes();
    +		this.fieldsMap = Arrays.copyOfRange(fieldsMap, 0, fieldsMap.length);
    +
    +		boolean[] includeMask = new boolean[fieldsMap.length];
    +		Class<?>[] newFieldTypes = new Class<?>[fieldsMap.length];
    +
    +		for (int i = 0; i < fieldsMap.length; i++) {
    +			if (fieldsMap[i] == null) {
    +				includeMask[i] = false;
    +				newFieldTypes[i] = null;
    +				continue;
    +			}
    +
    +			for (int j = 0; j < fields.length; j++) {
    +				if (fields[j].equals(fieldsMap[i])) {
    +					includeMask[i] = true;
    +					newFieldTypes[i] = fieldTypes[j];
    +					break;
    +				}
    +			}
    --- End diff --
    
    Can you throw an exception if the provided field name was not found in the POJO type information?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message