69
69
import java .io .InputStream ;
70
70
import java .io .OutputStream ;
71
71
import java .util .*;
72
- import java .util .function .Predicate ;
73
- import java .util .stream .Collectors ;
74
72
75
73
import static org .apache .atlas .AtlasErrorCode .BAD_REQUEST ;
76
74
import static org .apache .atlas .AtlasErrorCode .DEPRECATED_API ;
@@ -93,6 +91,10 @@ public class EntityREST {
93
91
public static final String PREFIX_ATTR_ = "attr_" ;
94
92
public static final String QUALIFIED_NAME = "qualifiedName" ;
95
93
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
+ }};
96
98
97
99
98
100
private final AtlasTypeRegistry typeRegistry ;
@@ -899,15 +901,25 @@ public EntityMutationResponse createOrUpdate(AtlasEntitiesWithExtInfo entities,
899
901
}
900
902
901
903
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 <>();
905
905
906
906
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 ));
911
923
}
912
924
}
913
925
}
0 commit comments