From fc4c7f5eb1aaccba2a3cfb9dde288ce00ce504d2 Mon Sep 17 00:00:00 2001 From: sprisha <61725373+sprisha@users.noreply.github.com> Date: Fri, 10 Nov 2023 11:42:51 -0600 Subject: [PATCH] Add Snowflake Reserved Words to Extension file (#2444) * Add Snowflake Reserved Words to Extension file snowflake reserved words * Update postgresExtension.pure * Update snowflakeExtension.pure * Update TestSnowflakeExplodeSemiStructured.java * Update legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-postgres/legend-engine-xt-relationalStore-postgres-pure/src/main/resources/core_relational_postgres/relational/sqlQueryToString/postgresExtension.pure --------- Co-authored-by: Andrew Ormerod <49908208+aormerod-gs@users.noreply.github.com> --- .../sqlQueryToString/postgresExtension.pure | 107 +++++++++++++++++- .../TestSnowflakeExplodeSemiStructured.java | 22 ++-- .../sqlQueryToString/snowflakeExtension.pure | 103 ++++++++++++++++- 3 files changed, 217 insertions(+), 15 deletions(-) diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-postgres/legend-engine-xt-relationalStore-postgres-pure/src/main/resources/core_relational_postgres/relational/sqlQueryToString/postgresExtension.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-postgres/legend-engine-xt-relationalStore-postgres-pure/src/main/resources/core_relational_postgres/relational/sqlQueryToString/postgresExtension.pure index c66d916ebdb..e4ac10cb56a 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-postgres/legend-engine-xt-relationalStore-postgres-pure/src/main/resources/core_relational_postgres/relational/sqlQueryToString/postgresExtension.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-postgres/legend-engine-xt-relationalStore-postgres-pure/src/main/resources/core_relational_postgres/relational/sqlQueryToString/postgresExtension.pure @@ -24,7 +24,7 @@ function <> meta::relational::functions::sqlQueryToString::postg ^DbExtension( isBooleanLiteralSupported = true, - isDbReservedIdentifier = {str:String[1]| $str->in($reservedWords)}, + isDbReservedIdentifier = {str:String[1]| $str->toLower()->in($reservedWords)}, literalProcessor = $literalProcessor, joinStringsProcessor = processJoinStringsOperationForPostgres_JoinStrings_1__SqlGenerationContext_1__String_1_, selectSQLQueryProcessor = processSelectSQLQueryForPostgres_SelectSQLQuery_1__SqlGenerationContext_1__Boolean_1__String_1_, @@ -36,7 +36,110 @@ function <> meta::relational::functions::sqlQueryToString::postg function <> meta::relational::functions::sqlQueryToString::postgres::postgresReservedWords():String[*] { - []; + // https://www.postgresql.org/docs/current/sql-keywords-appendix.html + [ + 'all', + 'analyse', + 'analyze', + 'and', + 'any', + 'array', + 'as', + 'asc', + 'asymmetric', + 'authorization', + 'binary', + 'both', + 'case', + 'cast', + 'check', + 'collate', + 'collation', + 'column', + 'concurrently', + 'constraint', + 'create', + 'cross', + 'current_catalog', + 'current_date', + 'current_role', + 'current_schema', + 'current_time', + 'current_timestamp', + 'current_user', + 'default', + 'deferrable', + 'desc', + 'distinct', + 'do', + 'else', + 'end', + 'except', + 'false', + 'fetch', + 'for', + 'foreign', + 'freeze', + 'from', + 'full', + 'grant', + 'group', + 'having', + 'ilike', + 'in', + 'initially', + 'inner', + 'intersect', + 'into', + 'is', + 'isnull', + 'join', + 'lateral', + 'leading', + 'left', + 'like', + 'limit', + 'localtime', + 'localtimestamp', + 'natural', + 'not', + 'notnull', + 'null', + 'offset', + 'on', + 'only', + 'or', + 'order', + 'outer', + 'overlaps', + 'placing', + 'primary', + 'references', + 'returning', + 'right', + 'select', + 'session_user', + 'similar', + 'some', + 'symmetric', + 'system_user', + 'table', + 'tablesample', + 'then', + 'to', + 'trailing', + 'true', + 'union', + 'unique', + 'user', + 'using', + 'variadic', + 'verbose', + 'when', + 'where', + 'window', + 'with' + ]; } function <> meta::relational::functions::sqlQueryToString::postgres::getLiteralProcessorsForPostgres():Map[1] diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-execution/src/test/java/org/finos/legend/engine/plan/execution/stores/relational/test/semiStructured/TestSnowflakeExplodeSemiStructured.java b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-execution/src/test/java/org/finos/legend/engine/plan/execution/stores/relational/test/semiStructured/TestSnowflakeExplodeSemiStructured.java index 067d778e714..5d1a410d1e6 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-execution/src/test/java/org/finos/legend/engine/plan/execution/stores/relational/test/semiStructured/TestSnowflakeExplodeSemiStructured.java +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-execution/src/test/java/org/finos/legend/engine/plan/execution/stores/relational/test/semiStructured/TestSnowflakeExplodeSemiStructured.java @@ -33,7 +33,7 @@ public void testSimplePrimitivePropertiesProjectExplodeSource() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Orders/Id, String, VARCHAR(100), \"\"), (Orders/Identifier, String, VARCHAR(100), \"\"), (Orders/Price, Float, DOUBLE, \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Account\", VARCHAR(100)), (\"Orders/Id\", VARCHAR(100)), (\"Orders/Identifier\", VARCHAR(100)), (\"Orders/Price\", DOUBLE)]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".ACCOUNT as \"Account\", \"blocks_1\".ID as \"Orders/Id\", \"blocks_1\".IDENTIFIER as \"Orders/Identifier\", \"blocks_1\".PRICE as \"Orders/Price\" from Semistructured.Blocks as \"root\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".\"ACCOUNT\" as \"Account\", \"blocks_1\".ID as \"Orders/Id\", \"blocks_1\".IDENTIFIER as \"Orders/Identifier\", \"blocks_1\".PRICE as \"Orders/Price\" from Semistructured.Blocks as \"root\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Orders/Id, String, VARCHAR(100), \"\"), (Orders/Identifier, String, VARCHAR(100), \"\"), (Orders/Price, Float, DOUBLE, \"\")]\n"; @@ -51,7 +51,7 @@ public void testSimplePrimitivePropertiesProjectExplodeTarget() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Status, String, VARCHAR(100), \"\"), (Block/Id, String, VARCHAR(100), \"\"), (Block/Account, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Status\", VARCHAR(100)), (\"Block/Id\", VARCHAR(100)), (\"Block/Account\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".STATUS as \"Status\", \"trades_1\".ID as \"Block/Id\", \"trades_1\".ACCOUNT as \"Block/Account\" from Semistructured.Trades as \"root\" left outer join (select \"trades_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".ACCOUNT, \"blocks_0\".BLOCKDATA from Semistructured.Trades as \"trades_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".ACCOUNT, \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_2\".ID)) as \"trades_1\" on (\"root\".ID = \"trades_1\".leftJoinKey_0)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".STATUS as \"Status\", \"trades_1\".ID as \"Block/Id\", \"trades_1\".\"ACCOUNT\" as \"Block/Account\" from Semistructured.Trades as \"root\" left outer join (select \"trades_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".\"ACCOUNT\", \"blocks_0\".BLOCKDATA from Semistructured.Trades as \"trades_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".\"ACCOUNT\", \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_2\".ID)) as \"trades_1\" on (\"root\".ID = \"trades_1\".leftJoinKey_0)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Status, String, VARCHAR(100), \"\"), (Block/Id, String, VARCHAR(100), \"\"), (Block/Account, String, VARCHAR(100), \"\")]\n"; @@ -87,7 +87,7 @@ public void testComplexProjectMultiplePropertiesToExplodeInProject() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Orders/Id, String, VARCHAR(100), \"\"), (Orders/Identifier, String, VARCHAR(100), \"\"), (Trades/Id, String, VARCHAR(100), \"\"), (Trades/Status, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Account\", VARCHAR(100)), (\"Orders/Id\", VARCHAR(100)), (\"Orders/Identifier\", VARCHAR(100)), (\"Trades/Id\", VARCHAR(100)), (\"Trades/Status\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".ACCOUNT as \"Account\", \"blocks_1\".ID as \"Orders/Id\", \"blocks_1\".IDENTIFIER as \"Orders/Identifier\", \"blocks_3\".ID as \"Trades/Id\", \"blocks_3\".STATUS as \"Trades/Status\" from Semistructured.Blocks as \"root\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0) left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_3\" on (\"root\".ID = \"blocks_3\".leftJoinKey_0)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".\"ACCOUNT\" as \"Account\", \"blocks_1\".ID as \"Orders/Id\", \"blocks_1\".IDENTIFIER as \"Orders/Identifier\", \"blocks_3\".ID as \"Trades/Id\", \"blocks_3\".STATUS as \"Trades/Status\" from Semistructured.Blocks as \"root\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0) left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_3\" on (\"root\".ID = \"blocks_3\".leftJoinKey_0)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Orders/Id, String, VARCHAR(100), \"\"), (Orders/Identifier, String, VARCHAR(100), \"\"), (Trades/Id, String, VARCHAR(100), \"\"), (Trades/Status, String, VARCHAR(100), \"\")]\n"; @@ -105,7 +105,7 @@ public void testSimplePrimitivePropertiesProjectWithFilterOnSource() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Trades/Id, String, VARCHAR(100), \"\"), (Trades/Status, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Account\", VARCHAR(100)), (\"Trades/Id\", VARCHAR(100)), (\"Trades/Status\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".ACCOUNT as \"Account\", \"blocks_1\".ID as \"Trades/Id\", \"blocks_1\".STATUS as \"Trades/Status\" from Semistructured.Blocks as \"root\" left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0) where (\"root\".BLOCKDATA['status']::varchar <> 'cancelled' OR \"root\".BLOCKDATA['status']::varchar is null)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".\"ACCOUNT\" as \"Account\", \"blocks_1\".ID as \"Trades/Id\", \"blocks_1\".STATUS as \"Trades/Status\" from Semistructured.Blocks as \"root\" left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0) where (\"root\".BLOCKDATA['status']::varchar <> 'cancelled' OR \"root\".BLOCKDATA['status']::varchar is null)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Trades/Id, String, VARCHAR(100), \"\"), (Trades/Status, String, VARCHAR(100), \"\")]\n"; @@ -123,7 +123,7 @@ public void testSimplePrimitivePropertiesProjectWithFilterOnTarget() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Status, String, VARCHAR(100), \"\"), (Block/Id, String, VARCHAR(100), \"\"), (Block/Account, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Status\", VARCHAR(100)), (\"Block/Id\", VARCHAR(100)), (\"Block/Account\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".STATUS as \"Status\", \"trades_1\".ID as \"Block/Id\", \"trades_1\".ACCOUNT as \"Block/Account\" from Semistructured.Trades as \"root\" left outer join (select \"trades_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".ACCOUNT, \"blocks_0\".BLOCKDATA from Semistructured.Trades as \"trades_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".ACCOUNT, \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_2\".ID)) as \"trades_1\" on (\"root\".ID = \"trades_1\".leftJoinKey_0) where (\"trades_1\".BLOCKDATA['status']::varchar <> 'cancelled' OR \"trades_1\".BLOCKDATA['status']::varchar is null)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".STATUS as \"Status\", \"trades_1\".ID as \"Block/Id\", \"trades_1\".\"ACCOUNT\" as \"Block/Account\" from Semistructured.Trades as \"root\" left outer join (select \"trades_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".\"ACCOUNT\", \"blocks_0\".BLOCKDATA from Semistructured.Trades as \"trades_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".\"ACCOUNT\", \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_2\".ID)) as \"trades_1\" on (\"root\".ID = \"trades_1\".leftJoinKey_0) where (\"trades_1\".BLOCKDATA['status']::varchar <> 'cancelled' OR \"trades_1\".BLOCKDATA['status']::varchar is null)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Status, String, VARCHAR(100), \"\"), (Block/Id, String, VARCHAR(100), \"\"), (Block/Account, String, VARCHAR(100), \"\")]\n"; @@ -141,7 +141,7 @@ public void testProjectWithExplodedPropertyAccessOnlyInFilter() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Status, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Status\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".STATUS as \"Status\" from Semistructured.Trades as \"root\" left outer join (select \"trades_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".ACCOUNT, \"blocks_0\".BLOCKDATA from Semistructured.Trades as \"trades_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".ACCOUNT, \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_2\".ID)) as \"trades_1\" on (\"root\".ID = \"trades_1\".leftJoinKey_0) where (\"trades_1\".BLOCKDATA['status']::varchar <> 'cancelled' OR \"trades_1\".BLOCKDATA['status']::varchar is null)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".STATUS as \"Status\" from Semistructured.Trades as \"root\" left outer join (select \"trades_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".\"ACCOUNT\", \"blocks_0\".BLOCKDATA from Semistructured.Trades as \"trades_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".\"ACCOUNT\", \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_2\".ID)) as \"trades_1\" on (\"root\".ID = \"trades_1\".leftJoinKey_0) where (\"trades_1\".BLOCKDATA['status']::varchar <> 'cancelled' OR \"trades_1\".BLOCKDATA['status']::varchar is null)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Status, String, VARCHAR(100), \"\")]\n"; @@ -159,7 +159,7 @@ public void testFilterOnExplodedPropertyFilteringInsideProject() " (\n" + " type = TDS[(Block/Id, String, VARCHAR(100), \"\"), (Block/Account, String, VARCHAR(100), \"\"), (Big Buy Orders, String, VARCHAR(100), \"\"), (Orders/Id, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Block/Id\", VARCHAR(100)), (\"Block/Account\", VARCHAR(100)), (\"Big Buy Orders\", VARCHAR(100)), (\"Orders/Id\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Block/Id\", \"root\".ACCOUNT as \"Block/Account\", \"blocks_1\".ID as \"Big Buy Orders\", \"blocks_3\".ID as \"Orders/Id\" from Semistructured.Blocks as \"root\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0 and (\"blocks_1\".QUANTITY >= 100 and \"blocks_1\".SIDE = 'BUY')) left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_3\" on (\"root\".ID = \"blocks_3\".leftJoinKey_0)\n" + + " sql = select \"root\".ID as \"Block/Id\", \"root\".\"ACCOUNT\" as \"Block/Account\", \"blocks_1\".ID as \"Big Buy Orders\", \"blocks_3\".ID as \"Orders/Id\" from Semistructured.Blocks as \"root\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0 and (\"blocks_1\".QUANTITY >= 100 and \"blocks_1\".SIDE = 'BUY')) left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_3\" on (\"root\".ID = \"blocks_3\".leftJoinKey_0)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Block/Id, String, VARCHAR(100), \"\"), (Block/Account, String, VARCHAR(100), \"\"), (Big Buy Orders, String, VARCHAR(100), \"\"), (Orders/Id, String, VARCHAR(100), \"\")]\n"; @@ -177,7 +177,7 @@ public void testAggregationAggregateExplodedPropertyUsingGroupBy() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (quantity, Integer, INT, \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Account\", VARCHAR(100)), (\"quantity\", \"\")]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".ACCOUNT as \"Account\", sum(\"blocks_1\".TRADESUMMARY['execQuantity']) as \"quantity\" from Semistructured.Blocks as \"root\" left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0) group by \"Id\",\"Account\"\n" + + " sql = select \"root\".ID as \"Id\", \"root\".\"ACCOUNT\" as \"Account\", sum(\"blocks_1\".TRADESUMMARY['execQuantity']) as \"quantity\" from Semistructured.Blocks as \"root\" left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_2\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_2\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_2\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_2\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".leftJoinKey_0) group by \"Id\",\"Account\"\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (quantity, Integer, INT, \"\")]\n"; @@ -195,7 +195,7 @@ public void testAggregationAggregateExplodedPropertyInsideProject() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Buy Order, Integer, \"\", \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Account\", VARCHAR(100)), (\"Buy Order\", INT)]\n" + - " sql = select \"root\".ID as \"Id\", \"root\".ACCOUNT as \"Account\", \"blocks_1\".aggCol as \"Buy Order\" from Semistructured.Blocks as \"root\" left outer join (select \"blocks_2\".ID as ID, sum(\"blocks_3\".QUANTITY) as aggCol from Semistructured.Blocks as \"blocks_2\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_4\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_4\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_4\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_4\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_3\" on (\"blocks_2\".ID = \"blocks_3\".leftJoinKey_0) where \"blocks_3\".SIDE = 'BUY' group by \"blocks_2\".ID) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".ID)\n" + + " sql = select \"root\".ID as \"Id\", \"root\".\"ACCOUNT\" as \"Account\", \"blocks_1\".aggCol as \"Buy Order\" from Semistructured.Blocks as \"root\" left outer join (select \"blocks_2\".ID as ID, sum(\"blocks_3\".QUANTITY) as aggCol from Semistructured.Blocks as \"blocks_2\" left outer join (select \"orders_0\".ID, \"orders_0\".IDENTIFIER, \"orders_0\".QUANTITY, \"orders_0\".SIDE, \"orders_0\".PRICE, \"blocks_4\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_4\" inner join Semistructured.Orders as \"orders_0\" on (to_varchar(get_path(\"blocks_4\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_4\".flattened_prop, 'tagId')) = \"orders_0\".ID)) as \"blocks_3\" on (\"blocks_2\".ID = \"blocks_3\".leftJoinKey_0) where \"blocks_3\".SIDE = 'BUY' group by \"blocks_2\".ID) as \"blocks_1\" on (\"root\".ID = \"blocks_1\".ID)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Buy Order, Integer, \"\", \"\")]\n"; @@ -213,7 +213,7 @@ public void testSimpleJoinChainOneJoin() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Block/Id, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Account\", VARCHAR(100)), (\"Block/Id\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"orders_1\".ACCOUNT as \"Account\", \"orders_1\".ID as \"Block/Id\" from Semistructured.Orders as \"root\" left outer join (select \"orders_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".ACCOUNT, \"blocks_0\".BLOCKDATA from Semistructured.Orders as \"orders_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".ACCOUNT, \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"orders_2\".ID)) as \"orders_1\" on (\"root\".ID = \"orders_1\".leftJoinKey_0)\n" + + " sql = select \"root\".ID as \"Id\", \"orders_1\".\"ACCOUNT\" as \"Account\", \"orders_1\".ID as \"Block/Id\" from Semistructured.Orders as \"root\" left outer join (select \"orders_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".\"ACCOUNT\", \"blocks_0\".BLOCKDATA from Semistructured.Orders as \"orders_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".\"ACCOUNT\", \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"orders_2\".ID)) as \"orders_1\" on (\"root\".ID = \"orders_1\".leftJoinKey_0)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Account, String, VARCHAR(100), \"\"), (Block/Id, String, VARCHAR(100), \"\")]\n"; @@ -249,7 +249,7 @@ public void testJoinChainMultipleJoinsMultipleExplode() " (\n" + " type = TDS[(Id, String, VARCHAR(100), \"\"), (Trade Id, String, VARCHAR(100), \"\")]\n" + " resultColumns = [(\"Id\", VARCHAR(100)), (\"Trade Id\", VARCHAR(100))]\n" + - " sql = select \"root\".ID as \"Id\", \"blocks_2\".ID as \"Trade Id\" from Semistructured.Orders as \"root\" left outer join (select \"orders_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".ACCOUNT, \"blocks_0\".BLOCKDATA from Semistructured.Orders as \"orders_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".ACCOUNT, \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"orders_2\".ID)) as \"orders_1\" on (\"root\".ID = \"orders_1\".leftJoinKey_0) left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_0\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_2\" on (\"orders_1\".ID = \"blocks_2\".leftJoinKey_0)\n" + + " sql = select \"root\".ID as \"Id\", \"blocks_2\".ID as \"Trade Id\" from Semistructured.Orders as \"root\" left outer join (select \"orders_2\".ID as leftJoinKey_0, \"blocks_0\".ID, \"blocks_0\".\"ACCOUNT\", \"blocks_0\".BLOCKDATA from Semistructured.Orders as \"orders_2\" inner join (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID, \"root\".\"ACCOUNT\", \"root\".BLOCKDATA from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'order' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"orders_2\".ID)) as \"orders_1\" on (\"root\".ID = \"orders_1\".leftJoinKey_0) left outer join (select \"trades_0\".ID, \"trades_0\".STATUS, \"trades_0\".TRADESUMMARY, \"blocks_0\".leftJoinKey_0 as leftJoinKey_0 from (select \"ss_flatten_0\".value as flattened_prop, \"root\".ID as leftJoinKey_0 from Semistructured.Blocks as \"root\" inner join lateral flatten(input => \"root\".BLOCKDATA['relatedEntities'], outer => true, recursive => false, mode => 'array') as \"ss_flatten_0\") as \"blocks_0\" inner join Semistructured.Trades as \"trades_0\" on (to_varchar(get_path(\"blocks_0\".flattened_prop, 'tag')) = 'trade' and to_varchar(get_path(\"blocks_0\".flattened_prop, 'tagId')) = \"trades_0\".ID)) as \"blocks_2\" on (\"orders_1\".ID = \"blocks_2\".leftJoinKey_0)\n" + " connection = RelationalDatabaseConnection(type = \"Snowflake\")\n" + " )\n"; String TDSType = " type = TDS[(Id, String, VARCHAR(100), \"\"), (Trade Id, String, VARCHAR(100), \"\")]\n"; diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-pure/src/main/resources/core_relational_snowflake/relational/sqlQueryToString/snowflakeExtension.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-pure/src/main/resources/core_relational_snowflake/relational/sqlQueryToString/snowflakeExtension.pure index f2fb47dbcdf..588a8951ee8 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-pure/src/main/resources/core_relational_snowflake/relational/sqlQueryToString/snowflakeExtension.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-dbExtension/legend-engine-xt-relationalStore-snowflake/legend-engine-xt-relationalStore-snowflake-pure/src/main/resources/core_relational_snowflake/relational/sqlQueryToString/snowflakeExtension.pure @@ -20,7 +20,7 @@ function <> meta::relational::functions::sqlQueryToString::s function <> meta::relational::functions::sqlQueryToString::snowflake::createDbExtensionForSnowflake():DbExtension[1] { - let reservedWords = defaultReservedWords(); + let reservedWords = snowflakeReservedWords(); let literalProcessors = getDefaultLiteralProcessors()->putAll(getLiteralProcessorsForSnowflake()); let literalProcessor = {type:Type[1]| $literalProcessors->get(if($type->instanceOf(Enumeration), | Enum, | $type))->toOne()}; let dynaFuncDispatch = getDynaFunctionToSqlDefault($literalProcessor)->groupBy(d| $d.funcName)->putAll( @@ -30,7 +30,7 @@ function <> meta::relational::functions::sqlQueryToString::snowf isBooleanLiteralSupported = true, collectionThresholdLimit = 16348, aliasLimit = 255, - isDbReservedIdentifier = {str:String[1]| $str->in($reservedWords)}, + isDbReservedIdentifier = {str:String[1]| $str->toLower()->in($reservedWords)}, literalProcessor = $literalProcessor, windowColumnProcessor = processWindowColumn_WindowColumn_1__SqlGenerationContext_1__String_1_, semiStructuredElementProcessor = processSemiStructuredElementForSnowflake_RelationalOperationElement_1__SqlGenerationContext_1__String_1_, @@ -353,3 +353,102 @@ function meta::relational::functions::sqlQueryToString::snowflake::preAndFinally | [] ); } + +function <> meta::relational::functions::sqlQueryToString::snowflake::snowflakeReservedWords():String[*] +{ + // Based on https://docs.snowflake.com/en/sql-reference/reserved-keywords + [ + 'account', + 'alter', + 'and', + 'any', + 'as', + 'between', + 'by', + 'case', + 'cast', + 'check', + 'column', + 'connect', + 'connection', + 'constraint', + 'create', + 'cross', + 'current', + 'current_date', + 'current_time', + 'current_timestamp', + 'current_user', + 'database', + 'delete', + 'distinct', + 'drop', + 'else', + 'exists', + 'false', + 'following', + 'for', + 'from', + 'full', + 'grant', + 'group', + 'gscluster', + 'having', + 'ilike', + 'in', + 'increment', + 'inner', + 'insert', + 'intersect', + 'into', + 'is', + 'issue', + 'join', + 'lateral', + 'left', + 'like', + 'localtime', + 'localtimestamp', + 'minus', + 'natural', + 'not', + 'null', + 'of', + 'on', + 'or', + 'order', + 'organization', + 'qualify', + 'regexp', + 'revoke', + 'right', + 'rlike', + 'row', + 'rows', + 'sample', + 'schema', + 'select', + 'set', + 'some', + 'start', + 'table', + 'tablesample', + 'then', + 'to', + 'trigger', + 'true', + 'try_cast', + 'union', + 'unique', + 'update', + 'using', + 'values', + 'view', + 'when', + 'whenever', + 'where', + 'with' + ] +} + +