@Override public void addForwardedField1(int sourceField, int destinationField) { if (this.nonForwardedFields1 == null) { super.addForwardedField1(sourceField, destinationField); } else { throw new UnsupportedOperationException("When defining fields as implicitly constant for an input" + "(such as through the ConstantFieldsFirstExcept annotation), you cannot manually add forwarded fields."); } }
@Override public void addForwardedField2(int sourceField, int destinationField) { if (this.nonForwardedFields2 == null) { super.addForwardedField2(sourceField, destinationField); } else { throw new UnsupportedOperationException("When defining fields as implicitly constant for an input" + "(such as through the ConstantFieldsSecondExcept annotation), you cannot manually add forwarded fields."); } }
private static void parseReadFieldsFirst(String[] rf, DualInputSemanticProperties dm, TypeInformation<?> inType, TypeInformation<?> outType) { if (rf == null) { return; } for (String str : rf) { if (str != null) { FieldSet fs = readFieldSetFromString(str, inType, outType); dm.addReadFields1(fs); } } }
@Override public boolean isFieldConstant(int input, int fieldNumber) { DualInputOperator<?, ?, ?, ?> c = getPactContract(); DualInputSemanticProperties semanticProperties = c.getSemanticProperties(); switch(input) { case 0: if (semanticProperties != null) { FieldSet fs; if ((fs = semanticProperties.getForwardedField1(fieldNumber)) != null) { return fs.contains(fieldNumber); } } break; case 1: if(semanticProperties != null) { FieldSet fs; if ((fs = semanticProperties.getForwardedField2(fieldNumber)) != null) { return fs.contains(fieldNumber); } } break; default: throw new IndexOutOfBoundsException(); } return false; }
@Override public FieldSet getForwardedField1(int sourceField) { if (this.nonForwardedFields1 == null) { return super.getForwardedField1(sourceField); } else { if (this.nonForwardedFields1.contains(sourceField)) { return null; } else { return new FieldSet(sourceField); } } }
@Override public FieldSet getForwardedField2(int sourceField) { if (this.nonForwardedFields2 == null) { return super.getForwardedField2(sourceField); } else { if (this.nonForwardedFields2.contains(sourceField)) { return null; } else { return new FieldSet(sourceField); } } }
for (int i = 0; i < inType.getArity() && i < outType.getArity(); i++) { if (input == 0) { ((DualInputSemanticProperties) sp).addForwardedField1(i, i); } else if (input == 1) { ((DualInputSemanticProperties) sp).addForwardedField2(i, i); for (int i = 0; i < outType.getArity(); i++) { if (input == 0) { ((DualInputSemanticProperties) sp).addForwardedField1(sourceField, i); } else if (input == 1) { ((DualInputSemanticProperties) sp).addForwardedField2(sourceField, i); } else if (sp instanceof DualInputSemanticProperties) { if (input == 0) { ((DualInputSemanticProperties) sp).addForwardedField1(sourceField, fs); } else if (input == 1) { ((DualInputSemanticProperties) sp).addForwardedField2(sourceField, fs); } else if (sp instanceof DualInputSemanticProperties) { if (input == 0) { ((DualInputSemanticProperties) sp).addForwardedField1(i, i); } else if (input == 1) { ((DualInputSemanticProperties) sp).addForwardedField2(i, i);
public DualInputSemanticProperties() { super(); this.init(); }
/** * Adds a constant-set annotation for the first input of the UDF. * * <p> * Constant set annotations are used by the optimizer to infer the existence of data properties (sorted, partitioned, grouped). * In certain cases, these annotations allow the optimizer to generate a more efficient execution plan which can lead to improved performance. * Constant set annotations can only be specified if the first input and the output type of the UDF are of {@link Tuple} data types. * * <p> * A constant-set annotation is a set of constant field specifications. The constant field specification String "4->3" specifies, that this UDF copies the fourth field of * an input tuple to the third field of the output tuple. Field references are zero-indexed. * * <p> * <b>NOTICE: Constant set annotations are optional, but if given need to be correct. Otherwise, the program might produce wrong results!</b> * * @param constantSetFirst A list of constant field specification Strings for the first input. * @return This operator with an annotated constant field set for the first input. */ @SuppressWarnings("unchecked") public O withConstantSetFirst(String... constantSetFirst) { if (this.udfSemantics == null) { this.udfSemantics = new DualInputSemanticProperties(); } SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, constantSetFirst, null, null, null, null, null, this.getInput1Type(), this.getInput2Type(), this.getResultType()); O returnType = (O) this; return returnType; }
private static void parseReadFieldsSecond(String[] rf, DualInputSemanticProperties dm, TypeInformation<?> inType, TypeInformation<?> outType) { if (rf == null) { return; } for (String str : rf) { if (str != null) { FieldSet fs = readFieldSetFromString(str, inType, outType); dm.addReadFields2(fs); } } }
@Override public boolean isFieldConstant(int input, int fieldNumber) { DualInputOperator<?, ?, ?, ?> c = getPactContract(); DualInputSemanticProperties semanticProperties = c.getSemanticProperties(); switch(input) { case 0: if (semanticProperties != null) { FieldSet fs; if ((fs = semanticProperties.getForwardedField1(fieldNumber)) != null) { return fs.contains(fieldNumber); } } break; case 1: if(semanticProperties != null) { FieldSet fs; if ((fs = semanticProperties.getForwardedField2(fieldNumber)) != null) { return fs.contains(fieldNumber); } } break; default: throw new IndexOutOfBoundsException(); } return false; }
public DualInputSemanticProperties() { super(); this.init(); }
/** * Adds a constant-set annotation for the second input of the UDF. * * <p> * Constant set annotations are used by the optimizer to infer the existence of data properties (sorted, partitioned, grouped). * In certain cases, these annotations allow the optimizer to generate a more efficient execution plan which can lead to improved performance. * Constant set annotations can only be specified if the second input and the output type of the UDF are of {@link Tuple} data types. * * <p> * A constant-set annotation is a set of constant field specifications. The constant field specification String "4->3" specifies, that this UDF copies the fourth field of * an input tuple to the third field of the output tuple. Field references are zero-indexed. * * <p> * <b>NOTICE: Constant set annotations are optional, but if given need to be correct. Otherwise, the program might produce wrong results!</b> * * @param constantSetSecond A list of constant field specification Strings for the second input. * @return This operator with an annotated constant field set for the second input. */ @SuppressWarnings("unchecked") public O withConstantSetSecond(String... constantSetSecond) { if (this.udfSemantics == null) { this.udfSemantics = new DualInputSemanticProperties(); } SemanticPropUtil.getSemanticPropsDualFromString(this.udfSemantics, null, constantSetSecond, null, null, null, null, this.getInput1Type(), this.getInput2Type(), this.getResultType()); O returnType = (O) this; return returnType; }
/** * Clears the object. */ @Override public void clearProperties() { this.init(); super.clearProperties(); }
@Override public void addForwardedField1(int sourceField, FieldSet destinationFields) { if (this.nonForwardedFields1 == null) { super.addForwardedField1(sourceField, destinationFields); } else { throw new UnsupportedOperationException("When defining fields as implicitly constant for an input" + "(such as through the ConstantFieldsFirstExcept annotation), you cannot manually add forwarded fields."); } }
@Override public void addForwardedField2(int sourceField, FieldSet destinationFields) { if (this.nonForwardedFields2 == null) { super.addForwardedField2(sourceField, destinationFields); } else { throw new UnsupportedOperationException("When defining fields as implicitly constant for an input" + "(such as through the ConstantFieldsSecondExcept annotation), you cannot manually add forwarded fields."); } }
result = new DualInputSemanticProperties();
/** * Clears the object. */ @Override public void clearProperties() { this.init(); super.clearProperties(); }
@Override public void setForwardedField1(int sourceField, FieldSet destinationFields) { if (this.nonForwardedFields1 == null) { super.addForwardedField1(sourceField, destinationFields); } else { throw new UnsupportedOperationException("When defining fields as implicitly constant for an input" + "(such as through the ConstantFieldsFirstExcept annotation), you cannot manually add forwarded fields."); } }
@Override public void setForwardedField2(int sourceField, FieldSet destinationFields) { if (this.nonForwardedFields2 == null) { super.addForwardedField2(sourceField, destinationFields); } else { throw new UnsupportedOperationException("When defining fields as implicitly constant for an input" + "(such as through the ConstantFieldsSecondExcept annotation), you cannot manually add forwarded fields."); } } }