/// <summary> /// Execute this field setter on the given <paramref name="row"/>, /// that is, perform the field value assignments. It is the caller's /// duty to <see cref="Row.Store">Store</see> these changes. /// <para/> /// The values of the given <paramref name="row"/> are not available /// in the evaluation environment unless this row has been passed /// to <see cref="DefineFields(IRowValues, string)"/> before. /// </summary> /// <param name="row">The row on which to operate</param> /// <param name="env">The environment to use (optional, defaults /// to the FieldSetter's internal environment that you can /// manipulate with the various Define methods</param> public void Execute(IRowValues row, IEvaluationEnvironment env = null) { Assert.ArgumentNotNull(row, nameof(row)); Array.Clear(_values, 0, _values.Length); int count = _assignments.Length; for (int i = 0; i < count; i++) { var evaluator = _assignments[i].Evaluator; _values[i] = evaluator.Evaluate(env ?? _environment, _stack); } for (int i = 0; i < count; i++) { string fieldName = _assignments[i].FieldName; int fieldIndex = _findFieldCache.GetFieldIndex(row, fieldName); object value = _values[i]; row[fieldIndex] = value ?? DBNull.Value; } }
/// <summary> /// Define all the values of the given <paramref name="row"/> /// using the given <paramref name="qualifier"/> in the environment /// where the expression will be evaluated. /// </summary> /// <returns>This instance (for convenience).</returns> public ImplicitValue DefineFields([NotNull] IRowValues row, [CanBeNull] string qualifier = null) { var namedValues = (INamedValues)row; return(DefineFields(namedValues, qualifier)); }
private void ProcessFields(IRowValues row, Func <object, object, object> combine) { Assert.ArgumentNotNull(row, nameof(row)); Assert.ArgumentNotNull(combine, nameof(combine)); var fields = row.Fields; int fieldCount = fields.Count; for (int i = 0; i < fieldCount; i++) { Field field = fields[i]; if (string.IsNullOrEmpty(field.Name)) { continue; } object value = row[i]; if (value == DBNull.Value) { value = null; } object commonValue = GetValue(field.Name); _commonValues[field.Name] = combine(value, commonValue); } }
private void Add(IRowValues row) { if (FeatureCount == 0) { ProcessFields(row, CopyValue); } else { ProcessFields(row, CombineValues); } FeatureCount += 1; }
public int GetFieldIndex(IRowValues row, string fieldName) { if (row == null) { return(-1); } if (string.IsNullOrEmpty(fieldName)) { return(-1); } if (row is RowBufferValues rowBuffer) { return(GetFieldIndex(rowBuffer.Row, fieldName)); } if (row is Utils.RowValues realRow) { return(GetFieldIndex(realRow.Row, fieldName)); } return(row.FindField(fieldName)); }
private static int GetFieldIndex(IRowValues row, string fieldName) { // Here we *may* want to cache field index (measure) return(row.FindField(fieldName)); }
public CommonValues([NotNull] IRowValues row) : this() { Assert.ArgumentNotNull(nameof(row)); Add(row); }