diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java index cd40af9677..7f5521e527 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/EntityREST.java @@ -69,8 +69,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.*; -import java.util.function.Predicate; -import java.util.stream.Collectors; import static org.apache.atlas.AtlasErrorCode.BAD_REQUEST; import static org.apache.atlas.AtlasErrorCode.DEPRECATED_API; @@ -93,6 +91,10 @@ public class EntityREST { public static final String PREFIX_ATTR_ = "attr_"; public static final String QUALIFIED_NAME = "qualifiedName"; private static final int HUNDRED_THOUSAND = 100000; + private static final int TWO_MILLION = HUNDRED_THOUSAND * 10 * 2; + private static final Set ATTRS_WITH_TWO_MILLION_LIMIT = new HashSet() {{ + add("rawQueryText"); + }}; private final AtlasTypeRegistry typeRegistry; @@ -899,15 +901,25 @@ public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities, } public static void validateAttributeLength(final List entities) throws AtlasBaseException { - //Predicate to check attribute value exceeding length - Predicate> predicateOfAttributeLengthExceedingLimit = attribute -> - attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND; + List errorMessages = new ArrayList<>(); for (final AtlasEntity atlasEntity : entities) { - Set attributeKeys = org.apache.commons.collections4.MapUtils.emptyIfNull(atlasEntity.getAttributes()) - .entrySet().stream().filter(predicateOfAttributeLengthExceedingLimit).map(Map.Entry::getKey).collect(Collectors.toSet()); - if (!attributeKeys.isEmpty()) { - throw new AtlasBaseException("Attribute(s) " + String.join(",", attributeKeys) + " exceeds limit of "+HUNDRED_THOUSAND+" characters"); + for (Map.Entry attribute : atlasEntity.getAttributes().entrySet()) { + + if (attribute.getValue() instanceof String && ((String) attribute.getValue()).length() > HUNDRED_THOUSAND) { + + if (ATTRS_WITH_TWO_MILLION_LIMIT.contains(attribute.getKey())) { + if (((String) attribute.getValue()).length() > TWO_MILLION) { + errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + TWO_MILLION + " characters"); + } + } else { + errorMessages.add("Attribute " + attribute.getKey() + " exceeds limit of " + HUNDRED_THOUSAND + " characters"); + } + } + } + + if (errorMessages.size() > 0) { + throw new AtlasBaseException(AtlasType.toJson(errorMessages)); } } }