Skip to content

feat: add MODE aggregate function (#2482) - #2519

Open
Abhirup0 wants to merge 2 commits into
AlaSQL:developfrom
Abhirup0:feat/add-mode-aggregate-function
Open

feat: add MODE aggregate function (#2482)#2519
Abhirup0 wants to merge 2 commits into
AlaSQL:developfrom
Abhirup0:feat/add-mode-aggregate-function

Conversation

@Abhirup0

Copy link
Copy Markdown

Closes #2482

Summary

Adds the MODE() aggregate function to AlaSQL as requested in #2482.

Details

  • Implemented aggregate function alasql.aggr.MODE (and alias alasql.aggr.mode) in src/55functions.js.
  • Ignores NULL and undefined values during aggregation.
  • Accumulates frequency counts via Map.
  • Resolves ties by returning the smallest value (ANSI SQL semantics).
  • Added test suite test/test999_mode.js covering numbers, strings, tie-breaking, GROUP BY, and empty sets.

Comment thread test/test999_mode.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please rename file to test2482.js

Comment thread test/test999_mode.js Outdated
var alasql = require('..');
}

describe('Test MODE aggregate function', function () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add test cases that covers

  • All NULLs or undefined
  • Boolean values
  • Strict Equality / Mixed Types: Does MODE treat the number 1 and the string '1' as the same or different?
  • Negative Numbers and Floats

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.

Feature Request: Add MODE function

2 participants