crate / crate-admin

The admin user interface for CrateDB.
Apache License 2.0
26 stars 19 forks source link

Bug: When clicking "Query Table" generated query syntax is wrong for object fields with whitespaces #669

Closed proddata closed 4 years ago

proddata commented 4 years ago

CrateDB version: 4.1.6

Environment description: CrateDB Cloud (Dev-Instance - 3 nodes are / 3 CPUs / 3GB Ram

Problem description:

When clicking "Query Table" generated query syntax is wrong for object fields with whitespaces Steps to reproduce:

CREATE table nexo.test (obj OBJECT(DYNAMIC));
--CREATE TABLE OK, 1 row affected (0.852 sec)

INSERT INTO nexo.test VALUES('{ "field1" : 100 }');
-- INSERT OK, 1 row affected (0.076 sec)

INSERT INTO nexo.test VALUES('{ "field 2" : 100 }');
-- INSERT OK, 1 row affected (0.076 sec)

SELECT * FROM nexo.test limit 100;
-- SELECT OK, 2 rows in set (0.006 sec)

In Admin UI go to table nexo.test and press 'Query Table'

-- the following query gets generated:
SELECT "obj","obj['field 2']" FROM "nexo"."test" LIMIT 100;

Which leads to an error, as the syntax is wrong ... should be

SELECT "obj","obj"['field 2'] FROM "nexo"."test" LIMIT 100;

Or even better, should be ..

SELECT "obj" FROM "nexo"."test" LIMIT 100;
proddata commented 4 years ago

Regex in tables.js:144 is wrong / doesn't take care of whitespaces within columns

var isNestedColumn = function (column) {
          var re = /([^\s]+)(\[\'([^\s]+)\'])+/i;
          return column.match(re);
        };

probably should be something like ...

var isNestedColumn = function (column) {
          var re = /([^\s]+)(\[\'(.+)\'])+/i;
          return column.match(re);
        };
autophagy commented 4 years ago

@proddata Thanks for reporting this and pinning down the issue! The fix has been merged, and will be available in the next admin ui release. :slightly_smiling_face: