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

UNION not returning correct result #1415

Closed
umquat opened this issue Jan 14, 2022 · 10 comments
Closed

UNION not returning correct result #1415

umquat opened this issue Jan 14, 2022 · 10 comments

Comments

@umquat
Copy link

umquat commented Jan 14, 2022

AlaSQL is based on unpaid voluntary work. Thank you for taking the time to make it better.

Question about how to ...

Something is not working as expected:

  • Describe the problem

    UNION does not work.

  • Provide code that replicates the problem

data1=[{a:'abc'},{a:'xyz'}]
data2=[{a:'123'},{a:'987'}]

alasql("select * from :a union select * from :b",{a:data1,b:data2})

--- FF 95.01 Linux

[
  {},
  {},
  {
    "a": "abc"
  },
  {
    "a": "xyz"
  }
]

alasql.version
"1.7.3-develop-0be167bcundefined"

----- Chrome 97.0 Linux


[
    {},
    {},
    {
        "a": "abc"
    },
    {
        "a": "xyz"
    }
]

alasql.version
'1.7.3-develop-0be167bcundefined'

---- Node


> data1=[{a:'abc'},{a:'xyz'}]
[ { a: 'abc' }, { a: 'xyz' } ]
> data2=[{a:'123'},{a:'987'}]
[ { a: '123' }, { a: '987' } ]
> 
> alasql("select * from :a union select * from :b",{a:data1,b:data2})
[ {}, {}, { a: 'abc' }, { a: 'xyz' } ]
> alasql.version
'1.7.3-develop-0be167bcundefined'

---- How does it work in sqlite3

sqlite> create table one(a text);
sqlite> create table two(a text);
sqlite> insert into a values('abc'),('def');
sqlite> insert into two values('xyz'),('123');
sqlite> select * from one union select * from two;
123
abc
def
xyz



Maybe I'm using alasql incorrectly? I tried looking at some documentation in the wiki but the section on union is quite spartan.

Anyway, thanks a lot!

@mathiasrw
Copy link
Member

It should work - but does not...

@Tisamu
Copy link

Tisamu commented Oct 13, 2022

I would like to take the issue, could it be assigned to me ? 👍
( Here is a correct jsfiddle relative to this issue btw : http://jsfiddle.net/7pdhe9ng/ )

Thanks !

@mathiasrw
Copy link
Member

Sure!

@mathiasrw
Copy link
Member

@Tisamu Any ideas on how to approach this issue?

@Tisamu
Copy link

Tisamu commented Oct 26, 2022

Hello, sorry for giving no news.

Yep I've debugged a bit and it seems that the params of the first table are not passed to the union compilation method.

I'm still trying to understand all the compilation process of the query so I'm not sure where is the problem precisely.

I'm gonna work more on it this weekend. 😄

@mathiasrw
Copy link
Member

I have not dived into where this might be - but a few hints to debug: Its often good to understand the compiled function that is constructed to execute the query.

Idea:

Replicate the problem in the CLI version of alasql.

node bin/alasql-cli.js 'select * from @[{x:true}, {x:3}] UNION select * from @[{x:false}, {x:9}]'
[
  {},
  {},
  {
    "x": true
  },
  {
    "x": 3
  }
]

In the file dist/alasql.fs.js >THIS FILE WILL BE OVERWRITTEN IF YOU yarn build OR yarn test!< you find where the compiled function to be executed is created.

It could be here forexample

image

Then you run your CLI command with the inspect flag

node --inspect-brk bin/alasql-cli.js 'select * from @[{x:true}, {x:3}] UNION select * from @[{x:false}, {x:9}]'

Then you open chrome and go to chrome://inspect/#devices and click "inspect"

image

Now click here to start running

image

Then - if you placed the debugger; correctly you can inspect and follow what is happening. Happy hunting.

(nope - the place I inserted the debugger; did not stop the execution meaning that its not the right place...)


Please remember to move any changes to the proper files in src/ folder. Too many times have I found a fix and forgot I was live editing in the build destination and had to redo the details.

@Tisamu
Copy link

Tisamu commented Oct 27, 2022

Nice ! Thanks for the tips. 😄

@mathiasrw mathiasrw changed the title Problems with the UNION :) UNION not returning correct result Oct 27, 2022
@Tisamu
Copy link

Tisamu commented Nov 3, 2022

Well, sorry but I've a bit busy those weeks, not sure if I will be able to fix it soon. ☹️

Feel free to un-assign me the issue if someone else wanna take it.

@mathiasrw
Copy link
Member

Thank you for leaning in. Let me know if you leant something you want to share with others.

@mathiasrw
Copy link
Member

Any luck @Tisamu ?

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

No branches or pull requests

4 participants
@mathiasrw @Tisamu @umquat and others