Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Description

DISTINCT operations failed when comparing object values, treating all objects as identical due to [object Object] string coercion. Additionally, SELECT COLUMN DISTINCT did not apply distinct filtering to extracted values.

var data = [{a:1}, {a:2}, {a:1}];

// Before: returned 1 item (incorrect)
alasql('SELECT DISTINCT _ FROM ?', [data]);
// After: returns 2 items (correct)

// Before: returned [{a:1}] (incorrect) 
alasql('SELECT COLUMN DISTINCT _ FROM ?', [{a:1}, {b:2}, {a:1}]);
// After: returns [{a:1}, {b:2}] (correct)

Changes

Core Fix (src/38query.js)

  • doDistinct: Use JSON.stringify() for object comparison instead of default string coercion

Modifier Enhancement (src/40select.js)

  • modify COLUMN case: Apply distinctArray when query has distinct flag

Test Coverage (test/test167B.js)

  • Added tests for object DISTINCT with same structure
  • Added tests for object DISTINCT with different structures
  • Added tests for primitive value DISTINCT
  • Verified consistency between SELECT DISTINCT *, SELECT COLUMN DISTINCT _, and SEARCH DISTINCT(/)
  • Converted tests to use arrow functions for synchronous test cases (removed unnecessary async callbacks)

Checklist

  • Tests added for new functionality
  • All tests pass
  • No security vulnerabilities introduced
  • Code formatting passes Prettier validation

[!WARNING]

Original prompt

This section details on the original issue you should resolve

<filter_complete></filter_complete>

<issue_title>Fix SEARCH DISTINCT function and SELECT DISTINCT functions</issue_title>
<issue_description>There are some problems with this operator to be fixed
</issue_description>

<agent_instructions>Please make a test file called test167B.js verifying if this issue is still a problem.

If it is a problem try to solve it.

If you need to update the grammar of alasql, then please do small precice changes to alasqlparser.jison and then run yarn jison && yarn test</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@mathiasrw Can you describe the problems a bit more? @agershun The result of these two functions should be the same, and it seems that now it is a same:
var data = [{a:1},{a:2},{a:1}];

var res1= alasql('SELECT * FROM ?',[data]);
var res2= alasql('SELECT DISTINCT * FROM ?',[data]);
var res3= alasql('SELECT COLUMN DISTINCT _ FROM ?',[data]);
var res4= alasql('SEARCH DISTINCT(/) FROM ?',[data]);

You can try this example in jsFiddle
</comment_new>
<comment_new>@mathiasrw
a) how come we use the _in the column distinct?

b) if you change the middle data to b:2 I would expect [{a:1},{b:2}] from res3 but get only a:1 http://jsfiddle.net/dw6eLu8h/2/
</comment_new>
<comment_new>@agershun
_ is a original object from the source array (reference), where * is a copy property by property.

For example:

    SET @data = @[{a:1},{a:2}];
    SELECT a FROM @data;
    -- [{a:1},{a:2}]
    SELECT _ FROM @data;
    -- [{_:{a:1}},{_:{a:2}}]
    SELECT  FROM @data; -- equivalent of SELECT  COLUMN _ FROM @data;
    -- [{a:1},{a:2}]

   SET @arr = @[1,2,3];
   SELECT * FROM @arr;
   -- should be  Error because this is not an object
    SELECT _ FROM @arr
    -- [{_:1},{_:2},{_:3},]
    SELECT FROM @arr
     -- [1,2,3]
    SELECT FROM @arr ORDER BY _ DESC
    -- [3,2,1]

</comment_new>
<comment_new>@mathiasrw
Ahh - ok

Did you check out b) ?
</comment_new>

Original prompt

This section details on the original issue you should resolve

<issue_title>Fix SEARCH DISTINCT function and SELECT DISTINCT functions</issue_title>
<issue_description>There are some problems with this operator to be fixed
</issue_description>

<agent_instructions>Please make a test file called test167B.js verifying if this issue is still a problem.

If it is a problem try to solve it.

If you need to update the grammar of alasql, then please do small precice changes to alasqlparser.jison and then run yarn jison && yarn test</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@mathiasrw Can you describe the problems a bit more? @agershun The result of these two functions should be the same, and it seems that now it is a same:
var data = [{a:1},{a:2},{a:1}];

var res1= alasql('SELECT * FROM ?',[data]);
var res2= alasql('SELECT DISTINCT * FROM ?',[data]);
var res3= alasql('SELECT COLUMN DISTINCT _ FROM ?',[data]);
var res4= alasql('SEARCH DISTINCT(/) FROM ?',[data]);

You can try this example in jsFiddle

@mathiasrw a) how come we use the `_`in the column distinct?

b) if you change the middle data to b:2 I would expect [{a:1},{b:2}] from res3 but get only a:1 http://jsfiddle.net/dw6eLu8h/2/

@agershun _ is a original object from the source array (reference), where \* is a copy property by property.

For example:

    SET @data = @[{a:1},{a:2}];
    SELECT a FROM @data;
    -- [{a:1},{a:2}]
    SELECT _ FROM @data;
    -- [{_:{a:1}},{_:{a:2}}]
    SELECT  FROM @data; -- equivalent of SELECT  COLUMN _ FROM @data;
    -- [{a:1},{a:2}]

   SET @arr = @[1,2,3];
   SELECT * FROM @arr;
   -- should be  Error because this is not an object
    SELECT _ FROM @arr
    -- [{_:1},{_:2},{_:3},]
    SELECT FROM @arr
     -- [1,2,3]
    SELECT FROM @arr ORDER BY _ DESC
    -- [3,2,1]
@mathiasrw Ahh - ok

Did you check out b) ?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 19, 2025 10:01
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix SEARCH DISTINCT function and SELECT DISTINCT functions Fix DISTINCT with object values in SELECT and SEARCH queries Nov 19, 2025
Copilot finished work on behalf of mathiasrw November 19, 2025 10:12
Copilot AI requested a review from mathiasrw November 19, 2025 10:12
@mathiasrw mathiasrw marked this pull request as ready for review November 19, 2025 13:02
@mathiasrw
Copy link
Member

@copilot

Run yarn test-format-all
yarn run v1.22.22
$ prettier --list-different '{.,src,test}/*.{js,ts,json}' || (echo 'Please correct file formatting using yarn format-all and try again.' && exit 1)
test/test167B.js
Please correct file formatting using yarn format-all and try again.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@copilot

Run yarn test-format-all
...

Fixed formatting issues. Tests now use arrow functions without async done callbacks. Fixed in commit 7d43b9d.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • upload.wikimedia.org
    • Triggering command: /usr/local/bin/node node_modules/mocha/bin/mocha.js ./test --reporter dot --bail (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI requested a review from mathiasrw November 19, 2025 13:33
Copilot finished work on behalf of mathiasrw November 19, 2025 13:33
@mathiasrw mathiasrw merged commit 7ce536b into develop Nov 19, 2025
10 checks passed
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.

Fix SEARCH DISTINCT function and SELECT DISTINCT functions

2 participants