Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static org.apache.iotdb.commons.conf.IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;
import static org.apache.iotdb.commons.conf.IoTDBConstant.PATH_ROOT;
Expand Down Expand Up @@ -262,26 +264,29 @@
}

@Override
protected Optional<PipeWritePlanEvent> trimRealtimeEventByPrivilege(
final PipeWritePlanEvent event) {
protected List<PipeWritePlanEvent> trimRealtimeEventByPrivilege(final PipeWritePlanEvent event) {
final ConfigPhysicalPlan plan =
((PipeConfigRegionWritePlanEvent) event).getConfigPhysicalPlan();
final Boolean isTableDatabasePlan = isTableDatabasePlan(plan);
Optional<ConfigPhysicalPlan> result = Optional.of(plan);
if (!Boolean.TRUE.equals(isTableDatabasePlan)) {
result = treePrivilegeParseVisitor.process(plan, userEntity);
}
if (result.isPresent() && !Boolean.FALSE.equals(isTableDatabasePlan)) {
result = TABLE_PRIVILEGE_PARSE_VISITOR.process(result.get(), userEntity);
}
if (result.isPresent()) {
return Optional.of(
new PipeConfigRegionWritePlanEvent(result.get(), event.isGeneratedByPipe()));
List<ConfigPhysicalPlan> result =
Boolean.TRUE.equals(isTableDatabasePlan)
? Collections.singletonList(plan)
: treePrivilegeParseVisitor.process(plan, userEntity);
if (!Boolean.FALSE.equals(isTableDatabasePlan)) {
result =
result.stream()
.map(parsedPlan -> TABLE_PRIVILEGE_PARSE_VISITOR.process(parsedPlan, userEntity))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());

Check warning on line 281 in iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/pipe/source/IoTDBConfigRegionSource.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this usage of 'Stream.collect(Collectors.toList())' with 'Stream.toList()' and ensure that the list is unmodified.

See more on https://sonarcloud.io/project/issues?id=apache_iotdb&issues=AaG_Q-3WaOwTC3lEYrP9&open=AaG_Q-3WaOwTC3lEYrP9&pullRequest=19182
}
if (skipIfNoPrivileges) {
return Optional.empty();
if (result.isEmpty() && !skipIfNoPrivileges) {
throw new AccessDeniedException(ManagerMessages.NOT_HAS_PRIVILEGE_TO_TRANSFER_PLAN + plan);
}
throw new AccessDeniedException(ManagerMessages.NOT_HAS_PRIVILEGE_TO_TRANSFER_PLAN + plan);
return result.stream()
.map(
parsedPlan -> new PipeConfigRegionWritePlanEvent(parsedPlan, event.isGeneratedByPipe()))
.collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static org.apache.iotdb.commons.conf.IoTDBConstant.MULTI_LEVEL_PATH_WILDCARD;

/**
* The {@link PipeConfigTreePatternParseVisitor} will transform the schema {@link
* ConfigPhysicalPlan}s using {@link IoTDBTreePatternOperations}. Rule:
Expand Down Expand Up @@ -303,16 +305,25 @@ public Optional<ConfigPhysicalPlan> visitPipeDeactivateTemplate(
@Override
public Optional<ConfigPhysicalPlan> visitTTL(
final SetTTLPlan setTTLPlan, final IoTDBTreePatternOperations pattern) {
final PartialPath partialPath = new PartialPath(setTTLPlan.getPathPattern());
final PartialPath originalPath = new PartialPath(setTTLPlan.getPathPattern());
final PartialPath partialPath =
setTTLPlan.isDataBase() ? originalPath.concatNode(MULTI_LEVEL_PATH_WILDCARD) : originalPath;
final List<PartialPath> intersectionList =
pattern.matchPrefixPath(partialPath.getFullPath())
? Collections.singletonList(partialPath)
: pattern.getIntersection(partialPath);
// The intersectionList is either a singleton list or an empty list, because the pipe
// pattern and TTL path are each either a prefix path or a full path
return !intersectionList.isEmpty()
? Optional.of(new SetTTLPlan(intersectionList.get(0).getNodes(), setTTLPlan.getTTL()))
: Optional.empty();
// Both the pipe pattern and the TTL path are prefix paths or full paths.
if (intersectionList.isEmpty()) {
return Optional.empty();
}
final PartialPath intersection = intersectionList.get(0);
final boolean retainDatabase = setTTLPlan.isDataBase() && intersection.equals(partialPath);
final SetTTLPlan result =
new SetTTLPlan(
retainDatabase ? originalPath.getNodes() : intersection.getNodes(),
setTTLPlan.getTTL());
result.setDataBase(retainDatabase);
return Optional.of(result);
}

@Override
Expand Down
Loading
Loading