From 69bbc583794ec7b18c9222f0ee5dc97b2fab841a Mon Sep 17 00:00:00 2001 From: taozhi8833998 Date: Fri, 29 Nov 2024 08:35:09 +0800 Subject: [PATCH] feat: support float4 and float8 in snowflake --- pegjs/snowflake.pegjs | 8 +++++--- test/snowflake.spec.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pegjs/snowflake.pegjs b/pegjs/snowflake.pegjs index 58b682b4..d61253d4 100644 --- a/pegjs/snowflake.pegjs +++ b/pegjs/snowflake.pegjs @@ -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'; } @@ -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 }} diff --git a/test/snowflake.spec.js b/test/snowflake.spec.js index 1fec3d63..0a11aa89 100644 --- a/test/snowflake.spec.js +++ b/test/snowflake.spec.js @@ -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