manticoresearch icon indicating copy to clipboard operation
manticoresearch copied to clipboard

Select abstract values work for numbers, not for strings

Open AbstractiveNord opened this issue 1 year ago • 8 comments

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

AbstractiveNord avatar Oct 08 '23 16:10 AbstractiveNord

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

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

sanikolaev avatar Oct 09 '23 06:10 sanikolaev

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.

AbstractiveNord avatar Oct 09 '23 08:10 AbstractiveNord

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

tomatolog avatar Oct 09 '23 09:10 tomatolog

I'll prepare more examples today.

AbstractiveNord avatar Oct 09 '23 09:10 AbstractiveNord

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.

sanikolaev avatar Oct 09 '23 10:10 sanikolaev

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 avatar Oct 09 '23 10:10 AbstractiveNord

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 avatar Oct 09 '23 10:10 AbstractiveNord

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

AbstractiveNord avatar Oct 09 '23 15:10 AbstractiveNord