manticoresoftware / manticoresearch

Easy to use open source fast database for search | Good alternative to Elasticsearch now | Drop-in replacement for E in the ELK soon
https://manticoresearch.com
GNU General Public License v3.0
9.04k stars 507 forks source link

Select abstract values work for numbers, not for strings #1496

Open AbstractiveNord opened 1 year ago

AbstractiveNord commented 1 year ago

Describe the bug

SELECT 1 as number, data FROM table_name;  --works
SELECT 'string' as string, data FROM table_name;  --doesn't work

To Reproduce Steps to reproduce the behavior:

  1. Run latest ManticoreSearch in Docker
  2. CREATE TABLE issue(data text);
    INSERT INTO issue(data) values ('test');
    SELECT 1 as number, data FROM issue;
    SELECT 'string' as string, data FROM issue;
  3. mysql> CREATE TABLE issue(data text);
    Query OK, 0 rows affected (0,01 sec)
    
    mysql> INSERT INTO issue(data) values ('test');
    Query OK, 1 row affected (0,00 sec)
    
    mysql> SELECT 1 as number, data FROM issue;
    +--------+------+
    | number | data |
    +--------+------+
    |      1 | test |
    +--------+------+
    1 row in set (0,00 sec)
    
    mysql> SELECT 'string' as string, data FROM issue;
    ERROR 1064 (42000): P01: syntax error, unexpected AS, expecting '=' near 'as string, data FROM issue'
    mysql>

    Expected behavior

    mysql> SELECT 'string' as string, data FROM issue;
    +--------+------+
    | string | data |
    +--------+------+
    | string | test |
    +--------+------+

Describe the environment: Server version: 6.2.0 45680f95d@230804 git branch manticore-6.2.0...origin/manticore-6.2.0

sanikolaev commented 1 year ago

SELECT 'string' as string, data FROM table_name; --doesn't work

Please elaborate on why it's important to have this implemented.

AbstractiveNord commented 1 year ago

I have several cases with tools like Grafana and others, when returning abstract strings is required for specific plugins. For example, I want to enrich data from ManticoreSearch with static data, internal data from Grafana, using Variables, or even with data from another requests. Also popular use case is returning static data under IF statement.

tomatolog commented 1 year ago

it could be better to provide more examples of the feature as implement of plain select SELECT 'string' as s differs from the expression like SELECT if (attr1<b, 'string', attr2) as s

AbstractiveNord commented 1 year ago

I'll prepare more examples today.

sanikolaev commented 1 year ago

I have several cases with tools like Grafana and others, when returning abstract strings is required for specific plugins

How we can reproduce the issue with Grafana? You are probably using our recent Grafana integration and in this case if it's not working fine with Grafana, the task makes perfect sense and the required functionality should be implemented as a part of the integration (i.e. Buddy plugin), but there may be some specificity, so please provide the details.

AbstractiveNord commented 1 year ago

How we can reproduce the issue with Grafana? You are probably using our recent Grafana integration and in this case if it's not working fine with Grafana, the task makes perfect sense and the required functionality should be implemented as a part of the integration (i.e. Buddy plugin), but there may be some specificity, so please provide the details.

I use MySQL datasource with ManticoreSearch and it's work good. You can reproduce the issue using mysql console client, because it's identical with behavior of datasource. Performance of requests with static data are important, so I am not sure about implementing through Buddy. Simplest usecase of this feature is Logs dashboard for non-logs data. Let's say:

  1. Logs panel require level (trace, debug, info, etc.), message, and time columns.
  2. ManticoreSearch table "example" contains non-logs data, but it's similar, so Logs panel used for vizualization.
  3. Level field used by grafana plugin to highlight messages with colors different for every level (trace, debug, etc.)
  4. CREATE TABLE example(level integer, data text);
    INSERT INTO example(level, data) VALUES (1, 'text');
    SELECT 'info' as level, data as message, now() as time FROM example;  --doesn't work
  5. That's most common example.
  6. Example may be more complicated if you will try to remap some column (level for example) to tuple of ('trace', 'debug', 'info', etc.) with nested IFs.
AbstractiveNord commented 1 year ago

Also problem with string inside IFs

mysql> SELECT if (1 = 2, 1, 2);
+------------------+
| if (1 = 2, 1, 2) |
+------------------+
|                2 |
+------------------+
1 row in set (0,00 sec)

mysql> SELECT if ('test' = 'test', 1, 2);
ERROR 1064 (42000): P01: syntax error, unexpected ',', expecting '=' near ', 1, 2)'
AbstractiveNord commented 1 year ago

it could be better to provide more examples of the feature as implement of plain select SELECT 'string' as s differs from the expression like SELECT if (attr1<b, 'string', attr2) as s

mysql> SELECT if (attr1<b, 'string', attr2) as s;
ERROR 1064 (42000): if() arguments can not be string