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

MIN() and MAX() aggregate functions do not return a value #135

Closed
ajrcarey opened this issue Mar 25, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@ajrcarey
Copy link

commented Mar 25, 2019

Consider the following script, which uses 2.2.2 to import five identically-shaped CSV files containing random data into a table, and then runs a sequence of very simple aggregate functions across the data:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>NanoSQL Aggregate function test</title>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/@nano-sql/core@2.2.2/dist/nano-sql.min.js"></script>
</head>
<body>
</body>
<script>
    nSQL().connect({
        id: 'test',
        mode: 'TEMP',
        tables: [
            {
              name : 'users',
              model : {
                'id:uuid' : {'pk': true},
                'forename:string' : {},
                'surname:string' : {},
                'gender:string' : {},
                'age:int' : {},
                'education:string' : {},
                'occupation:string' : {},
                'salary:int' : {}
              },
              indexes: {
                'forename:string' : {},
                'surname:string' : {},
                'age:int' : {},
                'gender:string' : {},
                'education:string' : {},
                'occupation:string' : {},
                'salary:int' : {}
              }
            }
        ]
    }).then(() => {
        var promises = [];

        for (var i = 1; i <= 5; i ++) {
            promises[i - 1] = fetch(i + '.csv')
                .then(response => response.text())
                .then(csv => nSQL('users').loadCSV(csv));
        }

        Promise.all(promises).then(() => {
            nSQL('users')
                .query('select', ['COUNT(age)'])
                .exec()
                .then(result => console.log(result));

            nSQL('users')
                .query('select', ['AVG(age)'])
                .exec()
                .then(result => console.log(result));

            nSQL('users')
                .query('select', ['MIN(age)'])
                .exec()
                .then(result => console.log(result));

            nSQL('users')
                .query('select', ['MAX(age)'])
                .exec()
                .then(result => console.log(result));

            nSQL('users')
                .query('select', ['SUM(age)'])
                .exec()
                .then(result => console.log(result));
        });
    });
</script>
</html>

(The sample data is attached to #132 .)

The COUNT, AVG, and SUM aggregate functions all return the expected results. The MIN and MAX functions, however, do not; instead, they return the following error:

nano-sql.min.js:1 Uncaught (in promise) TypeError: s.match is not a function
    at Object.t.getFnValue (nano-sql.min.js:1)
    at nano-sql.min.js:1
    at Array.map (<anonymous>)
    at a (nano-sql.min.js:1)
    at Object.call (nano-sql.min.js:1)
    at Object.t.execFunction (nano-sql.min.js:1)
    at nano-sql.min.js:1
    at Array.forEach (<anonymous>)
    at o._streamAS (nano-sql.min.js:1)
    at t._nanoSQLQueue.processItem (nano-sql.min.js:1)

Do the MIN and MAX functions need to be provided by the browser, or otherwise polyfilled? This is on Chromium 73.0.3683.86 running on arch 64-bit fully patched.

@ClickSimply

This comment has been minimized.

Copy link
Owner

commented Mar 25, 2019

Yeah, looks like the built in javascript Math functions were overwriting the aggregate functions.

2.2.3 has been released and should have resolved the issue.

@ajrcarey

This comment has been minimized.

Copy link
Author

commented Mar 26, 2019

Many thanks, I confirm 2.2.3 resolves the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.