Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAT-18844] resolved some sonar issues #207

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public String getConfirmationMessage() {
getConstraintName());
}

@Override
protected Change[] createInverses() {
DropCheckConstraintChangeDatabricks inverse = new DropCheckConstraintChangeDatabricks();
inverse.setTableName(getTableName());
Expand Down
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 @@ -24,6 +24,7 @@
description = "Creates a lookup table containing values stored in a column and creates a foreign key to the new table.")
public class AddLookupTableChangeDatabricks extends AddLookupTableChange {

@Override
public String getFinalConstraintName() {
if (getConstraintName() == null) {
return ("fk_" + getExistingTableName() + "_" + getNewTableName()).toLowerCase();
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractAlterPropertiesChangeDatabricks already has supports() method that check DatabricksDatabase

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 @@ -8,11 +8,17 @@
import liquibase.ext.databricks.database.DatabricksDatabase;
import liquibase.servicelocator.PrioritizedService;
import liquibase.statement.SqlStatement;
import lombok.Getter;
import lombok.Setter;

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

@Getter
@Setter
@DatabaseChange(name = "analyzeTable", description = "Analyze Table Stats", priority = PrioritizedService.PRIORITY_DATABASE)
public class AnalyzeTableChange extends AbstractChange {

Expand All @@ -21,39 +27,7 @@ public class AnalyzeTableChange extends AbstractChange {
private String tableName;
private Map<String, String> partition = Collections.emptyMap();

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

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;
}

public Map<String, String> getPartition () {return this.partition;}

public ArrayList<String> getAnalyzeColumns () {return this.analyzeColumns;}

public void setPartition (Map<String, String> partition) {this.partition = partition;}

public void setAnalyzeColumns (ArrayList<String> analyzeColumns) {this.analyzeColumns = analyzeColumns;}
private List<String> analyzeColumns = new ArrayList<>();

@Override
public boolean supports(Database database) {
Expand All @@ -67,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 All @@ -88,14 +62,13 @@ public SqlStatement[] generateStatements(Database database) {
}

if (getAnalyzeColumns() == null) {
ArrayList<String> noColsArray = new ArrayList<> ();
List<String> noColsArray = new ArrayList<> ();

statement.setAnalyzeColumns(noColsArray);
} else {
statement.setAnalyzeColumns(getAnalyzeColumns());
}
SqlStatement[] builtStatement = new SqlStatement[] {statement};

return builtStatement;
return new SqlStatement[] {statement};
}
}
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
@@ -1,39 +1,22 @@
package liquibase.ext.databricks.change.analyzeTable;

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

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collections;

@Getter
@Setter
public class AnalyzeTableStatement extends AbstractSqlStatement {

private String catalogName;

private String schemaName;

private String tableName;

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

private List<String> analyzeColumns = new ArrayList<>();
private Map<String, String> partition = Collections.emptyMap();

public String getCatalogName() {return catalogName;}

public String getSchemaName() {return schemaName;}

public String getTableName() {return tableName;}

public ArrayList<String> getAnalyzeColumns() {return analyzeColumns;}

public Map<String, String> getPartition() {return partition;}
public void setCatalogName(String catalogName) { this.catalogName = catalogName;}

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

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

public void setAnalyzeColumns(ArrayList<String> analyzeColumns) {this.analyzeColumns = analyzeColumns;}

public void setPartition(Map<String, String> partition) {this.partition = partition;}

}
Loading
Loading