World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#4115] feat(api): add validate check for decimal(0,0) (#4375)
FANNGb323ad6ef665
diff --git a/api/src/main/java/org/apache/gravitino/rel/types/Types.java b/api/src/main/java/org/apache/gravitino/rel/types/Types.javaindex 2355f7ebfe..f0e9a20569 100644--- a/api/src/main/java/org/apache/gravitino/rel/types/Types.java+++ b/api/src/main/java/org/apache/gravitino/rel/types/Types.java@@ -256,11 +256,14 @@ public class Types {static void checkPrecisionScale(int precision, int scale) {Preconditions.checkArgument(- precision <= 38,- "Decimals with precision larger than 38 are not supported: %s",+ precision > 0 && precision <= 38,+ "Decimal precision must be in range[1, 38]: precision: %s",precision);Preconditions.checkArgument(- scale <= precision, "Scale cannot be larger than precision: %s > %s", scale, precision);+ scale >= 0 && scale <= precision,+ "Decimal scale must be in range [0, precision (%s)]: scala: %s",+ precision,+ scale);}/** @return The name of the decimal type. */diff --git a/api/src/test/java/org/apache/gravitino/rel/TestTypes.java b/api/src/test/java/org/apache/gravitino/rel/TestTypes.javaindex e1a52c5c87..1de911f93f 100644--- a/api/src/test/java/org/apache/gravitino/rel/TestTypes.java+++ b/api/src/test/java/org/apache/gravitino/rel/TestTypes.java@@ -91,13 +91,17 @@ public class TestTypes {IllegalArgumentException exception =Assertions.assertThrows(IllegalArgumentException.class, () -> Types.DecimalType.of(40, 0));Assertions.assertTrue(- exception- .getMessage()- .contains("Decimals with precision larger than 38 are not supported"));+ exception.getMessage().contains("Decimal precision must be in range[1, 38]:"));exception =- Assertions.assertThrows(IllegalArgumentException.class, () -> Types.DecimalType.of(0, 40));- Assertions.assertTrue(exception.getMessage().contains("Scale cannot be larger than precision"));+ Assertions.assertThrows(IllegalArgumentException.class, () -> Types.DecimalType.of(1, 40));+ Assertions.assertTrue(+ exception.getMessage().contains("Decimal scale must be in range [0, precision (1)]:"));++ exception =+ Assertions.assertThrows(IllegalArgumentException.class, () -> Types.DecimalType.of(0, 0));+ Assertions.assertTrue(+ exception.getMessage().contains("Decimal precision must be in range[1, 38]:"));Types.DecimalType decimalType = Types.DecimalType.of(26, 10);Assertions.assertEquals(Type.Name.DECIMAL, decimalType.name());diff --git a/docs/manage-relational-metadata-using-gravitino.md b/docs/manage-relational-metadata-using-gravitino.mdindex 55984bf72e..8e06fa142d 100644--- a/docs/manage-relational-metadata-using-gravitino.md+++ b/docs/manage-relational-metadata-using-gravitino.md@@ -703,36 +703,36 @@ In order to create a table, you need to provide the following information:The following types that Gravitino supports:-| Type | Java | JSON | Description |-|----------------------------|--------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|-| Boolean | `Types.BooleanType.get()` | `boolean` | Boolean type |-| Byte | `Types.ByteType.get()` | `byte` | Byte type, indicates a numerical value of 1 byte |-| Byte(false) | `Types.ByteType.unsigned()` | `byte unsigned` | Unsigned Byte type, indicates a unsigned numerical value of 1 byte |-| Short | `Types.ShortType.get()` | `short` | Short type, indicates a numerical value of 2 bytes |-| Short(false) | `Types.ShortType.unsigned()` | `short unsigned` | Unsigned Short type, indicates a unsigned numerical value of 2 bytes |-| Integer | `Types.IntegerType.get()` | `integer` | Integer type, indicates a numerical value of 4 bytes |-| Integer(false) | `Types.IntegerType.unsigned()` | `integer unsigned` | Unsigned Integer type, indicates a unsigned numerical value of 4 bytes |-| Long | `Types.LongType.get()` | `long` | Long type, indicates a numerical value of 8 bytes |-| Long(false) | `Types.LongType.unsigned()` | `long unsigned` | Unsigned Long type, indicates a unsigned numerical value of 8 bytes |-| Float | `Types.FloatType.get()` | `float` | Float type, indicates a single-precision floating point number |-| Double | `Types.DoubleType.get()` | `double` | Double type, indicates a double-precision floating point number |-| Decimal(precision, scale) | `Types.DecimalType.of(precision, scale)` | `decimal(p, s)` | Decimal type, indicates a fixed-precision decimal number |-| String | `Types.StringType.get()` | `string` | String type |-| FixedChar(length) | `Types.FixedCharType.of(length)` | `char(l)` | Char type, indicates a fixed-length string |-| VarChar(length) | `Types.VarCharType.of(length)` | `varchar(l)` | Varchar type, indicates a variable-length string, the length is the maximum length of the string |-| Timestamp | `Types.TimestampType.withoutTimeZone()` | `timestamp` | Timestamp type, indicates a timestamp without timezone |-| TimestampWithTimezone | `Types.TimestampType.withTimeZone()` | `timestamp_tz` | Timestamp with timezone type, indicates a timestamp with timezone |-| Date | `Types.DateType.get()` | `date` | Date type |-| Time | `Types.TimeType.withoutTimeZone()` | `time` | Time type |-| IntervalToYearMonth | `Types.IntervalYearType.get()` | `interval_year` | Interval type, indicates an interval of year and month |-| IntervalToDayTime | `Types.IntervalDayType.get()` | `interval_day` | Interval type, indicates an interval of day and time |-| Fixed(length) | `Types.FixedType.of(length)` | `fixed(l)` | Fixed type, indicates a fixed-length binary array |-| Binary | `Types.BinaryType.get()` | `binary` | Binary type, indicates a arbitrary-length binary array |-| List | `Types.ListType.of(elementType, elementNullable)` | `{"type": "list", "containsNull": JSON Boolean, "elementType": type JSON}` | List type, indicate a list of elements with the same type |-| Map | `Types.MapType.of(keyType, valueType)` | `{"type": "map", "keyType": type JSON, "valueType": type JSON, "valueContainsNull": JSON Boolean}` | Map type, indicate a map of key-value pairs |-| Struct | `Types.StructType.of([Types.StructType.Field.of(name, type, nullable)])` | `{"type": "struct", "fields": [JSON StructField, {"name": string, "type": type JSON, "nullable": JSON Boolean, "comment": string}]}` | Struct type, indicate a struct of fields |-| Union | `Types.UnionType.of([type1, type2, ...])` | `{"type": "union", "types": [type JSON, ...]}` | Union type, indicates a union of types |-| UUID | `Types.UUIDType.get()` | `uuid` | UUID type, indicates a universally unique identifier |+| Type | Java | JSON | Description |+|---------------------------|--------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|+| Boolean | `Types.BooleanType.get()` | `boolean` | Boolean type |+| Byte | `Types.ByteType.get()` | `byte` | Byte type, indicates a numerical value of 1 byte |+| Byte(false) | `Types.ByteType.unsigned()` | `byte unsigned` | Unsigned Byte type, indicates a unsigned numerical value of 1 byte |+| Short | `Types.ShortType.get()` | `short` | Short type, indicates a numerical value of 2 bytes |+| Short(false) | `Types.ShortType.unsigned()` | `short unsigned` | Unsigned Short type, indicates a unsigned numerical value of 2 bytes |+| Integer | `Types.IntegerType.get()` | `integer` | Integer type, indicates a numerical value of 4 bytes |+| Integer(false) | `Types.IntegerType.unsigned()` | `integer unsigned` | Unsigned Integer type, indicates a unsigned numerical value of 4 bytes |+| Long | `Types.LongType.get()` | `long` | Long type, indicates a numerical value of 8 bytes |+| Long(false) | `Types.LongType.unsigned()` | `long unsigned` | Unsigned Long type, indicates a unsigned numerical value of 8 bytes |+| Float | `Types.FloatType.get()` | `float` | Float type, indicates a single-precision floating point number |+| Double | `Types.DoubleType.get()` | `double` | Double type, indicates a double-precision floating point number |+| Decimal(precision, scale) | `Types.DecimalType.of(precision, scale)` | `decimal(p, s)` | Decimal type, indicates a fixed-precision decimal number with the constraint that the precision must be in range `[1, 38]` and the scala must be in range `[0, precision]` |+| String | `Types.StringType.get()` | `string` | String type |+| FixedChar(length) | `Types.FixedCharType.of(length)` | `char(l)` | Char type, indicates a fixed-length string |+| VarChar(length) | `Types.VarCharType.of(length)` | `varchar(l)` | Varchar type, indicates a variable-length string, the length is the maximum length of the string |+| Timestamp | `Types.TimestampType.withoutTimeZone()` | `timestamp` | Timestamp type, indicates a timestamp without timezone |+| TimestampWithTimezone | `Types.TimestampType.withTimeZone()` | `timestamp_tz` | Timestamp with timezone type, indicates a timestamp with timezone |+| Date | `Types.DateType.get()` | `date` | Date type |+| Time | `Types.TimeType.withoutTimeZone()` | `time` | Time type |+| IntervalToYearMonth | `Types.IntervalYearType.get()` | `interval_year` | Interval type, indicates an interval of year and month |+| IntervalToDayTime | `Types.IntervalDayType.get()` | `interval_day` | Interval type, indicates an interval of day and time |+| Fixed(length) | `Types.FixedType.of(length)` | `fixed(l)` | Fixed type, indicates a fixed-length binary array |+| Binary | `Types.BinaryType.get()` | `binary` | Binary type, indicates a arbitrary-length binary array |+| List | `Types.ListType.of(elementType, elementNullable)` | `{"type": "list", "containsNull": JSON Boolean, "elementType": type JSON}` | List type, indicate a list of elements with the same type |+| Map | `Types.MapType.of(keyType, valueType)` | `{"type": "map", "keyType": type JSON, "valueType": type JSON, "valueContainsNull": JSON Boolean}` | Map type, indicate a map of key-value pairs |+| Struct | `Types.StructType.of([Types.StructType.Field.of(name, type, nullable)])` | `{"type": "struct", "fields": [JSON StructField, {"name": string, "type": type JSON, "nullable": JSON Boolean, "comment": string}]}` | Struct type, indicate a struct of fields |+| Union | `Types.UnionType.of([type1, type2, ...])` | `{"type": "union", "types": [type JSON, ...]}` | Union type, indicates a union of types |+| UUID | `Types.UUIDType.get()` | `uuid` | UUID type, indicates a universally unique identifier |The related java doc is [here](pathname:///docs/0.5.1/api/java/org/apache/gravitino/rel/types/Type.html).