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

Formatter doesn't recognize Hive CREATE TABLE modifiers #797

Open
melin opened this issue Nov 6, 2024 · 3 comments
Open

Formatter doesn't recognize Hive CREATE TABLE modifiers #797

melin opened this issue Nov 6, 2024 · 3 comments

Comments

@melin
Copy link

melin commented Nov 6, 2024

Input data

Which SQL and options did you provide as input?

CREATE TABLE k8s_demos.dd_dd_dd 
(id string COMMENT 'd', name string COMMENT 'name') 
using paimon COMMENT '122' TBLPROPERTIES (
  'compression' = 'ZSTD',
  'bizOwner' = 'huaixin',
  'dataLevel' = 'P3',
  'dwClassification' = '',
  'subject1' = '',
  'subject2' = '',
  'primary-key' = 'id'
) lifeCycle 122;

Expected Output

CREATE TABLE k8s_demos.dd_dd_dd (
  id string COMMENT 'd', 
  name string COMMENT 'name'
) 
using paimon 
COMMENT '122' 
TBLPROPERTIES (
  'compression' = 'ZSTD',
  'primary-key' = 'id'
) lifeCycle 122;

Actual Output

CREATE TABLE k8s_demos.dd_dd_dd (id string COMMENT 'd', name string COMMENT 'name') using paimon COMMENT '122' TBLPROPERTIES (
  'compression' = 'ZSTD',
  'bizOwner' = 'huaixin',
  'dataLevel' = 'P3',
  'dwClassification' = '',
  'subject1' = '',
  'subject2' = '',
  'primary-key' = 'id'
) lifeCycle 122;

Usage

  • How are you calling / using the library?
  • What SQL language(s) does this apply to?
  • Which SQL Formatter version are you using?
@melin melin added the bug label Nov 6, 2024
@nene
Copy link
Collaborator

nene commented Nov 6, 2024

Thanks for reporting. There are a few different problems here.

One is that the expression inside the first pair of parenthesis (the columns list) is pretty short, so it gets formatted on a single line. Though if one would just increase it by one character, it would get formatted as:

CREATE TABLE k8s_demos.dd_dd_dd (
  id string COMMENT 'id',
  name string COMMENT 'name'
) using paimon COMMENT '122' TBLPROPERTIES (
  'compression' = 'ZSTD',
  'bizOwner' = 'huaixin',
  'dataLevel' = 'P3',
  'dwClassification' = '',
  'subject1' = '',
  'subject2' = '',
  'primary-key' = 'id'
) lifeCycle 122;

The second is that the formatter doesn't recognize USING, COMMENT and TBLPROPERTIES as entities to be formatted on separate lines. With USING and TBLPROPERTIES that should be easily achievable. However, with COMMENT it's tricky as the formatter won't be able to distinguish between column comment and table comment. So if one is to be formatted on a separate line, all of them would be, which is probably not what you want.

@nene nene added the hive label Nov 6, 2024
@nene nene changed the title [FORMATTING] Hive create table sql Formatter doesn't recognize Hive CREATE TABLE modifiers Nov 6, 2024
@melin
Copy link
Author

melin commented Nov 6, 2024

The solution possible?
Judge in ‘create table (...)’ comment in parentheses does not need to add a new line, other comment add a new line.

@nene
Copy link
Collaborator

nene commented Nov 6, 2024

Sorry, but I don't quite understand what you are trying to say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants