private static void checkNullableVariables(IQ query) throws NullableVariableInMappingException { VariableNullability variableNullability = query.getTree().getVariableNullability(); if (!variableNullability.getNullableGroups().isEmpty()) throw new NullableVariableInMappingException(query, variableNullability.getNullableGroups()); }
private static void checkNullableVariables(IQ query) throws NullableVariableInMappingException { VariableNullability variableNullability = query.getTree().getVariableNullability(); if (!variableNullability.getNullableGroups().isEmpty()) throw new NullableVariableInMappingException(query, variableNullability.getNullableGroups()); }
@Override public VariableNullability getVariableNullability(ImmutableList<IQTree> children) { ImmutableMap<Variable, Collection<IQTree>> variableProvenanceMap = children.stream() .flatMap(c -> c.getVariables().stream() .map(v -> Maps.immutableEntry(v, c))) .collect(ImmutableCollectors.toMultimap()) .asMap(); ImmutableSet<Variable> coOccuringVariables = variableProvenanceMap.entrySet().stream() .filter(e -> e.getValue().size() > 1) .map(Map.Entry::getKey) .collect(ImmutableCollectors.toSet()); ImmutableSet<ImmutableSet<Variable>> nullableGroups = children.stream() .flatMap(c -> c.getVariableNullability().getNullableGroups().stream()) .filter(g -> g.stream() .noneMatch(coOccuringVariables::contains)) .collect(ImmutableCollectors.toSet()); return getOptionalFilterCondition() .map(e -> updateWithFilter(e, nullableGroups)) .orElseGet(() -> new VariableNullabilityImpl(nullableGroups)); }
@Override public VariableNullability getVariableNullability(IQTree child) { return updateWithFilter(getFilterCondition(), child.getVariableNullability().getNullableGroups()); }
@Override public VariableNullability getVariableNullability(ImmutableList<IQTree> children) { ImmutableSet<VariableNullability> variableNullabilities = children.stream() .map(IQTree::getVariableNullability) .collect(ImmutableCollectors.toSet()); ImmutableMultimap<Variable, ImmutableSet<Variable>> multimap = variableNullabilities.stream() .flatMap(vn -> vn.getNullableGroups().stream()) .flatMap(g -> g.stream() .map(v -> Maps.immutableEntry(v, g))) .collect(ImmutableCollectors.toMultimap()); ImmutableMap<Variable, ImmutableSet<Variable>> preselectedGroupMap = multimap.asMap().entrySet().stream() .collect(ImmutableCollectors.toMap( Map.Entry::getKey, e -> intersect(e.getValue()))); ImmutableSet<ImmutableSet<Variable>> nullableGroups = preselectedGroupMap.keySet().stream() .map(v -> computeNullableGroup(v, preselectedGroupMap, variableNullabilities)) .collect(ImmutableCollectors.toSet()); return new VariableNullabilityImpl(nullableGroups); }
@Override public IQ transform(IQ originalQuery) { IQTree tree = originalQuery.getTree(); ImmutableSet<ImmutableSet<Variable>> nullableGroups = tree.getVariableNullability().getNullableGroups(); return nullableGroups.isEmpty() ? originalQuery : insertFilter(originalQuery, nullableGroups); }
.map(c -> updateWithFilter(c, rightChild.getVariableNullability().getNullableGroups())) .orElseGet(rightChild::getVariableNullability); .immutableCopy(); ImmutableSet<ImmutableSet<Variable>> rightSelectedGroups = rightNullability.getNullableGroups().stream() .map(g -> g.stream() .filter(rightSpecificVariables::contains) leftChild.getVariableNullability().getNullableGroups().stream(), rightGroupStream) .collect(ImmutableCollectors.toSet());
@Override public VariableNullability getVariableNullability(IQTree child) { VariableNullability childNullability = child.getVariableNullability(); VariableGenerator variableGenerator = coreUtilsFactory.createVariableGenerator( Sets.union(projectedVariables, child.getVariables()).immutableCopy()); /* * The substitutions are split by nesting level */ VariableNullability nullabilityBeforeProjectingOut = splitSubstitution(substitution, variableGenerator) .reduce(childNullability, (n, s) -> updateVariableNullability(s, n), (n1, n2) -> { throw new MinorOntopInternalBugException("vns are not expected to be combined"); }); /* * Projects away irrelevant variables */ ImmutableSet<ImmutableSet<Variable>> nullableGroups = nullabilityBeforeProjectingOut.getNullableGroups().stream() .map(g -> g.stream() .filter(projectedVariables::contains) .collect(ImmutableCollectors.toSet())) .filter(g -> !g.isEmpty()) .collect(ImmutableCollectors.toSet()); return new VariableNullabilityImpl(nullableGroups); }