72
72
import java .util .function .Predicate ;
73
73
import java .util .stream .Collectors ;
74
74
75
+ import static org .apache .commons .collections4 .MapUtils .emptyIfNull ;
75
76
import static org .apache .atlas .AtlasErrorCode .BAD_REQUEST ;
76
77
import static org .apache .atlas .AtlasErrorCode .DEPRECATED_API ;
77
78
import static org .apache .atlas .authorize .AtlasPrivilege .*;
@@ -93,6 +94,10 @@ public class EntityREST {
93
94
public static final String PREFIX_ATTR_ = "attr_" ;
94
95
public static final String QUALIFIED_NAME = "qualifiedName" ;
95
96
private static final int HUNDRED_THOUSAND = 100000 ;
97
+ private static final int TWO_MILLION = HUNDRED_THOUSAND * 10 * 2 ;
98
+ private static final Set <String > ATTRS_WITH_TWO_MILLION_LIMIT = new HashSet <String >() {{
99
+ add ("rawQueryText" );
100
+ }};
96
101
97
102
98
103
private final AtlasTypeRegistry typeRegistry ;
@@ -899,15 +904,25 @@ public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities,
899
904
}
900
905
901
906
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 ;
907
+ List <String > errorMessages = new ArrayList <>();
905
908
906
909
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" );
910
+ for (Map .Entry <String , Object > attribute : atlasEntity .getAttributes ().entrySet ()) {
911
+
912
+ if (attribute .getValue () instanceof String && ((String ) attribute .getValue ()).length () > HUNDRED_THOUSAND ) {
913
+
914
+ if (ATTRS_WITH_TWO_MILLION_LIMIT .contains (attribute .getKey ())) {
915
+ if (((String ) attribute .getValue ()).length () > TWO_MILLION ) {
916
+ errorMessages .add ("Attribute " + attribute .getKey () + " exceeds limit of " + TWO_MILLION + " characters" );
917
+ }
918
+ } else {
919
+ errorMessages .add ("Attribute " + attribute .getKey () + " exceeds limit of " + HUNDRED_THOUSAND + " characters" );
920
+ }
921
+ }
922
+ }
923
+
924
+ if (errorMessages .size () > 0 ) {
925
+ throw new AtlasBaseException (AtlasType .toJson (errorMessages ));
911
926
}
912
927
}
913
928
}
0 commit comments