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

Fix SQL config defaults and validation #3456

Merged
merged 9 commits into from
May 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import lombok.Builder;
import lombok.Data;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@Jacksonized
public class DatabaseConfig {

private static final String DEFAULT_PRIMARY_COLUMN = "pid";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
import java.util.Map;

import com.bakdata.conquery.models.datasets.Dataset;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.dropwizard.validation.ValidationMethod;
import jakarta.validation.Valid;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.jackson.Jacksonized;

@Data
@Builder
@Jacksonized
@NoArgsConstructor
@AllArgsConstructor
public class SqlConnectorConfig {
Expand All @@ -27,10 +32,19 @@ public class SqlConnectorConfig {
* Keys must match the name of existing {@link Dataset}s.
*/
@Getter(AccessLevel.PRIVATE)
private Map<String, DatabaseConfig> databaseConfigs;
private Map<String, @Valid DatabaseConfig> databaseConfigs;

public DatabaseConfig getDatabaseConfig(Dataset dataset) {
return databaseConfigs.get(dataset.getName());
}

@JsonIgnore
@ValidationMethod(message = "At lease 1 DatabaseConfig has to be present if SqlConnector config is enabled")
public boolean isValidSqlConnectorConfig() {
if (!enabled) {
return true;
}
return databaseConfigs != null && !databaseConfigs.isEmpty();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Table extends Labeled<TableId> implements NamespacedIdentifiable<Ta
*/
@Nullable
@JsonManagedReference
private Column primaryColum;
private Column primaryColumn;
Copy link
Collaborator

Choose a reason for hiding this comment

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

👌


@ValidationMethod(message = "More than one column map to the same secondaryId")
@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

public class TablePrimaryColumnUtil {

public static Field<Object> findPrimaryColumn(Table table, DatabaseConfig sqlConfig) {
String primaryColumnName = table.getPrimaryColum() == null
? sqlConfig.getPrimaryColumn()
: table.getPrimaryColum().getName();
public static Field<Object> findPrimaryColumn(Table table, DatabaseConfig databaseConfig) {
String primaryColumnName = table.getPrimaryColumn() == null
? databaseConfig.getPrimaryColumn()
: table.getPrimaryColumn().getName();
return DSL.field(DSL.name(table.getName(), primaryColumnName));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class RequiredTable {

public Table toTable(Dataset dataset, CentralRegistry centralRegistry) {
Table table = new Table();
table.setPrimaryColum(primaryColumn.toColumn(table, centralRegistry));
table.setPrimaryColumn(primaryColumn.toColumn(table, centralRegistry));
table.setDataset(dataset);
table.setName(name);
table.setColumns(Arrays.stream(columns)
Expand Down
Loading