aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTerry Wang <tytytyww@google.com>2023-12-05 03:36:06 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-12-05 03:36:06 +0000
commit185356a15e7a16a0a86d331ea1c87ee42f8c4844 (patch)
tree26b4619f5921a4948b419d870be2dcd527d05fdf
parentd7786c1d006962c09f64a08525386e5fb4b9450c (diff)
parente7b69188bb0a7111858430078478c3da02cebb42 (diff)
downloadicing-185356a15e7a16a0a86d331ea1c87ee42f8c4844.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into androidx-main am: e7b69188bb
Original change: https://android-review.googlesource.com/c/platform/external/icing/+/2858548 Change-Id: Ib31d172049889444a55c31941ba9f7460d39148d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--icing/icing-search-engine_schema_test.cc97
-rw-r--r--icing/util/document-validator.cc65
-rw-r--r--synced_AOSP_CL_number.txt2
3 files changed, 13 insertions, 151 deletions
diff --git a/icing/icing-search-engine_schema_test.cc b/icing/icing-search-engine_schema_test.cc
index 9b65e5e..49c024e 100644
--- a/icing/icing-search-engine_schema_test.cc
+++ b/icing/icing-search-engine_schema_test.cc
@@ -348,103 +348,6 @@ TEST_F(IcingSearchEngineSchemaTest,
}
}
-TEST_F(IcingSearchEngineSchemaTest, SchemaPropertyNotMatch) {
- IcingSearchEngine icing(GetDefaultIcingOptions(), GetTestJniCache());
- ASSERT_THAT(icing.Initialize().status(), ProtoIsOk());
-
- // 1. Create a schema with an Email type with String property
- SchemaProto schema;
- SchemaTypeConfigProto* type = schema.add_types();
- type->set_schema_type("Email");
- PropertyConfigProto* property = type->add_properties();
- property->set_property_name("title");
- property->set_data_type(PropertyConfigProto::DataType::STRING);
- property->set_cardinality(PropertyConfigProto::Cardinality::OPTIONAL);
-
- EXPECT_THAT(icing.SetSchema(schema).status(), ProtoIsOk());
-
- // 2. Add a document with different property
- DocumentProto doc = DocumentBuilder()
- .SetKey("emails", "email#1")
- .SetSchema("Email")
- .AddBooleanProperty("title", true)
- .Build();
- EXPECT_THAT(icing.Put(std::move(doc)).status(),
- ProtoStatusIs(StatusProto::INVALID_ARGUMENT));
- doc = DocumentBuilder()
- .SetKey("emails", "email#1")
- .SetSchema("Email")
- .AddDoubleProperty("title", 1)
- .Build();
- EXPECT_THAT(icing.Put(std::move(doc)).status(),
- ProtoStatusIs(StatusProto::INVALID_ARGUMENT));
- doc = DocumentBuilder()
- .SetKey("emails", "email#1")
- .SetSchema("Email")
- .AddBytesProperty("title", "attachment bytes")
- .Build();
- EXPECT_THAT(icing.Put(std::move(doc)).status(),
- ProtoStatusIs(StatusProto::INVALID_ARGUMENT));
- doc = DocumentBuilder()
- .SetKey("emails", "email#1")
- .SetSchema("Email")
- .AddInt64Property("title", 1)
- .Build();
- EXPECT_THAT(icing.Put(std::move(doc)).status(),
- ProtoStatusIs(StatusProto::INVALID_ARGUMENT));
- DocumentProto empty_document =
- DocumentBuilder().SetKey("icing", "uri1").SetSchema("email").Build();
- doc = DocumentBuilder()
- .SetKey("emails", "email#1")
- .SetSchema("Email")
- .AddDocumentProperty("title", empty_document)
- .Build();
- EXPECT_THAT(icing.Put(std::move(doc)).status(),
- ProtoStatusIs(StatusProto::INVALID_ARGUMENT));
-}
-
-TEST_F(IcingSearchEngineSchemaTest, SchemaPropertyNotMatchInNestedDoc) {
- IcingSearchEngine icing(GetDefaultIcingOptions(), GetTestJniCache());
- ASSERT_THAT(icing.Initialize().status(), ProtoIsOk());
-
- // 1. Create a schema with an Email type with a DOCUMENT property
- SchemaProto schema;
- SchemaTypeConfigProto* type = schema.add_types();
- type->set_schema_type("Email");
- PropertyConfigProto* property = type->add_properties();
- property->set_property_name("nestedDoc");
- property->set_schema_type("NestedDoc");
- property->set_data_type(PropertyConfigProto::DataType::DOCUMENT);
- property->set_cardinality(PropertyConfigProto::Cardinality::OPTIONAL);
-
- // 2. Create a schema with a NestedDoc type with a String property
- SchemaTypeConfigProto* nestedDoc = schema.add_types();
- nestedDoc->set_schema_type("NestedDoc");
- PropertyConfigProto* nestedDoc_property = nestedDoc->add_properties();
- nestedDoc_property->set_property_name("nestedProperty");
- nestedDoc_property->set_data_type(PropertyConfigProto::DataType::STRING);
- nestedDoc_property->set_cardinality(
- PropertyConfigProto::Cardinality::OPTIONAL);
-
- EXPECT_THAT(icing.SetSchema(schema).status(), ProtoIsOk());
-
- // 3. Create a nested document with different property
- DocumentProto nested_doc = DocumentBuilder()
- .SetKey("namespace", "nestedDoc#1")
- .SetSchema("NestedDoc")
- .AddBooleanProperty("nestedProperty", true)
- .Build();
-
- // 4. Add a Email with nested document.
- DocumentProto doc = DocumentBuilder()
- .SetKey("namespace", "email#1")
- .SetSchema("Email")
- .AddDocumentProperty("nestedDoc", nested_doc)
- .Build();
- EXPECT_THAT(icing.Put(std::move(doc)).status(),
- ProtoStatusIs(StatusProto::INVALID_ARGUMENT));
-}
-
TEST_F(IcingSearchEngineSchemaTest, SetSchemaUnsetVersionIsZero) {
IcingSearchEngine icing(GetDefaultIcingOptions(), GetTestJniCache());
ASSERT_THAT(icing.Initialize().status(), ProtoIsOk());
diff --git a/icing/util/document-validator.cc b/icing/util/document-validator.cc
index ebdb0d7..e0880ea 100644
--- a/icing/util/document-validator.cc
+++ b/icing/util/document-validator.cc
@@ -104,65 +104,24 @@ libtextclassifier3::Status DocumentValidator::Validate(
}
const PropertyConfigProto& property_config = *property_iter->second;
- // Validate the property data type and get the property value size according
- // to data type.
+ // Get the property value size according to data type.
int value_size = 0;
- if (property.string_values_size() > 0) {
- if (property_config.data_type() !=
- PropertyConfigProto::DataType::STRING) {
- return absl_ports::InvalidArgumentError(absl_ports::StrCat(
- "The data type of property name '", property.name(),
- "' is not STRING for key: (", document.namespace_(), ", ",
- document.uri(), ")."));
- }
+ if (property_config.data_type() == PropertyConfigProto::DataType::STRING) {
value_size = property.string_values_size();
- }
- if (property.int64_values_size() > 0) {
- if (property_config.data_type() != PropertyConfigProto::DataType::INT64) {
- return absl_ports::InvalidArgumentError(absl_ports::StrCat(
- "The data type of property name '", property.name(),
- "' is not INT64 for key: (", document.namespace_(), ", ",
- document.uri(), ")."));
- }
+ } else if (property_config.data_type() ==
+ PropertyConfigProto::DataType::INT64) {
value_size = property.int64_values_size();
- }
- if (property.double_values_size() > 0) {
- if (property_config.data_type() !=
- PropertyConfigProto::DataType::DOUBLE) {
- return absl_ports::InvalidArgumentError(absl_ports::StrCat(
- "The data type of property name '", property.name(),
- "' is not DOUBLE for key: (", document.namespace_(), ", ",
- document.uri(), ")."));
- }
+ } else if (property_config.data_type() ==
+ PropertyConfigProto::DataType::DOUBLE) {
value_size = property.double_values_size();
- }
- if (property.boolean_values_size() > 0) {
- if (property_config.data_type() !=
- PropertyConfigProto::DataType::BOOLEAN) {
- return absl_ports::InvalidArgumentError(absl_ports::StrCat(
- "The data type of property name '", property.name(),
- "' is not BOOLEAN for key: (", document.namespace_(), ", ",
- document.uri(), ")."));
- }
+ } else if (property_config.data_type() ==
+ PropertyConfigProto::DataType::BOOLEAN) {
value_size = property.boolean_values_size();
- }
- if (property.bytes_values_size() > 0) {
- if (property_config.data_type() != PropertyConfigProto::DataType::BYTES) {
- return absl_ports::InvalidArgumentError(absl_ports::StrCat(
- "The data type of property name '", property.name(),
- "' is not BYTES for key: (", document.namespace_(), ", ",
- document.uri(), ")."));
- }
+ } else if (property_config.data_type() ==
+ PropertyConfigProto::DataType::BYTES) {
value_size = property.bytes_values_size();
- }
- if (property.document_values_size() > 0) {
- if (property_config.data_type() !=
- PropertyConfigProto::DataType::DOCUMENT) {
- return absl_ports::InvalidArgumentError(absl_ports::StrCat(
- "The data type of property name '", property.name(),
- "' is not DOCUMENT for key: (", document.namespace_(), ", ",
- document.uri(), ")."));
- }
+ } else if (property_config.data_type() ==
+ PropertyConfigProto::DataType::DOCUMENT) {
value_size = property.document_values_size();
}
diff --git a/synced_AOSP_CL_number.txt b/synced_AOSP_CL_number.txt
index d79ff41..dd08fd1 100644
--- a/synced_AOSP_CL_number.txt
+++ b/synced_AOSP_CL_number.txt
@@ -1 +1 @@
-set(synced_AOSP_CL_number=587157429)
+set(synced_AOSP_CL_number=587883838)