clarkyu2016 / sql-beautify

VS Code extension that beautifies SQL(HQL).
MIT License
60 stars 20 forks source link

comments format bug #8

Closed xubuild closed 2 years ago

xubuild commented 3 years ago

Thanks for this useful tool!

I got some error when dealing with complex hive sql. The comments are not handled correctly in the sql below:

SELECT  aaa
       ,CAST(get_json_object(json_obj,'$.uid') AS BIGINT) AS uid 
       ,CASE WHEN get_json_object(json_obj,'$.app') = 'app1' THEN id -- comments
             ELSE get_json_object(json_obj,'$.start_id') -- comments
             END AS id
       ,CASE WHEN (
               array_contains(split(regexp_replace(regexp_replace(event_attribute['items'],'^\\[', ''), '\\]$', ''), ','), get_json_object(json_obj,'$.id')) -- comments
               OR event_attribute['id'] = get_json_object(json_obj,'$.id') -- comments
            ) THEN 1 -- comments
            ELSE 0 
            END AS has_item
FROM ddd.ttt
xubuild commented 3 years ago

It also got error in a simple case

select a,b,c
 -- comments
 d,e,f
 from ddd.ttt
clarkyu2016 commented 3 years ago

It also got error in a simple case

select a,b,c
 -- comments
 d,e,f
 from ddd.ttt

In this case,you miss the comma between c and d, so it got an error

xubuild commented 3 years ago

It also got error in a simple case

select a,b,c
 -- comments
 d,e,f
 from ddd.ttt

In this case,you miss the comma between c and d, so it got an error

sorry, mistype, I got error even with the comma

select a,b,c,
 -- comments
 d,e,f
 from ddd.ttt

become

SELECT  a
       ,b
       ,c
       ,
-- comments d
       ,e
       ,f
FROM ddd.ttt
clarkyu2016 commented 3 years ago

Thanks for this useful tool!

I got some error when dealing with complex hive sql. The comments are not handled correctly in the sql below:

SELECT  aaa
       ,CAST(get_json_object(json_obj,'$.uid') AS BIGINT) AS uid 
     ,CASE WHEN get_json_object(json_obj,'$.app') = 'app1' THEN id -- comments
           ELSE get_json_object(json_obj,'$.start_id') -- comments
             END AS id
       ,CASE WHEN (
               array_contains(split(regexp_replace(regexp_replace(event_attribute['items'],'^\\[', ''), '\\]$', ''), ','), get_json_object(json_obj,'$.id')) -- comments
               OR event_attribute['id'] = get_json_object(json_obj,'$.id') -- comments
            ) THEN 1 -- comments
            ELSE 0 
            END AS has_item
FROM ddd.ttt

Thanks for this complex case! I will try to fix it ASAP.

clarkyu2016 commented 3 years ago

select a,b,c -- comments d,e,f from ddd.ttt

This case has been fixed.