liquibase.ext.databricks.sqlgenerator.AlterTablePropertiesGeneratorDatabricks Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of liquibase-databricks Show documentation
Show all versions of liquibase-databricks Show documentation
Liquibase Extension for Databricks.
The newest version!
package liquibase.ext.databricks.sqlgenerator;
import liquibase.database.Database;
import liquibase.exception.ValidationErrors;
import liquibase.ext.databricks.change.alterTableProperties.AlterTablePropertiesStatementDatabricks;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.sql.Sql;
import liquibase.sql.UnparsedSql;
import liquibase.sqlgenerator.SqlGeneratorChain;
import liquibase.sqlgenerator.core.AbstractSqlGenerator;
public class AlterTablePropertiesGeneratorDatabricks extends AbstractSqlGenerator {
@Override
public boolean supports(AlterTablePropertiesStatementDatabricks statement, Database database) {
return super.supports(statement, database) && (database instanceof DatabricksDatabase);
}
@Override
public int getPriority() {
return PRIORITY_DATABASE;
}
@Override
public ValidationErrors validate(AlterTablePropertiesStatementDatabricks statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
ValidationErrors validationErrors = new ValidationErrors();
if (statement.getSetExtendedTableProperties() == null && statement.getUnsetExtendedTableProperties() == null){
validationErrors.addError("WARNING! Alter Table Properties change require 'setExtendedTableProperties' or 'unsetExtendedTableProperties' element, please add at least one option.");
}
return validationErrors;
}
@Override
public Sql[] generateSql(AlterTablePropertiesStatementDatabricks statement, Database database, SqlGeneratorChain sqlGeneratorChain) {
StringBuilder buffer = new StringBuilder();
buffer.append("ALTER TABLE ");
buffer.append(database.escapeTableName(statement.getCatalogName(), statement.getSchemaName(), statement.getTableName()));
if (statement.getSetExtendedTableProperties() != null) {
buffer.append(" SET TBLPROPERTIES (");
buffer.append(statement.getSetExtendedTableProperties().getTblProperties());
} else if (statement.getUnsetExtendedTableProperties() != null) {
buffer.append(" UNSET TBLPROPERTIES (");
buffer.append(statement.getUnsetExtendedTableProperties().getTblProperties());
}
buffer.append(")");
return new Sql[]{
new UnparsedSql(buffer.toString())
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy