summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Wang <tytytyww@google.com>2021-07-15 18:39:38 -0700
committerTerry Wang <tytytyww@google.com>2021-07-16 12:20:26 -0700
commit830c6797cd2647198f885e4ad1f5eb095aa866a2 (patch)
tree2fd99399be23d0f677c33cb52b6ff5c94f2a5f8b
parent4162c032bf1ec28e49548df1e042f57c8a7ae387 (diff)
Allow GenericDocument accept a String property longer than 20_000.
This limit was removed from the AppSearch Jetpack API meaning that a client could construct a GenericDocument successfully, but then have a PutDocuments call fail when converting from androidx.appsearch.GenericDocument to android.appsearch.GenericDocument. Icing still has a total document size limit which is 16 MiB. The put call will fail if it trying to write such document. Bug: 192909904 Test: GenericDocumentTest Change-Id: I86f97acc3a8e0f1c25fadf597aed9f42a2c493eb
-rw-r--r--apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java12
-rw-r--r--core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java14
2 files changed, 14 insertions, 12 deletions
diff --git a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java
index c905f95fe4c4..5801972fe81a 100644
--- a/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java
+++ b/apex/appsearch/framework/java/external/android/app/appsearch/GenericDocument.java
@@ -51,9 +51,6 @@ import java.util.Set;
public class GenericDocument {
private static final String TAG = "AppSearchGenericDocumen";
- /** The maximum {@link String#length} of a {@link String} field. */
- private static final int MAX_STRING_LENGTH = 20_000;
-
/** The maximum number of indexed properties a document can have. */
private static final int MAX_INDEXED_PROPERTIES = 16;
@@ -1286,15 +1283,6 @@ public class GenericDocument {
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
throw new IllegalArgumentException("The String at " + i + " is null.");
- } else if (values[i].length() > MAX_STRING_LENGTH) {
- throw new IllegalArgumentException(
- "The String at "
- + i
- + " length is: "
- + values[i].length()
- + ", which exceeds length limit: "
- + MAX_STRING_LENGTH
- + ".");
}
}
mProperties.putStringArray(name, values);
diff --git a/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java b/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java
index 6884f13d4cc9..3d820acf2d22 100644
--- a/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java
+++ b/core/tests/coretests/src/android/app/appsearch/external/app/GenericDocumentTest.java
@@ -62,4 +62,18 @@ public class GenericDocumentTest {
assertThat(outDoc.getPropertyDocument("propDocument").getPropertyBytesArray("propBytes"))
.isEqualTo(new byte[][] {{3, 4}});
}
+
+ @Test
+ public void testPutLargeDocument_exceedLimit() throws Exception {
+ // Create a String property that has a very large property.
+ char[] chars = new char[10_000_000];
+ String property = new StringBuilder().append(chars).append("the end.").toString();
+
+ GenericDocument doc =
+ new GenericDocument.Builder<>("namespace", "id1", "schema1")
+ .setPropertyString("propString", property)
+ .build();
+
+ assertThat(doc.getPropertyString("propString")).isEqualTo(property);
+ }
}