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 e08d7633f3d..3b42e40750a 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 @@ -41,6 +41,7 @@ function <> meta::relational::functions::sqlQueryToString::snowf joinStringsProcessor = processJoinStringsOperationForSnowflake_JoinStrings_1__SqlGenerationContext_1__String_1_, selectSQLQueryProcessor = processSelectSQLQueryForSnowflake_SelectSQLQuery_1__SqlGenerationContext_1__Boolean_1__String_1_, selectSQLQueryWithCTEsProcessor = processSelectSQLQueryWithCTEsDefault_SelectSQLQueryWithCommonTableExpressions_1__SqlGenerationContext_1__Boolean_1__String_1_, + schemaIdentifierToString = meta::relational::functions::sqlQueryToString::snowflake::schemaIdentifierToString_String_1__DbConfig_1__String_1_, columnNameToIdentifier = columnNameToIdentifierDefault_String_1__DbConfig_1__String_1_, identifierProcessor = processIdentifierWithDoubleQuotes_String_1__DbConfig_1__String_1_, dynaFuncDispatch = $dynaFuncDispatch, @@ -50,6 +51,11 @@ function <> meta::relational::functions::sqlQueryToString::snowf ); } +function meta::relational::functions::sqlQueryToString::snowflake::schemaIdentifierToString(identifier:String[1], dbConfig: DbConfig[1]):String[1] +{ + $identifier->split('.')->map(s|$s->processIdentifierWithQuoteChar('"', $dbConfig))->joinStrings('.'); +} + function <> meta::relational::functions::sqlQueryToString::snowflake::getLiteralProcessorsForSnowflake():Map[1] { newMap([ @@ -413,7 +419,7 @@ function meta::relational::functions::sqlQueryToString::snowflake::preAndFinally function <> meta::relational::functions::sqlQueryToString::snowflake::transformConvertTimeZone(params:String[3],context:SqlGenerationContext[1]):String[1] { - let unWrappedfmt = $params->at(2)->substring(1, $params->at(2)->length()-1); $unWrappedfmt->println(); + let unWrappedfmt = $params->at(2)->substring(1, $params->at(2)->length()-1); assert($unWrappedfmt->validateDateTimeFormat(),'Found an invalid date format'); let formatpairs = meta::relational::functions::sqlQueryToString::default::defaultJavaToSQLTimeParts(); let format = $formatpairs->fold( {sub, date| $date->toOne()->replace($sub.first,$sub.second)},$params->at(2)); 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/transform/fromPure/tests/testSnowflakeToSQLString.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/transform/fromPure/tests/testSnowflakeToSQLString.pure index 1898b2a4603..ba5b69b40e8 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/transform/fromPure/tests/testSnowflakeToSQLString.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/transform/fromPure/tests/testSnowflakeToSQLString.pure @@ -172,6 +172,21 @@ function <> meta::relational::tests::sqlToString::snowflake::testToSQ assertEquals('select "root"."NAME" as "name" from "productSchema"."synonymTable" as "root" where (\'CUSIP\' <> \'ISIN\')', $result->replace('\n', '')); } +function <> meta::relational::tests::sqlToString::snowflake::testToSQLStringWithQuoteIdentifiersFlagAndSchemaMapping():Boolean[1] +{ + let runtime = ^meta::core::runtime::Runtime(connectionStores = ^meta::core::runtime::ConnectionStore(element = meta::relational::tests::db, + connection=^meta::external::store::relational::runtime::TestDatabaseConnection( + type = DatabaseType.Snowflake, + quoteIdentifiers = true, + sqlQueryPostProcessors = meta::pure::alloy::connections::postProcessTablesFn([], ^meta::pure::alloy::connections::SchemaNameMapper(from='productSchema', to='test.productSchema')) + ->map(pp|{query:meta::relational::metamodel::relation::SelectSQLQuery[1] | $query->meta::relational::postProcessor::postprocess($pp)}) + ))); + let result = toSQLStringPretty(|Synonym.all()->filter(s | $s.type != 'ISIN')->project([s | $s.name],['name']), + simpleRelationalMappingWithEnumConstant, $runtime, meta::relational::extension::relationalExtensions()); + + assertEquals('select "root"."NAME" as "name" from "test"."productSchema"."synonymTable" as "root" where (\'CUSIP\' <> \'ISIN\')', $result->replace('\n', '')); +} + function <> meta::relational::tests::sqlToString::snowflake::testToSQLStringWithQuoteIdentifiersFlagInColumnName():Boolean[1] { let runtime = ^meta::core::runtime::Runtime(connectionStores = ^meta::core::runtime::ConnectionStore(element = meta::relational::tests::db, connection=^meta::external::store::relational::runtime::TestDatabaseConnection( diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/src/main/resources/core_relational/relational/sqlQueryToString/dbExtension.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/src/main/resources/core_relational/relational/sqlQueryToString/dbExtension.pure index 4ea7fd7308b..f7e71f3e75f 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/src/main/resources/core_relational/relational/sqlQueryToString/dbExtension.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/src/main/resources/core_relational/relational/sqlQueryToString/dbExtension.pure @@ -114,6 +114,12 @@ Class meta::relational::functions::sqlQueryToString::DbConfig if($this.dbExtension.schemaNameToIdentifier->isEmpty(), |$s, |$this.dbExtension.schemaNameToIdentifier->toOne()->eval($s, $this)); }: String[1]; + schemaIdentifierToString(s:String[1]) + { + if($this.dbExtension.schemaIdentifierToString->isEmpty(), |$this.identifierProcessor($s), |$this.dbExtension.schemaIdentifierToString->toOne()->eval($s, $this)); + }: String[1]; + + tableNameToIdentifier(s:String[1]) { if($this.dbExtension.tableNameToIdentifier->isEmpty(), |$s, |$this.dbExtension.tableNameToIdentifier->toOne()->eval($s, $this)); @@ -226,6 +232,7 @@ Class meta::relational::functions::sqlQueryToString::DbExtension selectSQLQueryWithCTEsProcessor: meta::pure::metamodel::function::Function<{SelectSQLQueryWithCommonTableExpressions[1], SqlGenerationContext[1], Boolean[1] -> String[1]}>[0..1]; upsertSQLQueryProcessor: meta::pure::metamodel::function::Function<{UpsertSQLQuery[1], SqlGenerationContext[1] -> String[1]}>[0..1]; schemaNameToIdentifier: meta::pure::metamodel::function::Function<{String[1], DbConfig[1] -> String[1]}>[0..1]; + schemaIdentifierToString: meta::pure::metamodel::function::Function<{String[1], DbConfig[1] -> String[1]}>[0..1]; tableNameToIdentifier: meta::pure::metamodel::function::Function<{String[1], DbConfig[1] -> String[1]}>[0..1]; columnNameToIdentifier: meta::pure::metamodel::function::Function<{String[1], DbConfig[1] -> String[1]}>[0..1]; identifierProcessor: meta::pure::metamodel::function::Function<{String[1], DbConfig[1] -> String[1]}>[1]; @@ -443,7 +450,7 @@ function meta::relational::functions::sqlQueryToString::tableToString(table:Tabl { let schemaName = $dbConfig.schemaNameToIdentifier($table.schema.name); let tableName = $dbConfig.tableNameToIdentifier($table.name); - if($schemaName == 'default', | $dbConfig.identifierProcessor($tableName), | $dbConfig.identifierProcessor($schemaName) + '.' + $dbConfig.identifierProcessor($tableName)); + if($schemaName == 'default', | $dbConfig.identifierProcessor($tableName), | $dbConfig.schemaIdentifierToString($schemaName) + '.' + $dbConfig.identifierProcessor($tableName)); } function meta::relational::functions::sqlQueryToString::indent(d:Format[1]):Format[1]