|
25 | 25 | #include <gtest/gtest.h> |
26 | 26 |
|
27 | 27 | #include "iceberg/expression/literal.h" |
| 28 | +#include "iceberg/test/matchers.h" |
28 | 29 | #include "iceberg/type.h" |
29 | 30 | #include "iceberg/util/formatter.h" // IWYU pragma: keep |
30 | 31 |
|
@@ -170,4 +171,22 @@ TEST(SchemaFieldTest, CastDefaultValue) { |
170 | 171 | } |
171 | 172 | } |
172 | 173 |
|
| 174 | +TEST(SchemaFieldTest, ValidateRejectsDecimalDefaultExceedingPrecision) { |
| 175 | + // A decimal default whose unscaled value needs more digits than the field precision has |
| 176 | + // the matching literal type (decimal(2, 1)) but does not fit; Validate must reject it |
| 177 | + // so it is never serialized to metadata the reader would later refuse to parse. |
| 178 | + SchemaField field(/*field_id=*/1, /*name=*/"d", decimal(2, 1), |
| 179 | + /*optional=*/true, /*doc=*/"", |
| 180 | + std::make_shared<const Literal>(Literal::Decimal(999, 2, 1))); |
| 181 | + EXPECT_THAT(field.Validate(), IsError(ErrorKind::kInvalidSchema)); |
| 182 | + EXPECT_THAT(field.Validate(), HasErrorMessage("does not fit precision")); |
| 183 | +} |
| 184 | + |
| 185 | +TEST(SchemaFieldTest, ValidateAcceptsDecimalDefaultWithinPrecision) { |
| 186 | + SchemaField field(/*field_id=*/1, /*name=*/"d", decimal(4, 1), |
| 187 | + /*optional=*/true, /*doc=*/"", |
| 188 | + std::make_shared<const Literal>(Literal::Decimal(999, 4, 1))); |
| 189 | + EXPECT_THAT(field.Validate(), IsOk()); |
| 190 | +} |
| 191 | + |
173 | 192 | } // namespace iceberg |
0 commit comments