Skip to content

fix #1415: UNION not returning correct result - #1629

Merged
mathiasrw merged 3 commits into
AlaSQL:developfrom
ambujsahu81:patch-1
Feb 8, 2023
Merged

mathiasrw merged 3 commits into
AlaSQL:developfrom
ambujsahu81:patch-1

Conversation

@ambujsahu81

@ambujsahu81 ambujsahu81 commented Feb 2, 2023 •

Copy link
Copy Markdown
Contributor

What is the PR `for?

  • This is an attempt to fix the issue #1415.
  • It seems that empty objects where due to query.columns.length = 0. That is why res and res2 had empty objects like this {}. May be the solution should make sure that query.columns.length !=0.
  • The solution in this pr might be a bad approach to resolve the issue. But if there are any feedback or issues related to my current solution than i could try to work on different approach too.🙂

Examples :

var data1=[{a:'abc'},{a:'xyz'}];
var data2=[{a:'123'},{a:'987'}];
var res = alasql("select * from :a union select * from :b",{a:data1,b:data2});

console.log(res); // [ { a: '123' }, { a: '987' }, { a: 'abc' }, { a: 'xyz' } ]

var res2 = alasql("select * from @[{x:true}, {x:3}] UNION select * from @[{x:false}, {x:9}]");

console.log(res2); // [ { x: false }, { x: 9 }, { x: true }, { x: 3 } ]

alasql("CREATE TABLE one (a string)");
alasql("CREATE TABLE Two (a string)");
alasql("INSERT INTO one VALUES ('abc'),('xyz')");
alasql("INSERT INTO Two VALUES ('123'),('987')");

var res3 = alasql("SELECT * FROM one union SELECT * FROM Two");

console.log(res3) // [ { a: 'abc' }, { a: 'xyz' }, { a: '123' }, { a: '987' } ]

@mathiasrw

Copy link
Copy Markdown
Member

Interesting. Thank you so much for taking the time do dive into this. -

Any chance you can add a test file so we know if we break it again one day?

@ambujsahu81

ambujsahu81 commented Feb 6, 2023 •

Copy link
Copy Markdown
Contributor Author

Interesting. Thank you so much for taking the time do dive into this. -

Any chance you can add a test file so we know if we break it again one day?

@mathiasrw, Thanks for reviewing the pr 🙂, I have added a simple unit test for this issue.

@mathiasrw
mathiasrw merged commit 4287740 into AlaSQL:develop Feb 8, 2023
@mathiasrw

Copy link
Copy Markdown
Member

Released as part of v3.1

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.

2 participants