Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unifying Remove function with PA #2776

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ internal sealed class DefaultEnabledFeatures : IExternalEnabledFeatures

public bool IsEnhancedComponentFunctionPropertyEnabled => true;

public bool IsComponentFunctionPropertyDataflowEnabled => true;
public bool IsComponentFunctionPropertyDataflowEnabled => true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ private bool SetErrorForMismatchedColumnsCore(DType expectedType, DType actualTy
}

// Second, set column missing message if applicable
if (RequireAllParamColumns && !expectedType.AreFieldsOptional)
if ((RequireAllParamColumns || features.PowerFxV1CompatibilityRules) && !expectedType.AreFieldsOptional)
{
errors.EnsureError(
DocumentErrorSeverity.Severe,
Expand Down
11 changes: 9 additions & 2 deletions src/libraries/Microsoft.PowerFx.Core/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,10 @@ internal static class TexlStrings
public static StringGetter AboutClearCollect = (b) => StringResources.Get("AboutClearCollect", b);

public static StringGetter AboutRemove = (b) => StringResources.Get("AboutRemove", b);
public static StringGetter RemoveDataSourceArg = (b) => StringResources.Get("RemoveDataSourceArg", b);
public static StringGetter RemoveRecordsArg = (b) => StringResources.Get("RemoveRecordsArg", b);
public static StringGetter RemoveArg1 = (b) => StringResources.Get("RemoveArg1", b);
public static StringGetter RemoveArg2 = (b) => StringResources.Get("RemoveArg2", b);
public static StringGetter RemoveArg3 = (b) => StringResources.Get("RemoveArg3", b);
public static StringGetter RemoveAllArg2 = (b) => StringResources.Get("RemoveAllArg2", b);

public static StringGetter AboutDec2Hex = (b) => StringResources.Get("AboutDec2Hex", b);
public static StringGetter Dec2HexArg1 = (b) => StringResources.Get("Dec2HexArg1", b);
Expand Down Expand Up @@ -655,6 +657,7 @@ internal static class TexlStrings
public static ErrorResourceKey ErrBadType_ExpectedType_ProvidedType = new ErrorResourceKey("ErrBadType_ExpectedType_ProvidedType");
public static ErrorResourceKey ErrBadType_VoidExpression = new ErrorResourceKey("ErrBadType_VoidExpression");
public static ErrorResourceKey ErrBadSchema_ExpectedType = new ErrorResourceKey("ErrBadSchema_ExpectedType");
public static ErrorResourceKey ErrNeedTable_Arg = new ErrorResourceKey("ErrNeedTable_Arg");
public static ErrorResourceKey ErrInvalidArgs_Func = new ErrorResourceKey("ErrInvalidArgs_Func");
public static ErrorResourceKey ErrNeedTable_Func = new ErrorResourceKey("ErrNeedTable_Func");
public static ErrorResourceKey ErrNeedTableCol_Func = new ErrorResourceKey("ErrNeedTableCol_Func");
Expand Down Expand Up @@ -868,5 +871,9 @@ internal static class TexlStrings
public static ErrorResourceKey ErrJoinArgIsNotAsNode = new ErrorResourceKey("ErrJoinArgIsNotAsNode");
public static ErrorResourceKey ErrJoinAtLeastOneRigthRecordField = new ErrorResourceKey("ErrJoinAtLeastOneRigthRecordField");
public static ErrorResourceKey ErrJoinDottedNameleft = new ErrorResourceKey("ErrJoinDottedNameleft");

public static ErrorResourceKey ErrCollectionDoesNotAcceptThisType = new ErrorResourceKey("ErrCollectionDoesNotAcceptThisType");
public static ErrorResourceKey ErrNeedAll = new ErrorResourceKey("ErrNeedAll");
public static ErrorResourceKey ErrNeedCollection_Func = new ErrorResourceKey("ErrNeedCollection_Func");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public sealed class Features
/// </summary>
internal bool IsUserDefinedTypesEnabled { get; init; } = false;

/// <summary>
/// Enables RemoveAll delegation.
/// </summary>
internal bool IsRemoveAllDelegationEnabled { get; init; }

internal static readonly Features None = new Features();

/// <summary>
Expand Down Expand Up @@ -124,6 +129,7 @@ internal Features(Features other)
AsTypeLegacyCheck = other.AsTypeLegacyCheck;
JsonFunctionAcceptsLazyTypes = other.JsonFunctionAcceptsLazyTypes;
IsLookUpReductionDelegationEnabled = other.IsLookUpReductionDelegationEnabled;
IsRemoveAllDelegationEnabled = other.IsRemoveAllDelegationEnabled;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public override DValue<RecordValue> Last(bool mutationCopy = false)
public override async Task<DValue<BooleanValue>> RemoveAsync(IEnumerable<FormulaValue> recordsToRemove, bool all, CancellationToken cancellationToken)
{
var ret = false;
var deleteList = new List<T>();
var markedToDeletionIndexes = new HashSet<int>();
var errors = new List<ExpressionError>();

cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -194,21 +194,30 @@ public override async Task<DValue<BooleanValue>> RemoveAsync(IEnumerable<Formula
return await base.RemoveAsync(recordsToRemove, all, cancellationToken).ConfigureAwait(false);
}

var rowsArray = _enumerator.ToArray();

foreach (RecordValue recordToRemove in recordsToRemove)
{
var found = false;

foreach (T item in _enumerator)
for (int i = 0; i < rowsArray.Length; i++)
{
cancellationToken.ThrowIfCancellationRequested();

var item = rowsArray[i];
DValue<RecordValue> dRecord = Marshal(item);

if (await MatchesAsync(dRecord.Value, recordToRemove, cancellationToken).ConfigureAwait(false))
{
found = true;

deleteList.Add(item);
if (markedToDeletionIndexes.Contains(i))
{
continue;
}
else
{
found = true;
markedToDeletionIndexes.Add(i);
}

if (!all)
{
Expand All @@ -220,13 +229,13 @@ public override async Task<DValue<BooleanValue>> RemoveAsync(IEnumerable<Formula
if (!found)
{
// https://github.com/microsoft/Power-Fx/issues/2618
errors.Add(new ExpressionError() { Message = "The specified record was not found.", Kind = ErrorKind.NotFound });
errors.Add(new ExpressionError() { Kind = ErrorKind.NotFound });
}
}

foreach (var delete in deleteList)
foreach (var index in markedToDeletionIndexes)
{
_sourceList.Remove(delete);
_sourceList.Remove(rowsArray[index]);
ret = true;
}

Expand Down
Loading
Loading