Skip to content

Commit 1006eca

Browse files
Merge pull request #2360 from atlanhq/rawquerymigration
PLT-1886 Migrate Query.rawQuery to Query.rawQueryText
2 parents 0eb0644 + a428b48 commit 1006eca

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@
6969
import java.io.InputStream;
7070
import java.io.OutputStream;
7171
import java.util.*;
72-
import java.util.function.Predicate;
73-
import java.util.stream.Collectors;
7472

7573
import static org.apache.atlas.AtlasErrorCode.BAD_REQUEST;
7674
import static org.apache.atlas.AtlasErrorCode.DEPRECATED_API;
@@ -93,6 +91,10 @@ public class EntityREST {
9391
public static final String PREFIX_ATTR_ = "attr_";
9492
public static final String QUALIFIED_NAME = "qualifiedName";
9593
private static final int HUNDRED_THOUSAND = 100000;
94+
private static final int TWO_MILLION = HUNDRED_THOUSAND * 10 * 2;
95+
private static final Set<String> ATTRS_WITH_TWO_MILLION_LIMIT = new HashSet<String>() {{
96+
add("rawQueryText");
97+
}};
9698

9799

98100
private final AtlasTypeRegistry typeRegistry;
@@ -899,15 +901,25 @@ public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities,
899901
}
900902

901903
public static void validateAttributeLength(final List<AtlasEntity> entities) throws AtlasBaseException {
902-
//Predicate to check attribute value exceeding length
903-
Predicate<Map.Entry<String, Object>> predicateOfAttributeLengthExceedingLimit = attribute ->
904-
attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND;
904+
List<String> errorMessages = new ArrayList<>();
905905

906906
for (final AtlasEntity atlasEntity : entities) {
907-
Set<String> attributeKeys = org.apache.commons.collections4.MapUtils.emptyIfNull(atlasEntity.getAttributes())
908-
.entrySet().stream().filter(predicateOfAttributeLengthExceedingLimit).map(Map.Entry::getKey).collect(Collectors.toSet());
909-
if (!attributeKeys.isEmpty()) {
910-
throw new AtlasBaseException("Attribute(s) " + String.join(",", attributeKeys) + " exceeds limit of "+HUNDRED_THOUSAND+" characters");
907+
for (Map.Entry<String, Object> attribute : atlasEntity.getAttributes().entrySet()) {
908+
909+
if (attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND) {
910+
911+
if (ATTRS_WITH_TWO_MILLION_LIMIT.contains(attribute.getKey())) {
912+
if (((String) attribute.getValue()).length() > TWO_MILLION) {
913+
errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + TWO_MILLION + " characters");
914+
}
915+
} else {
916+
errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + HUNDRED_THOUSAND + " characters");
917+
}
918+
}
919+
}
920+
921+
if (errorMessages.size() > 0) {
922+
throw new AtlasBaseException(AtlasType.toJson(errorMessages));
911923
}
912924
}
913925
}

0 commit comments

Comments
 (0)