AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.02k stars 656 forks source link

FULL OUTER JOIN : artificial property added in results #647

Open Cheyenne55 opened 8 years ago

Cheyenne55 commented 8 years ago

Hello there,

(man your app is great) I am FULL OUTER JOINING two array of objects on a certain key. The output is fine at 99% but I noticed in the results that a property has been artificially added.

Array 1 :

[{
    "fusionkey": "MGN01",
    "cd_contrat": "MGN",
    "cd_risque": "01",
    "cd_produit": "336",
    "libelle": "Mutuelles Générales des Navigateurs"
}, {
    "fusionkey": "MGN02",
    "cd_contrat": "MGN",
    "cd_risque": "02",
    "cd_produit": "550",
    "libelle": "Mutuelles Générales des Navigateurs"
}, {
    "fusionkey": "MGN04",
    "cd_contrat": "MGN",
    "cd_risque": "04",
    "cd_produit": "911",
    "libelle": "Mutuelles Générales des Navigateurs"
}]

Array 2 :

[{
    "fusionkey": "MGN01",
    "cd_contrat": "MGN",
    "cd_risque": "01",
    "collectivite": "0993X-8299J"
}, {
    "fusionkey": "MGN01",
    "cd_contrat": "MGN",
    "cd_risque": "01",
    "collectivite": "0993X-IISJ1"
}, {
    "fusionkey": "MGN02",
    "cd_contrat": "MGN",
    "cd_risque": "02",
    "collectivite": "0994X-000I8"
}, {
    "fusionkey": "MGN03",
    "cd_contrat": "MGN",
    "cd_risque": "03",
    "collectivite": "YYSJK-98188"
}]

Resulting array :

[{
    "fusionkey": "MGN01",
    "cd_contrat": "MGN",
    "cd_risque": "01",
    "collectivite": "0993X-8299J",
    "cd_produit": "336",
    "libelle": "Mutuelles Générales des Navigateurs"
}, {
    "fusionkey": "MGN01",
    "cd_contrat": "MGN",
    "cd_risque": "01",
    "collectivite": "0993X-IISJ1",
    "cd_produit": "336",
    "libelle": "Mutuelles Générales des Navigateurs",
    "_rightjoin": true
}, {
    "fusionkey": "MGN02",
    "cd_contrat": "MGN",
    "cd_risque": "02",
    "collectivite": "0994X-000I8",
    "cd_produit": "550",
    "libelle": "Mutuelles Générales des Navigateurs"
}, {
    "fusionkey": "MGN03",
    "cd_contrat": "MGN",
    "cd_risque": "03",
    "collectivite": "YYSJK-98188"
}, {
    "fusionkey": "MGN04",
    "cd_contrat": "MGN",
    "cd_risque": "04",
    "cd_produit": "911",
    "libelle": "Mutuelles Générales des Navigateurs"
}]

alasql('SELECT * FROM ? arr1 FULL OUTER JOIN ? arr2 USING fusionkey', [array1, array2])

See the property _rightjoin in the results ? It is nowhere to be found in the joined array.

Any clue ? I am using v0.2.5

Btw : what is the difference between FULL OUTER JOIN and OUTER JOIN (neither LEFT or RIGHT) ?

Regards

mathiasrw commented 8 years ago

(glad you like it - lets make it awesome together)

Hmm... verry strange.

Thanks for taking the time to document an issue.

Any inputs @agershun ?

mathiasrw commented 8 years ago

Have a feeling its around https://github.com/agershun/alasql/blob/6eb924c74be866f0538b8cf895eb84458df03873/src/39dojoin.js#L112

Have been playing with http://jsfiddle.net/jqbxyxLL/ and can replicate the problem - but not your exact output

What SQL are you joining on to get only 5 results? (your exact SELECT)

mathiasrw commented 8 years ago

Any news on this?

Cheyenne55 commented 8 years ago

Hello back,

I am very busy these days so I have a high response latency... Well the exact used sql is the one I provided, no less no more. I tried it in your fiddle and indeed it outputs more articifial properties than I reported but nevertheless it is not good. Looking at the alasql code, I see that in step 2 the _rightjoin is supposed to be removed if it exists (line 161). So I think the code does not enter this part as it should be.

mathiasrw commented 8 years ago

Ok. Hmm. I will see what I can do

nbdamian commented 8 years ago

It looks like what is happening is that https://github.com/agershun/alasql/blob/6eb924c74be866f0538b8cf895eb84458df03873/src/39dojoin.js#L154 is only looping through the first array, so any data from the second array still contains the extra property.

mathiasrw commented 8 years ago

Ahh - so it never gets to delete dataw._rightjoin; for the other arrays

natee commented 7 years ago

Any new on this?

mathiasrw commented 7 years ago

nope :-/