Skip to content

Commit

Permalink
Run bundles to speed up validation runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rikkola committed Jul 7, 2023
1 parent 8429482 commit 03b8308
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public CustomTreeSet() {
super(getComparator());
}

public Set<ColumnKey> getEqualColumns() {
return equalColumns;
}

private static Comparator<Key> getComparator() {
return (a, b) -> {
final int compareResult = compareKeys(a, b);
Expand All @@ -62,6 +58,24 @@ private static int compareKeys(final Key a,
return -1;
}

public Set<ColumnKey> getEqualColumns() {
return equalColumns;
}

public int getHash(Set<ColumnKey> bundleKeys) {
int result = 0;

// Inner HashMap would speed this up, but not sure if it is worth it.
// All the ParentKeys that we are looking for are like on the front of the list.
for (Key key : this) {
if (bundleKeys.contains(key.getParent())) {
result = 31 * result + ((OperatorValueKey) key).getValue().hashCode();
}
}

return result;
}

@Override
public boolean addAll(Collection c) {
if (c instanceof CustomTreeSet) {
Expand All @@ -79,4 +93,5 @@ public boolean add(Key o) {
}
return super.add(o);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,51 @@
public class CheckProducer {

public static List<Check> getChecks(final Map<Location, CustomTreeSet> parse) {
final Set<ColumnKey> bundleKeys = new HashSet<>();
final Set<ColumnKey> bundleKeys = formBundleKeys(parse);
final Map<Integer, RunBundle> bundles = formBundles(parse, bundleKeys);

final List<Check> result = new ArrayList<>();
for (final RunBundle value : bundles.values()) {
result.addAll(getCheckList(value.getMap()));
}

return result;
}

private static Set<ColumnKey> formBundleKeys(final Map<Location, CustomTreeSet> parse) {
final Set<ColumnKey> result = new HashSet<>();
for (final CustomTreeSet value : parse.values()) {
if (value instanceof CustomTreeSet) {
if (bundleKeys.isEmpty()) {
bundleKeys.addAll(value.getEqualColumns());
if (result.isEmpty()) {
result.addAll(value.getEqualColumns());
} else {
final Set<ColumnKey> removeKeys = bundleKeys.stream().filter(x -> !value.getEqualColumns().contains(x)).collect(Collectors.toSet());
bundleKeys.removeAll(removeKeys);
final Set<ColumnKey> removeKeys = result.stream().filter(x -> !value.getEqualColumns().contains(x)).collect(Collectors.toSet());
result.removeAll(removeKeys);
}
}
}
// TODO Skip using Collection<Key>
// TODO group by bundle column key hashes.

return result;
}

return getCheckList(parse);
private static Map<Integer, RunBundle> formBundles(final Map<Location, CustomTreeSet> parse,
final Set<ColumnKey> bundleKeys) {
final Map<Integer, RunBundle> result = new HashMap<>();
for (Map.Entry<Location, CustomTreeSet> entry : parse.entrySet()) {
int hash = entry.getValue().getHash(bundleKeys);
if (!result.containsKey(hash)) {
result.put(hash, new RunBundle());
}
result.get(hash).put(entry.getKey(), entry.getValue());
}
return result;
}

private static List<Check> getCheckList(final Map<Location, CustomTreeSet> parse) {
final List<Check> checks = new ArrayList<>();
final List<Check> result = new ArrayList<>();

// Single row
for (Map.Entry<Location, CustomTreeSet> row : parse.entrySet()) {
checks.add(
result.add(
new DetectEmptyRowCheck(
row.getKey(),
row.getValue()));
Expand All @@ -74,11 +95,11 @@ private static List<Check> getCheckList(final Map<Location, CustomTreeSet> parse
locationB,
parse.get(locationB));

checks.add(new SubsumptionCheck(
result.add(new SubsumptionCheck(
checkItemA,
checkItemB));
}
}
return checks;
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2023 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.yard.validator.adapter.checks;

import org.yard.validator.adapter.CustomTreeSet;
import org.yard.validator.adapter.key.Location;

import java.util.HashMap;
import java.util.Map;

public class RunBundle {

private final Map<Location, CustomTreeSet> map = new HashMap<>();

public Map<Location, CustomTreeSet> getMap() {
return map;
}

public void put(final Location key,
final CustomTreeSet value) {
map.put(key, value);
}
}

0 comments on commit 03b8308

Please sign in to comment.