Skip to content

Commit

Permalink
Work around regression introduced in core 4.29.2 (#650)
Browse files Browse the repository at this point in the history
[This commit](liquibase/liquibase@631b7d4#diff-57b8a969c50e3c98da190e27b6887f88de5466091cf62518775f6fda91ce008bR191-R206)
merged in core makes it so that parameters passed as `ArrayList`
get flattened to individual parameters, which breaks internal
prepared statements in `loadData` and `mergeNodes`.

The workaround consists in using another `List` type which is not
handled by the code linked above.
  • Loading branch information
fbiville authored Sep 10, 2024
1 parent 28cc697 commit deebc69
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import liquibase.statement.core.RawParameterizedSqlStatement;

import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -58,7 +59,10 @@ private List<Map<String, Object>> keyValuePairs(List<LoadDataRowConfig> rows) {
.map(row -> row.getColumns().stream()
.flatMap(LoadGraphDataChange::keyValuePair)
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)))
.collect(Collectors.toList());
// note: this is explicitly NOT using an ArrayList because of a regression introduced in core v4.29.2
// (see commit 631b7d42dd32d67f59f8294dc40d20d3c01085ab, JdbcExecutor#setParameters)
// ArrayList parameters get flattened instead of being treated as a whole list
.collect(Collectors.toCollection(LinkedList::new));
}

private static Stream<AbstractMap.SimpleEntry<String, Object>> keyValuePair(LoadDataColumnConfig column) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -42,7 +43,11 @@ public SqlStatement[] merge(MatchPattern pattern, List<PropertyMergePolicy> poli
private List<Long> getNodeIds(MatchPattern pattern) throws LiquibaseException {
String query = String.format("MATCH %s RETURN id(%s) AS id", pattern.cypherFragment(), pattern.outputVariable());
List<Map<String, ?>> rows = database.run(new RawParameterizedSqlStatement(query));
return rows.stream().map(row -> (Long) row.get("id")).collect(Collectors.toList());
return rows.stream().map(row -> (Long) row.get("id"))
// note: this is explicitly NOT using an ArrayList because of a regression introduced in core v4.29.2
// (see commit 631b7d42dd32d67f59f8294dc40d20d3c01085ab, JdbcExecutor#setParameters)
// ArrayList parameters get flattened instead of being treated as a whole list
.collect(Collectors.toCollection(LinkedList::new));
}

private Optional<SqlStatement> generateLabelCopyStatement(List<Long> ids) throws LiquibaseException {
Expand Down

0 comments on commit deebc69

Please sign in to comment.