Skip to content

Commit

Permalink
Merge pull request #2242 from taozhi8833998/feat-float-num-type-snowf…
Browse files Browse the repository at this point in the history
…lake

feat: support float4 and float8 in snowflake
  • Loading branch information
taozhi8833998 authored Nov 29, 2024
2 parents f09376b + 69bbc58 commit ac394b1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4438,6 +4438,8 @@ KW_LONGTEXT = "LONGTEXT"i !ident_start { return 'LONGTEXT'; }
KW_BIGINT = "BIGINT"i !ident_start { return 'BIGINT'; }
KW_ENUM = "ENUM"i !ident_start { return 'ENUM'; }
KW_FLOAT = "FLOAT"i !ident_start { return 'FLOAT'; }
KW_FLOAT4 = "FLOAT4"i !ident_start { return 'FLOAT4'; }
KW_FLOAT8 = "FLOAT8"i !ident_start { return 'FLOAT8'; }
KW_DOUBLE = "DOUBLE"i !ident_start { return 'DOUBLE'; }
KW_BIGSERIAL = "BIGSERIAL"i !ident_start { return 'BIGSERIAL'; }
KW_REAL = "REAL"i !ident_start { return 'REAL'; }
Expand Down Expand Up @@ -4847,9 +4849,9 @@ numeric_type_suffix
return result
}
numeric_type
= t:(KW_NUMBER / KW_DECIMAL / KW_INT / KW_BYTEINT / KW_INTEGER / KW_NUMERIC / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_SERIAL / KW_BIGSERIAL / KW_REAL) __ LPAREN __ l:[0-9]+ __ r:(COMMA __ [0-9]+)? __ RPAREN __ s:numeric_type_suffix? { /* => data_type */ return { dataType: t, length: parseInt(l.join(''), 10), scale: r && parseInt(r[2].join(''), 10), parentheses: true, suffix: s }; }
/ t:(KW_NUMBER / KW_DECIMAL / KW_INT / KW_BYTEINT / KW_INTEGER / KW_NUMERIC / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_SERIAL / KW_BIGSERIAL / KW_REAL)l:[0-9]+ __ s:numeric_type_suffix? { /* => data_type */ return { dataType: t, length: parseInt(l.join(''), 10), suffix: s }; }
/ t:(KW_NUMBER / KW_DECIMAL / KW_INT / KW_BYTEINT / KW_INTEGER / KW_NUMERIC / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_DOUBLE / KW_SERIAL / KW_BIGSERIAL / KW_REAL) __ s:numeric_type_suffix? __{ /* => data_type */ return { dataType: t, suffix: s }; }
= t:(KW_NUMBER / KW_DECIMAL / KW_INT / KW_BYTEINT / KW_INTEGER / KW_NUMERIC / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_FLOAT4 / KW_FLOAT8 / KW_DOUBLE / KW_SERIAL / KW_BIGSERIAL / KW_REAL) __ LPAREN __ l:[0-9]+ __ r:(COMMA __ [0-9]+)? __ RPAREN __ s:numeric_type_suffix? { /* => data_type */ return { dataType: t, length: parseInt(l.join(''), 10), scale: r && parseInt(r[2].join(''), 10), parentheses: true, suffix: s }; }
/ t:(KW_NUMBER / KW_DECIMAL / KW_INT / KW_BYTEINT / KW_INTEGER / KW_NUMERIC / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_FLOAT4 / KW_FLOAT8 / KW_DOUBLE / KW_SERIAL / KW_BIGSERIAL / KW_REAL)l:[0-9]+ __ s:numeric_type_suffix? { /* => data_type */ return { dataType: t, length: parseInt(l.join(''), 10), suffix: s }; }
/ t:(KW_NUMBER / KW_DECIMAL / KW_INT / KW_BYTEINT / KW_INTEGER / KW_NUMERIC / KW_SMALLINT / KW_TINYINT / KW_BIGINT / KW_FLOAT / KW_FLOAT4 / KW_FLOAT8 / KW_DOUBLE / KW_SERIAL / KW_BIGSERIAL / KW_REAL) __ s:numeric_type_suffix? __{ /* => data_type */ return { dataType: t, suffix: s }; }

oid_type
= t:(KW_OID / KW_REGCLASS / KW_REGCOLLATION / KW_REGCONFIG / KW_REGDICTIONARY / KW_REGNAMESPACE / KW_REGOPER / KW_REGOPERATOR / KW_REGPROC / KW_REGPROCEDURE / KW_REGROLE / KW_REGTYPE) { /* => data_type */ return { dataType: t }}
Expand Down
12 changes: 12 additions & 0 deletions test/snowflake.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,18 @@ describe('snowflake', () => {
'SELECT listagg(DISTINCT "id", ", ") AS "ids" FROM "foo"'
]
},
{
title: 'float4 and float8 data type',
sql: [
`SELECT
my_column::float AS "my_number",
my_column::float4 AS "my_number2",
my_column::float8 AS "my_number3"
FROM
"my_table"`,
'SELECT "my_column"::FLOAT AS "my_number", "my_column"::FLOAT4 AS "my_number2", "my_column"::FLOAT8 AS "my_number3" FROM "my_table"'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit ac394b1

Please sign in to comment.