Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
KushnirykOleh committed Oct 31, 2024
1 parent 746e9c7 commit 3435072
Show file tree
Hide file tree
Showing 29 changed files with 36 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Sql[] generateSql(AddCheckConstraintStatementDatabricks statement, Databa

sql.append(" ADD CONSTRAINT ");

// Constrinat Name
// Constraint Name
sql.append(statement.getConstraintName());

sql.append(" CHECK (").append(statement.getConstraintBody()).append(")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import liquibase.exception.ValidationErrors;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import lombok.Setter;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

@Setter
@DatabaseChange(name = "alterCluster", description = "Alter Cluster", priority = PrioritizedService.PRIORITY_DATABASE +500)
public class AlterClusterChangeDatabricks extends AbstractChange {

Expand Down Expand Up @@ -59,10 +61,6 @@ public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

@DatabaseChangeProperty
public List<ColumnConfig> getColumns() {
if (columns == null) {
Expand All @@ -71,28 +69,16 @@ public List<ColumnConfig> getColumns() {
return columns;
}

public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}

@DatabaseChangeProperty
public String getCatalogName() {
return catalogName;
}

public void setCatalogName(String catalogName) {
this.catalogName = catalogName;
}

@DatabaseChangeProperty
public String getSchemaName() {
return schemaName;
}

public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}

@DatabaseChangeProperty
public List<NoneConfig> getClusterBy() {
if (clusterBy == null) {
Expand All @@ -101,7 +87,4 @@ public List<NoneConfig> getClusterBy() {
return clusterBy;
}

public void setClusterBy(List<NoneConfig> clusterBy) {
this.clusterBy = clusterBy;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package liquibase.ext.databricks.change.alterCluster;

import liquibase.statement.AbstractSqlStatement;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class AlterClusterDatabricksStatement extends AbstractSqlStatement {

private String tableName;
Expand All @@ -17,44 +21,4 @@ public AlterClusterDatabricksStatement(String tableName, String catalogName, Str
this.catalogName = catalogName;
this.schemaName = schemaName;
}

public String getTableName() {
return tableName;
}

public void setTableName(String tableName) {
this.tableName = tableName;
}

public List<ColumnConfig> getColumns() {
return columns;
}

public void setColumns(List<ColumnConfig> columns) {
this.columns = columns;
}

public String getCatalogName() {
return catalogName;
}

public void setCatalogName(String catalogName) {
this.catalogName = catalogName;
}

public String getSchemaName() {
return schemaName;
}

public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}

public List<NoneConfig> getClusterBy() {
return clusterBy;
}

public void setClusterBy(List<NoneConfig> clusterBy) {
this.clusterBy = clusterBy;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package liquibase.ext.databricks.change.alterCluster;

import liquibase.serializer.AbstractLiquibaseSerializable;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ColumnConfig extends AbstractLiquibaseSerializable {

private String name;
Expand All @@ -15,12 +19,4 @@ public String getSerializedObjectName() {
public String getSerializedObjectNamespace() {
return "http://www.liquibase.org/xml/ns/databricks";
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package liquibase.ext.databricks.change.alterCluster;

import liquibase.serializer.AbstractLiquibaseSerializable;
import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class NoneConfig extends AbstractLiquibaseSerializable {

private String none;
Expand All @@ -16,11 +20,4 @@ public String getSerializedObjectNamespace() {
return "http://www.liquibase.org/xml/ns/databricks";
}

public String getNone() {
return none;
}

public void setNone(String none) {
this.none = none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import liquibase.change.DatabaseChangeProperty;
import liquibase.database.Database;
import liquibase.ext.databricks.change.AbstractAlterPropertiesChangeDatabricks;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import lombok.Setter;
Expand All @@ -16,11 +15,6 @@ public class AlterTablePropertiesChangeDatabricks extends AbstractAlterPropertie
private static final String CHANGE_TYPE_SUBJECT = "Table";
private String tableName;

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
protected String getNoPropertiesErrorMessage() {
return applySubjectToErrorPattern(CHANGE_TYPE_SUBJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import liquibase.change.DatabaseChangeProperty;
import liquibase.database.Database;
import liquibase.ext.databricks.change.AbstractAlterPropertiesChangeDatabricks;
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import lombok.Setter;
Expand All @@ -16,11 +15,6 @@ public class AlterViewPropertiesChangeDatabricks extends AbstractAlterProperties
private static final String CHANGE_TYPE_SUBJECT = "View";
private String viewName;

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
}

@Override
protected String getNoPropertiesErrorMessage() {
return applySubjectToErrorPattern(CHANGE_TYPE_SUBJECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String getConfirmationMessage() {

@Override
protected Change[] createInverses() {
// No Op for Databricks ANALYZE statement. there is no rolling this back. Its just a stats collection operation
// No Op for Databricks ANALYZE statement. there is no rolling this back. It's just a stats collection operation
return new Change[]{
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ValidationErrors validate(AnalyzeTableStatement statement, Database datab
validationErrors.checkRequiredField("tableName", statement.getTableName());

// if analyzeColumns columns if null, dont add to sql statement - just use defaults (all columns)
// If parititon is null, skip
// If partition is null, skip
return validationErrors;
}

Expand All @@ -46,13 +46,13 @@ public Sql[] generateSql(AnalyzeTableStatement statement, Database database, Sql
String partitionColumnValue = partitionMap.getValue();

// append partition column for each map element, but there should only be one
sql.append(" PARTITION (" + partitionColumnName + " = '" + partitionColumnValue + "') ");
sql.append(" PARTITION (").append(partitionColumnName).append(" = '").append(partitionColumnValue).append("') ");


}

if (!statement.getAnalyzeColumns().isEmpty()) {
sql.append("COMPUTE STATISTICS FOR COLUMNS (" + String.join(", ", statement.getAnalyzeColumns()) + ")");
sql.append("COMPUTE STATISTICS FOR COLUMNS (").append(String.join(", ", statement.getAnalyzeColumns())).append(")");
}
else {
sql.append(" COMPUTE STATISTICS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
public class AnalyzeTableStatement extends AbstractSqlStatement {

private String catalogName;

private String schemaName;

private String tableName;

private List<String> analyzeColumns = new ArrayList<>();

private Map<String, String> partition = Collections.emptyMap();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,41 @@


import liquibase.statement.core.CreateTableStatement;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Getter
@Setter
public class CreateTableStatementDatabricks extends CreateTableStatement {

private String tableFormat;
private String tableLocation;

private List<String> clusterColumns;

private List<String> partitionColumns;

private ExtendedTableProperties extendedTableProperties;


public CreateTableStatementDatabricks(String catalogName, String schemaName, String tableName) {
super(catalogName, schemaName, tableName);
}

public void setTableFormat(String tableFormat) {this.tableFormat = tableFormat;}

public String getTableFormat() {return this.tableFormat;}

public void setTableLocation(String tableLocation) { this.tableLocation = tableLocation;}

public String getTableLocation() {return this.tableLocation;}
public List<String> getClusterColumns () {
return clusterColumns;
}

public List<String> getPartitionColumns () {
return partitionColumns;
}


public void setPartitionColumns (String partitionColumns) {
public void setPartitionColumns(String partitionColumns) {
if (partitionColumns == null) {
this.partitionColumns = new ArrayList<>();
return;
}
this.partitionColumns = new ArrayList<>(Arrays.asList(partitionColumns.split("\\s*,\\s*")));
}



public void setClusterColumns (String clusterColumns) {
public void setClusterColumns(String clusterColumns) {
if (clusterColumns == null) {
this.clusterColumns = new ArrayList<>();
return;
}
this.clusterColumns = new ArrayList<>(Arrays.asList(clusterColumns.split("\\s*,\\s*")));
}

public ExtendedTableProperties getExtendedTableProperties() {
return extendedTableProperties;
}

public void setExtendedTableProperties(ExtendedTableProperties extendedTableProperties) {
this.extendedTableProperties = extendedTableProperties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,21 @@
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import lombok.Getter;
import lombok.Setter;

import java.text.MessageFormat;

@Setter
@Getter
@DatabaseChange(name = "dropCheckConstraint", description = "Drops check constraint to Delta Table", priority = PrioritizedService.PRIORITY_DATABASE)
public class DropCheckConstraintChangeDatabricks extends AbstractChange {

private String catalogName;
private String schemaName;
private String tableName;

private String constraintName;

public String getCatalogName() {
return catalogName;
}

public void setCatalogName (String catalogName) {
this.catalogName = catalogName;
}

public String getTableName() {
return tableName;
}

public void setTableName (String tableName) {
this.tableName = tableName;
}

public String getSchemaName() {
return schemaName;
}

public void setSchemaName (String schemaName) {
this.schemaName = schemaName;
}

@Override
public boolean supports(Database database) {
return database instanceof DatabricksDatabase;
Expand All @@ -57,10 +36,6 @@ public String getConstraintName() {
return this.constraintName;
}

public void setConstraintName(String name) {
this.constraintName = name;
}


@Override
public String getConfirmationMessage() {
Expand Down
Loading

0 comments on commit 3435072

Please sign in to comment.