Repository navigation
Case insensitive table/column names - #909
Conversation
…sql.options.casesensitive. Therefore, used alasql.options.casesensitive in alasqlparser.js 2) Now, as alasqlparser file when casesensitive options set to false sets all the column names to lowercase therefore in 84form.js file we are changing all column names to lowercase. This way now whatever case whether upper, lower or mixed case column names are specified in excel then also alasql can read data for all those columns when alasql.options.casesensitive is set to false.
|
This looks great - thank you! Please submit the builded files too so the automated tests can let us merge the code :) |
| if(opt.headers) { | ||
| if(workbook.Sheets[sheetid][col+""+row0]) { | ||
| hh[col] = workbook.Sheets[sheetid][col+""+row0].v; | ||
| hh[col] = alasql.options.casesensitive ? workbook.Sheets[sheetid][col+""+row0].v : (workbook.Sheets[sheetid][col+""+row0].v ? workbook.Sheets[sheetid][col+""+row0].v.toLowerCase() : workbook.Sheets[sheetid][col+""+row0].v); |
There was a problem hiding this comment.
This works - but its not so easy for future contributors to grasp.
Please restructure without using the if?then:else; structure.
| hh[col] = alasql.options.casesensitive ? workbook.Sheets[sheetid][col+""+row0].v : (workbook.Sheets[sheetid][col+""+row0].v ? workbook.Sheets[sheetid][col+""+row0].v.toLowerCase() : workbook.Sheets[sheetid][col+""+row0].v); | ||
| } else { | ||
| hh[col] = col; | ||
| hh[col] = alasql.options.casesensitive ? col : (col ? col.toLowerCase() : col); |
There was a problem hiding this comment.
Please restructure without using the if?then:else; structure.
|
|
||
| var test = '614'; // insert test file number | ||
|
|
||
| describe('Test ' + test + ' - Read data from column irrespective of case in query', function () { |
There was a problem hiding this comment.
Thank you so much for remembering to make a test for your PR :)
| alasql.options.casesensitive = true; | ||
| }); | ||
|
|
||
| it('1) Read Data and Check Value', function (done) { |
There was a problem hiding this comment.
Please describe the test in a way that tells what it is doing. Example could be "Mixed case excel with camel case select"
| assert.equal(res[0]['Account'.toLowerCase()], 12); | ||
| done(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I suggest having a few more tests both from a positive and a negative side.
A negative test would be that setting the flag to false, the same test would give an error / not find data
there could also be two columns with different case'ing setup (one only upper, one only lower) where it could be tested what happens on casesensetive = off or on
|
Hi,
I am working on the changes as suggested and I will submit those changes
soon. It's my pleasure that I can be of any help to open source community.
For automated tests to pass I will commit all the files which comes in
source control on build.
Regards
Amit
+91-8285400128
…On Thu, Jul 20, 2017 at 4:56 PM, Mathias Rangel Wulff < ***@***.***> wrote:
***@***.**** requested changes on this pull request.
------------------------------
In src/84from.js
<#909 (comment)>:
> @@ -405,9 +405,9 @@ function XLSXLSX(X,filename, opts, cb, idx, query) {
var col = alasql.utils.xlsnc(j);
if(opt.headers) {
if(workbook.Sheets[sheetid][col+""+row0]) {
- hh[col] = workbook.Sheets[sheetid][col+""+row0].v;
+ hh[col] = alasql.options.casesensitive ? workbook.Sheets[sheetid][col+""+row0].v : (workbook.Sheets[sheetid][col+""+row0].v ? workbook.Sheets[sheetid][col+""+row0].v.toLowerCase() : workbook.Sheets[sheetid][col+""+row0].v);
This works - but its not easy for people to understand.
Please restructure without using the if?then:else; structure.
------------------------------
In src/84from.js
<#909 (comment)>:
> } else {
- hh[col] = col;
+ hh[col] = alasql.options.casesensitive ? col : (col ? col.toLowerCase() : col);
Please restructure without using the if?then:else; structure.
------------------------------
In test/test614.js
<#909 (comment)>:
> @@ -0,0 +1,28 @@
+if (typeof exports === 'object') {
+ var assert = require("assert");
+ var alasql = require('..');
+}
+
+var test = '614'; // insert test file number
+
+describe('Test ' + test + ' - Read data from column irrespective of case in query', function () {
Thank you so much for remembering to make a test for your PR :)
------------------------------
In test/test614.js
<#909 (comment)>:
> +var test = '614'; // insert test file number
+
+describe('Test ' + test + ' - Read data from column irrespective of case in query', function () {
+
+ before(function () {
+ alasql('create database test' + test);
+ alasql('use test' + test);
+ alasql.options.casesensitive = false;
+ });
+
+ after(function () {
+ alasql('drop database test' + test);
+ alasql.options.casesensitive = true;
+ });
+
+ it('1) Read Data and Check Value', function (done) {
Please describe the test in a way that tells what it is doing. Example
could be "Mixed case excel with camel case select"
------------------------------
In test/test614.js
<#909 (comment)>:
> + alasql('create database test' + test);
+ alasql('use test' + test);
+ alasql.options.casesensitive = false;
+ });
+
+ after(function () {
+ alasql('drop database test' + test);
+ alasql.options.casesensitive = true;
+ });
+
+ it('1) Read Data and Check Value', function (done) {
+ alasql('SELECT Account FROM XLSX("' + __dirname + '/test614.xlsx")', [], function (res) {
+ assert.equal(res[0]['Account'.toLowerCase()], 12);
+ done();
+ });
+ });
I suggest having a few more tests both from a positive and a negative side.
A negative test would be that setting the flag to false, the same test
would give an error / not find data
there could also be two columns with different case'ing setup (one only
upper, one only lower) where it could be tested what happens on
casesensetive = off or on
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#909 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHhXF1YHaKiC3nOa3UbtYiL9bftiRJ2lks5sPzlLgaJpZM4Od3G6>
.
|
2) added test cases for Mixed Case, Upper Case and Lower Case. Both positive and negative tests are used 3) added files generated at build time in the commit
Codecov Report
@@ Coverage Diff @@
## develop #909 +/- ##
===========================================
+ Coverage 67.9% 67.92% +0.02%
===========================================
Files 1 1
Lines 9908 9912 +4
Branches 2963 2964 +1
===========================================
+ Hits 6728 6733 +5
+ Misses 3180 3179 -1
Continue to review full report at Codecov.
|
|
|
Looks really really good. Thank you for taking the time to contribute... |
|
It's my pleasure to have any contribution to such a great library. |
yy.casesensitive option doesn't update after changing value of alasql.options.casesensitive. Therefore, used alasql.options.casesensitive in alasqlparser.js
Now, as alasqlparser file when case-sensitive options set to false sets all the column names to lowercase therefore in 84form.js file we are changing all column names to lowercase. This way now whatever case whether upper, lower or mixed case column names are specified in excel then also alasql can read data for all those columns when alasql.options.casesensitive is set to false.
I have commited only my changes to the repository. I have not commited changes after build which includes changes in dist folder etc.
Thank you for the time you are putting into AlaSQL!