Skip to content
Open
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
24 changes: 24 additions & 0 deletions cli/src/main/java/com/adaptivescale/rosetta/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,37 @@ private Stream<FileNameAndDatabasePair> getDatabaseForModel(Path directory, Stri
.map(path -> {
try {
Database input = new ObjectMapper(new YAMLFactory()).readValue(path.toFile(), Database.class);
applyOverride(path, input);
return new FileNameAndDatabasePair(path.getFileName().toString(), input);
} catch (Exception exception) {
throw new RuntimeException(exception);
}
});
}


/**
* Checks if an override file exists for the selected model. If it does,
* it applies the changes from the override file to the original model.
*
* @param path {@link Path} The path to the original model.
* @param input {@link Database} The original model.
* @throws IOException If an I/O error occurs.
*/
private void applyOverride(Path path,Database input) throws IOException {
Path overrideFile = Path.of(FilenameUtils.removeExtension(path.toString()) + ".override.yaml");
if (!Files.isDirectory(overrideFile)) {
Database override = new ObjectMapper(new YAMLFactory()).readValue(overrideFile.toFile(), Database.class);
HashMap<String, Table> tables = new HashMap();
input.getTables().stream().forEach(tbl -> tables.put(tbl.getSchema() + tbl.getName(), tbl));
override.getTables().stream().forEach(tbl -> {
//TODO: this currently overrides the whole table, we can extend this to include table or column level specific override
tables.put(tbl.getSchema() + tbl.getName(), tbl);
});
input.setTables(tables.values());
}
}

private Function<FileNameAndDatabasePair, FileNameAndDatabasePair> translateDatabases(Translator<Database, Database> translator) {
return fileNameAndModelPair -> {
try {
Expand Down