Skip to content

Commit adf4401

Browse files
dilumichcopybara-github
authored andcommitted
Improve the error message for schema embedding
PiperOrigin-RevId: 718465534 Change-Id: I46260fc05d7761f9c080b077034ce4d7d3a123a2
1 parent 23fa58b commit adf4401

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

koladata/data_slice.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,10 +1341,10 @@ absl::Status DataSlice::DelAttr(absl::string_view attr_name) const {
13411341
absl::StatusOr<DataSlice> DataSlice::EmbedSchema(bool overwrite) const {
13421342
if (!GetSchemaImpl().is_primitive_schema() &&
13431343
!GetSchemaImpl().is_struct_schema() && GetSchemaImpl() != schema::kNone) {
1344-
return absl::InvalidArgumentError(
1345-
absl::StrFormat("schema embedding is only supported for primitive and "
1346-
"entity schemas, got %v",
1347-
GetSchemaImpl()));
1344+
return absl::InvalidArgumentError(absl::StrFormat(
1345+
"schema embedding is only supported for a DataSlice with primitive, "
1346+
"entity, list or dict schemas, got %v",
1347+
GetSchemaImpl()));
13481348
}
13491349
return ToObject(*this, /*validate_schema=*/!overwrite);
13501350
}

koladata/data_slice_test.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,10 +1526,12 @@ TEST(DataSliceTest, EmbedSchema_MixedNotAllowed) {
15261526
auto values = test::MixedDataSlice<int, ObjectId>(
15271527
{1, std::nullopt}, {std::nullopt, internal::AllocateSingleObject()},
15281528
schema::kAny);
1529-
EXPECT_THAT(values.EmbedSchema(),
1530-
StatusIs(absl::StatusCode::kInvalidArgument,
1531-
"schema embedding is only supported for primitive and "
1532-
"entity schemas, got ANY"));
1529+
EXPECT_THAT(
1530+
values.EmbedSchema(),
1531+
StatusIs(
1532+
absl::StatusCode::kInvalidArgument,
1533+
"schema embedding is only supported for a DataSlice with primitive, "
1534+
"entity, list or dict schemas, got ANY"));
15331535
}
15341536

15351537
TEST(DataSliceTest, EmbedSchema_Object_Errors) {

koladata/object_factories_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,9 +1141,10 @@ TEST(ObjectCreatorTest, ObjectConverterError) {
11411141
EXPECT_THAT(
11421142
ObjectCreator::ConvertWithoutAdopt(
11431143
db, test::DataSlice<int>({1}, schema::kAny)),
1144-
StatusIs(absl::StatusCode::kInvalidArgument,
1145-
"schema embedding is only supported for primitive and "
1146-
"entity schemas, got ANY"));
1144+
StatusIs(
1145+
absl::StatusCode::kInvalidArgument,
1146+
"schema embedding is only supported for a DataSlice with primitive, "
1147+
"entity, list or dict schemas, got ANY"));
11471148
}
11481149

11491150
TEST(UuObjectCreatorTest, DataSlice) {

py/koladata/functions/tests/embed_schema_test.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"""Tests for embed_schema."""
16-
1715
from absl.testing import absltest
1816
from arolla import arolla
1917
from koladata.functions import functions as fns
@@ -48,8 +46,8 @@ def test_primitive(self):
4846
def test_error(self):
4947
with self.assertRaisesRegex(
5048
ValueError,
51-
'schema embedding is only supported for primitive and entity schemas,'
52-
' got ANY',
49+
'schema embedding is only supported for a DataSlice with primitive, '
50+
'entity, list or dict schemas, got ANY',
5351
):
5452
fns.embed_schema(ds([1, 'a']).as_any())
5553

0 commit comments

Comments
 (0)