-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Add SORTBY array function #2245
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
Conversation
Introduces the `SORTBY` array function for dynamic in-cell sorting. This function allows sorting a given array based on the values in one or more corresponding arrays (sort keys). Each sort key can specify an ascending or descending order. It supports multi-key sorting and adheres to Excel's sorting rules for mixed data types: numbers precede strings, strings precede errors, and blanks come last. This provides powerful data manipulation capabilities directly within formulas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thanks for your PR. Implement in calc.go and calc_test.go instead of introduce separate source code files.
The SORTBY array function and its associated helper logic have been moved from `calcrange.go` to `calc.go`. This consolidates formula implementation into a single, primary file. This change simplifies the project structure by reducing the number of files. It also places the SORTBY logic alongside other core calculation functions, improving code organization.
|
@xuri updated 👍 |
xuri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your update, I've left some comments.
- Using existing `compareFormulaArg` function instead of introducing new `compareSortbyValues` function - Reduce `getSortbyArgs` function's cyclomatic complexity less than 16 - Add unit test cases to improve code coverage
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2245 +/- ##
========================================
Coverage 99.55% 99.55%
========================================
Files 32 32
Lines 25778 25884 +106
========================================
+ Hits 25663 25769 +106
Misses 60 60
Partials 55 55
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
xuri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. I've made some changes based on your branch, resolved code review issues.
PR Details
Introduces the
SORTBYarray function for dynamic in-cell sorting.Description
The
SORTBYfunction allows sorting a given array based on the values in one or more corresponding arrays (sort keys). Each sort key can specify an ascending or descending order.It supports multi-key sorting and adheres to Excel's sorting rules for mixed data types: numbers precede strings, strings precede errors, and blanks come last. This provides powerful data manipulation capabilities directly within formulas.
The
SORTBYfunction is in a new filecalcrange.go, my thinking there was to move the range calculations into this file, which will reduce the overall size of calc.go making it easier to work with.Related Issue
NA
Motivation and Context
The
SORTBYfunction is a modern Excel dynamic array function (introduced in Excel 365) that was missing from excelize's formula calculation engine. This function is essential for users who need to sort data dynamically within formulas without manually rearranging cells.Key benefits:
UNIQUE,XLOOKUP, andTRANSPOSEThis implementation was organized into a new
calcrange.gofile to avoid further bloating the already largecalc.gofile (19k+ lines), making it easier to maintain and setting a pattern for future array functions likeSORT,FILTER, andSEQUENCE.How Has This Been Tested
Test Coverage
TestCalcSORTBY: Comprehensive integration tests covering:TestCompareSortbyValues: Unit tests for comparison logic:TestSORTBYEdgeCases: Edge case validation:Test Environment
TestCalcCellValueand others)Validation Method
Tests use
TEXTJOINto flatten array results into comma-separated strings for easy assertion, following the pattern used by other array function tests in the codebase.Types of changes
Checklist