-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read Snowflake views definitions with the Snowflake-specific query (#…
…3794) * Read Snowflake views definitions with the Snowflake-specific query * Move view DDL reading to the GetViewDefinitionGeneratorSnowflake class; avoid NPE from a view definition in the ViewSnapshotGenerator * Add logging for the case of empty view definition * Add Javadoc to the GetViewDefinitionGeneratorSnowflake class --------- Co-authored-by: filipe <flautert@liquibase.org>
- Loading branch information
1 parent
b5bad04
commit 11f4b66
Showing
4 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...wflake/src/main/java/liquibase/sqlgenerator/core/GetViewDefinitionGeneratorSnowflake.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package liquibase.sqlgenerator.core; | ||
|
||
import liquibase.CatalogAndSchema; | ||
import liquibase.database.Database; | ||
import liquibase.database.core.SnowflakeDatabase; | ||
import liquibase.sql.Sql; | ||
import liquibase.sql.UnparsedSql; | ||
import liquibase.sqlgenerator.SqlGeneratorChain; | ||
import liquibase.statement.core.GetViewDefinitionStatement; | ||
|
||
/** | ||
* Snowflake-specific view definition generator. | ||
* Uses Snowflake-specific query to read full view definition statement from a database. | ||
*/ | ||
public class GetViewDefinitionGeneratorSnowflake extends GetViewDefinitionGenerator { | ||
|
||
@Override | ||
public int getPriority() { | ||
return PRIORITY_DATABASE; | ||
} | ||
|
||
@Override | ||
public boolean supports(GetViewDefinitionStatement statement, Database database) { | ||
return database instanceof SnowflakeDatabase; | ||
} | ||
|
||
@Override | ||
public Sql[] generateSql(GetViewDefinitionStatement statement, Database database, SqlGeneratorChain sqlGeneratorChain) { | ||
CatalogAndSchema schema = new CatalogAndSchema(statement.getCatalogName(), statement.getSchemaName()).customize(database); | ||
// We can use non quoted schema/catalog/view names here. | ||
// SELECT GET_DDL('VIEW', 'TEST.BAD$SCHEMA_NAME.BAD$%^VIEW_NAME', TRUE) - works fine. | ||
// "TRUE" means that the returned result will be in the full representation | ||
return new Sql[] { | ||
new UnparsedSql( "SELECT GET_DDL('VIEW', '" | ||
+ schema.getCatalogName() + "." + schema.getSchemaName() + "." + statement.getViewName() + "', TRUE)" | ||
) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters