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

Remove function #2634

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Remove function #2634

wants to merge 7 commits into from

Conversation

anderson-joyle
Copy link
Contributor

@anderson-joyle anderson-joyle commented Sep 10, 2024

Unifying Remove function between PFx/PA.
Issue #2623.

@anderson-joyle anderson-joyle force-pushed the andersonf/2623-remove-function branch from bf65e7d to 5979601 Compare September 10, 2024 23:17
@LucGenetier
Copy link
Contributor

LucGenetier commented Sep 10, 2024

Public API changes:
❌CP0002 M:Microsoft.PowerFx.Types.CollectionTableValue`1.FindAsync(Microsoft.PowerFx.Types.RecordValue,System.Threading.CancellationToken,System.Boolean) #Resolved

@anderson-joyle anderson-joyle marked this pull request as ready for review September 11, 2024 18:28
@anderson-joyle anderson-joyle requested a review from a team as a code owner September 11, 2024 18:28
@LucGenetier
Copy link
Contributor

LucGenetier commented Sep 11, 2024

✅ No public API change. #Resolved

@anderson-joyle anderson-joyle changed the title WIP Remove function Remove function Sep 11, 2024
@anderson-joyle anderson-joyle force-pushed the andersonf/2623-remove-function branch from f9bfa73 to 7b3d469 Compare September 13, 2024 13:58
@LucGenetier
Copy link
Contributor

LucGenetier commented Sep 13, 2024

✅ No public API change. #Resolved

@LucGenetier
Copy link
Contributor

LucGenetier commented Sep 17, 2024

✅ No public API change. #Resolved

}
}

if (context.AnalysisMode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnalysisMode

This definitely should not be context.AnalysisMode, but !context.Features.PowerFxV1CompatibilityRules instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original code wasn't checking if context.Features.PowerFxV1CompatibilityRules was active or not. The idea here is, whatever PA was returning, keep returning it. Since PFxV1 in Core is active, return Void.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Power Apps moves to PFxV1, it should have the same behavior as the C# interpreter. Remove is one of the functions that we will update the return type on V1 to be Void.

errors.EnsureError(DocumentErrorSeverity.Severe, args[i], TexlStrings.ErrTableDoesNotAcceptThisType);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check wasn't in the original Remove implementation; what is the scenario that it is covering? In the existing implementation, there is already a check for the types of the arguments compared to the data source / collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the returning types are different between PA/PFx.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this is not about the return type of the function, but for input validation. And as I mentioned in another comment, whenever we expose Power Fx V1 compatibility in Power Apps, it should have the same behavior as the C# interpreter.

}

// Remove(collection:*[], source:*[], ["All"])
internal class RemoveAllFunction : BuiltinFunction
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveAllFunction

This function looks very similar to the previous one; can we have a single one?

Copy link
Contributor

@CarlosFigueiraMSFT CarlosFigueiraMSFT Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I noticed the difference (record arguments vs. table arguments). It can probably be refactored, though, to a common base type, so that most shared code can be written once.

{ "First", "first" },
{ "All", "all" },
},
canCoerceFromBackingKind: true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

canCoerceFromBackingKind: true

This should not be coercible - if we use strongly-typed built-in enums, we want makers to write Remove.All, and not "all" .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other enums that are also coercible (DateTimeFormatEnum)? I unmderstand we want to force makers to to write Remove.All but shouldn't we also take in consideration that this is still supported in PA?

Copy link
Contributor

@CarlosFigueiraMSFT CarlosFigueiraMSFT Sep 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DateTimeFormat is an enum that is passed to the Text function - and it can also take a string value. This is more similar to something like SortOrder - there is only one possible value that can be used

recordsToRemove = args
.Skip(1)
.Where(arg => arg is RecordValue)
.Select(row => (RecordValue)row)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.OfType<RecordValue>()

@CarlosFigueiraMSFT
Copy link
Contributor

#SETUP: PowerFxV1CompatibilityRules

Not related to your changes, but can you change the file name from Remove_V1Compact.txt to Remove_V1Compat.txt?


Refers to: src/tests/Microsoft.PowerFx.Core.Tests.Shared/ExpressionTestCases/Remove_V1Compact.txt:1 in f4ede39. [](commit_id = f4ede39, deletion_comment = False)

@CarlosFigueiraMSFT
Copy link
Contributor

#SETUP: PowerFxV1CompatibilityRules

The "base" remove test (Remove.txt) already uses the PowerFxV1CompatibilityRules setup; do we need this file, or can we merge it into the base one?


Refers to: src/tests/Microsoft.PowerFx.Core.Tests.Shared/ExpressionTestCases/Remove_V1Compact.txt:1 in f4ede39. [](commit_id = f4ede39, deletion_comment = False)

@@ -164,7 +164,7 @@ public void DataTableEvalTest2()
var result7 = engine.Eval("Patch(robintable, First(robintable),{Names:\"new-name\"});robintable", options: opt);
Assert.Equal("Table({Names:\"new-name\",Scores:10},{Names:\"name3\",Scores:30},{Names:\"name100\",Scores:10})", ((DataTableValue)result7).Dump());

var result8 = engine.Eval("Remove(robintable, {Scores:10}, \"All\");robintable", options: opt);
var result8 = engine.Eval("Remove(robintable, {Scores:10}, RemoveFlags.All);robintable", options: opt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RemoveFlags.All

Will this be considered a breaking change for PAD?

@LucGenetier
Copy link
Contributor

✅ No public API change.

@LucGenetier
Copy link
Contributor

✅ No public API change.

@LucGenetier
Copy link
Contributor

✅ No public API change.

@LucGenetier
Copy link
Contributor

✅ No public API change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants