World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#2340] improvement(api/catalog/spark/trino): support unsigned type (#3505)
hanwxx05fd4d63ef7a
diff --git a/api/src/main/java/com/datastrato/gravitino/rel/expressions/literals/Literals.java b/api/src/main/java/com/datastrato/gravitino/rel/expressions/literals/Literals.javaindex a1c8e2fd60..9599d0368b 100644--- a/api/src/main/java/com/datastrato/gravitino/rel/expressions/literals/Literals.java+++ b/api/src/main/java/com/datastrato/gravitino/rel/expressions/literals/Literals.java@@ -50,6 +50,16 @@ public class Literals {return of(value, Types.ByteType.get());}+ /**+ * Creates an unsigned byte type literal with the given value.+ *+ * @param value the unsigned byte literal value+ * @return a new {@link Literal} instance+ */+ public static LiteralImpl<Short> unsignedByteLiteral(Short value) {+ return of(value, Types.ByteType.unsigned());+ }+/*** Creates a short type literal with the given value.*@@ -60,6 +70,16 @@ public class Literals {return of(value, Types.ShortType.get());}+ /**+ * Creates an unsigned short type literal with the given value.+ *+ * @param value the unsigned short literal value+ * @return a new {@link Literal} instance+ */+ public static LiteralImpl<Integer> unsignedShortLiteral(Integer value) {+ return of(value, Types.ShortType.unsigned());+ }+/*** Creates an integer type literal with the given value.*@@ -70,6 +90,16 @@ public class Literals {return of(value, Types.IntegerType.get());}+ /**+ * Creates an unsigned integer type literal with the given value.+ *+ * @param value the unsigned integer literal value+ * @return a new {@link Literal} instance+ */+ public static LiteralImpl<Long> unsignedIntegerLiteral(Long value) {+ return of(value, Types.IntegerType.unsigned());+ }+/*** Creates a long type literal with the given value.*@@ -80,6 +110,16 @@ public class Literals {return of(value, Types.LongType.get());}+ /**+ * Creates an unsigned long type literal with the given value.+ *+ * @param value the unsigned long literal value+ * @return a new {@link Literal} instance+ */+ public static LiteralImpl<Decimal> unsignedLongLiteral(Decimal value) {+ return of(value, Types.LongType.unsigned());+ }+/*** Creates a float type literal with the given value.*diff --git a/api/src/main/java/com/datastrato/gravitino/rel/types/Type.java b/api/src/main/java/com/datastrato/gravitino/rel/types/Type.javaindex ede539a871..54bdba19d6 100644--- a/api/src/main/java/com/datastrato/gravitino/rel/types/Type.java+++ b/api/src/main/java/com/datastrato/gravitino/rel/types/Type.java@@ -101,7 +101,19 @@ public interface Type {abstract class ComplexType implements Type {}/** The base type of all integral types. */- abstract class IntegralType extends NumericType {}+ abstract class IntegralType extends NumericType {+ private final boolean signed;++ /** @param signed or unsigned of the integer type. */+ public IntegralType(boolean signed) {+ this.signed = signed;+ }++ /** @return True if the integer type has signed, false otherwise. */+ public boolean signed() {+ return signed;+ }+ }/** The base type of all fractional types. */abstract class FractionType extends NumericType {}diff --git a/api/src/main/java/com/datastrato/gravitino/rel/types/Types.java b/api/src/main/java/com/datastrato/gravitino/rel/types/Types.javaindex 8848f423de..a897fe3a64 100644--- a/api/src/main/java/com/datastrato/gravitino/rel/types/Types.java+++ b/api/src/main/java/com/datastrato/gravitino/rel/types/Types.java@@ -58,14 +58,22 @@ public class Types {/** The byte type in Gravitino. */public static class ByteType extends Type.IntegralType {- private static final ByteType INSTANCE = new ByteType();+ private static final ByteType INSTANCE = new ByteType(true);+ private static final ByteType UNSIGNED_INSTANCE = new ByteType(false);++ /** @return The singleton instance of unsigned byte type */+ public static ByteType unsigned() {+ return UNSIGNED_INSTANCE;+ }/** @return The singleton instance of {@link ByteType}. */public static ByteType get() {return INSTANCE;}- private ByteType() {}+ private ByteType(boolean signed) {+ super(signed);+ }@Overridepublic Name name() {@@ -74,20 +82,28 @@ public class Types {@Overridepublic String simpleString() {- return "byte";+ return signed() ? "byte" : "byte unsigned";}}/** The short type in Gravitino. */public static class ShortType extends Type.IntegralType {- private static final ShortType INSTANCE = new ShortType();+ private static final ShortType INSTANCE = new ShortType(true);+ private static final ShortType UNSIGNED_INSTANCE = new ShortType(false);++ /** @return The singleton instance of unsigned short type */+ public static ShortType unsigned() {+ return UNSIGNED_INSTANCE;+ }/** @return The singleton instance of {@link ShortType}. */public static ShortType get() {return INSTANCE;}- private ShortType() {}+ private ShortType(boolean signed) {+ super(signed);+ }@Overridepublic Name name() {@@ -96,20 +112,28 @@ public class Types {@Overridepublic String simpleString() {- return "short";+ return signed() ? "short" : "short unsigned";}}/** The integer type in Gravitino. */public static class IntegerType extends Type.IntegralType {- private static final IntegerType INSTANCE = new IntegerType();+ private static final IntegerType INSTANCE = new IntegerType(true);+ private static final IntegerType UNSIGNED_INSTANCE = new IntegerType(false);++ /** @return The singleton instance of unsigned integer type */+ public static IntegerType unsigned() {+ return UNSIGNED_INSTANCE;+ }/** @return The singleton instance of {@link IntegerType}. */public static IntegerType get() {return INSTANCE;}- private IntegerType() {}+ private IntegerType(boolean signed) {+ super(signed);+ }@Overridepublic Name name() {@@ -118,20 +142,28 @@ public class Types {@Overridepublic String simpleString() {- return "integer";+ return signed() ? "integer" : "integer unsigned";}}/** The long type in Gravitino. */public static class LongType extends Type.IntegralType {- private static final LongType INSTANCE = new LongType();+ private static final LongType INSTANCE = new LongType(true);+ private static final LongType UNSIGNED_INSTANCE = new LongType(false);++ /** @return The singleton instance of unsigned long type */+ public static LongType unsigned() {+ return UNSIGNED_INSTANCE;+ }/** @return The singleton instance of {@link LongType}. */public static LongType get() {return INSTANCE;}- private LongType() {}+ private LongType(boolean signed) {+ super(signed);+ }@Overridepublic Name name() {@@ -140,7 +172,7 @@ public class Types {@Overridepublic String simpleString() {- return "long";+ return signed() ? "long" : "long unsigned";}}diff --git a/api/src/test/java/com/datastrato/gravitino/rel/TestLiteral.java b/api/src/test/java/com/datastrato/gravitino/rel/TestLiteral.javaindex a9641a8c9a..8c1d3f57e5 100644--- a/api/src/test/java/com/datastrato/gravitino/rel/TestLiteral.java+++ b/api/src/test/java/com/datastrato/gravitino/rel/TestLiteral.java@@ -16,6 +16,10 @@ import static com.datastrato.gravitino.rel.expressions.literals.Literals.shortLiimport static com.datastrato.gravitino.rel.expressions.literals.Literals.stringLiteral;import static com.datastrato.gravitino.rel.expressions.literals.Literals.timeLiteral;import static com.datastrato.gravitino.rel.expressions.literals.Literals.timestampLiteral;+import static com.datastrato.gravitino.rel.expressions.literals.Literals.unsignedByteLiteral;+import static com.datastrato.gravitino.rel.expressions.literals.Literals.unsignedIntegerLiteral;+import static com.datastrato.gravitino.rel.expressions.literals.Literals.unsignedLongLiteral;+import static com.datastrato.gravitino.rel.expressions.literals.Literals.unsignedShortLiteral;import com.datastrato.gravitino.rel.expressions.literals.Literal;import com.datastrato.gravitino.rel.expressions.literals.Literals;@@ -40,18 +44,34 @@ public class TestLiteral {Assertions.assertEquals((byte) 1, literal.value());Assertions.assertEquals(Types.ByteType.get(), literal.dataType());+ literal = unsignedByteLiteral(Short.valueOf("1"));+ Assertions.assertEquals((short) 1, literal.value());+ Assertions.assertEquals(Types.ByteType.unsigned(), literal.dataType());+literal = shortLiteral(Short.valueOf("1"));Assertions.assertEquals((short) 1, literal.value());Assertions.assertEquals(Types.ShortType.get(), literal.dataType());+ literal = unsignedShortLiteral(Integer.valueOf("1"));+ Assertions.assertEquals(1, literal.value());+ Assertions.assertEquals(Types.ShortType.unsigned(), literal.dataType());+literal = integerLiteral(Integer.valueOf("1"));Assertions.assertEquals(1, literal.value());Assertions.assertEquals(Types.IntegerType.get(), literal.dataType());+ literal = unsignedIntegerLiteral(Long.valueOf("1"));+ Assertions.assertEquals(1L, literal.value());+ Assertions.assertEquals(Types.IntegerType.unsigned(), literal.dataType());+literal = longLiteral(Long.valueOf("1"));Assertions.assertEquals(1L, literal.value());Assertions.assertEquals(Types.LongType.get(), literal.dataType());+ literal = unsignedLongLiteral(Decimal.of("1"));+ Assertions.assertEquals(Decimal.of("1"), literal.value());+ Assertions.assertEquals(Types.LongType.unsigned(), literal.dataType());+literal = floatLiteral(Float.valueOf("1.234"));Assertions.assertEquals(1.234f, literal.value());Assertions.assertEquals(Types.FloatType.get(), literal.dataType());diff --git a/api/src/test/java/com/datastrato/gravitino/rel/TestTypes.java b/api/src/test/java/com/datastrato/gravitino/rel/TestTypes.javaindex f623451867..8a8165fdf8 100644--- a/api/src/test/java/com/datastrato/gravitino/rel/TestTypes.java+++ b/api/src/test/java/com/datastrato/gravitino/rel/TestTypes.java@@ -26,24 +26,44 @@ public class TestTypes {Types.ByteType byteType = Types.ByteType.get();Assertions.assertEquals(Type.Name.BYTE, byteType.name());- Assertions.assertSame(byteType, Types.ByteType.get());Assertions.assertEquals("byte", byteType.simpleString());+ Types.ByteType unsignByteType = Types.ByteType.unsigned();+ Assertions.assertEquals(Type.Name.BYTE, unsignByteType.name());+ Assertions.assertFalse(unsignByteType.signed());+ Assertions.assertEquals("byte unsigned", unsignByteType.simpleString());+Types.ShortType shortType = Types.ShortType.get();Assertions.assertEquals(Type.Name.SHORT, shortType.name());Assertions.assertSame(shortType, Types.ShortType.get());Assertions.assertEquals("short", shortType.simpleString());+ Types.ShortType unsignShortType = Types.ShortType.unsigned();+ Assertions.assertEquals(Type.Name.SHORT, unsignShortType.name());+ Assertions.assertFalse(unsignShortType.signed());+ Assertions.assertEquals("short unsigned", unsignShortType.simpleString());+Types.IntegerType integerType = Types.IntegerType.get();Assertions.assertEquals(Type.Name.INTEGER, integerType.name());Assertions.assertSame(integerType, Types.IntegerType.get());Assertions.assertEquals("integer", integerType.simpleString());+ Types.IntegerType unsignIntegerType = Types.IntegerType.unsigned();+ Assertions.assertEquals(Type.Name.INTEGER, unsignIntegerType.name());+ Assertions.assertFalse(unsignIntegerType.signed());+ Assertions.assertEquals("integer unsigned", unsignIntegerType.simpleString());+Types.LongType longType = Types.LongType.get();Assertions.assertEquals(Type.Name.LONG, longType.name());Assertions.assertSame(longType, Types.LongType.get());Assertions.assertEquals("long", longType.simpleString());+ Types.LongType unsignLongType = Types.LongType.unsigned();+ Assertions.assertEquals(Type.Name.LONG, unsignLongType.name());+ Assertions.assertFalse(unsignLongType.signed());+ Assertions.assertNotSame(unsignLongType, Types.LongType.get());+ Assertions.assertEquals("long unsigned", unsignLongType.simpleString());+Types.FloatType floatType = Types.FloatType.get();Assertions.assertEquals(Type.Name.FLOAT, floatType.name());Assertions.assertSame(floatType, Types.FloatType.get());diff --git a/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/converter/MysqlTypeConverter.java b/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/converter/MysqlTypeConverter.javaindex a32550bea9..006f6270e2 100644--- a/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/converter/MysqlTypeConverter.java+++ b/catalogs/catalog-jdbc-mysql/src/main/java/com/datastrato/gravitino/catalog/mysql/converter/MysqlTypeConverter.java@@ -12,9 +12,13 @@ import com.datastrato.gravitino.rel.types.Types;public class MysqlTypeConverter extends JdbcTypeConverter {static final String TINYINT = "tinyint";+ static final String TINYINT_UNSIGNED = "tinyint unsigned";static final String SMALLINT = "smallint";+ static final String SMALLINT_UNSIGNED = "smallint unsigned";static final String INT = "int";+ static final String INT_UNSIGNED = "int unsigned";static final String BIGINT = "bigint";+ static final String BIGINT_UNSIGNED = "bigint unsigned";static final String FLOAT = "float";static final String DOUBLE = "double";static final String DECIMAL = "decimal";@@ -27,12 +31,20 @@ public class MysqlTypeConverter extends JdbcTypeConverter {switch (typeBean.getTypeName().toLowerCase()) {case TINYINT:return Types.ByteType.get();+ case TINYINT_UNSIGNED:+ return Types.ByteType.unsigned();case SMALLINT:return Types.ShortType.get();+ case SMALLINT_UNSIGNED:+ return Types.ShortType.unsigned();case INT:return Types.IntegerType.get();+ case INT_UNSIGNED:+ return Types.IntegerType.unsigned();case BIGINT:return Types.LongType.get();+ case BIGINT_UNSIGNED:+ return Types.LongType.unsigned();case FLOAT:return Types.FloatType.get();case DOUBLE:@@ -68,13 +80,29 @@ public class MysqlTypeConverter extends JdbcTypeConverter {@Overridepublic String fromGravitino(Type type) {if (type instanceof Types.ByteType) {- return TINYINT;+ if (((Types.ByteType) type).signed()) {+ return TINYINT;+ } else {+ return TINYINT_UNSIGNED;+ }} else if (type instanceof Types.ShortType) {- return SMALLINT;+ if (((Types.ShortType) type).signed()) {+ return SMALLINT;+ } else {+ return SMALLINT_UNSIGNED;+ }} else if (type instanceof Types.IntegerType) {- return INT;+ if (((Types.IntegerType) type).signed()) {+ return INT;+ } else {+ return INT_UNSIGNED;+ }} else if (type instanceof Types.LongType) {- return BIGINT;+ if (((Types.LongType) type).signed()) {+ return BIGINT;+ } else {+ return BIGINT_UNSIGNED;+ }} else if (type instanceof Types.FloatType) {return type.simpleString();} else if (type instanceof Types.DoubleType) {diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.javaindex ba722cc462..e12382ba80 100644--- a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java+++ b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java@@ -1644,4 +1644,49 @@ public class CatalogMysqlIT extends AbstractIT {Indexes.EMPTY_INDEXES,table);}++ @Test+ public void testMySqlIntegerTypes() {+ Column col1 = Column.of("col_1", Types.ByteType.get(), "byte type", true, false, null);+ Column col2 =+ Column.of("col_2", Types.ByteType.unsigned(), "byte unsigned type", true, false, null);+ Column col3 = Column.of("col_3", Types.ShortType.get(), "short type", true, false, null);+ Column col4 =+ Column.of("col_4", Types.ShortType.unsigned(), "short unsigned type ", true, false, null);+ Column col5 = Column.of("col_5", Types.IntegerType.get(), "integer type", true, false, null);+ Column col6 =+ Column.of(+ "col_6", Types.IntegerType.unsigned(), "integer unsigned type", true, false, null);+ Column col7 = Column.of("col_7", Types.LongType.get(), "long type", true, false, null);+ Column col8 =+ Column.of("col_8", Types.LongType.unsigned(), "long unsigned type", true, false, null);+ String tableName = "default_integer_types_table";+ Column[] newColumns = new Column[] {col1, col2, col3, col4, col5, col6, col7, col8};++ NameIdentifier tableIdentifier =+ NameIdentifier.of(metalakeName, catalogName, schemaName, tableName);+ Map<String, String> properties = createProperties();+ TableCatalog tableCatalog = catalog.asTableCatalog();+ tableCatalog.createTable(+ tableIdentifier,+ newColumns,+ table_comment,+ properties,+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ new SortOrder[0],+ Indexes.EMPTY_INDEXES);++ Table table = tableCatalog.loadTable(tableIdentifier);+ Assertions.assertEquals(8, table.columns().length);+ Column[] columns = table.columns();+ Assertions.assertEquals(columns[0].dataType().simpleString(), "byte");+ Assertions.assertEquals(columns[1].dataType().simpleString(), "byte unsigned");+ Assertions.assertEquals(columns[2].dataType().simpleString(), "short");+ Assertions.assertEquals(columns[3].dataType().simpleString(), "short unsigned");+ Assertions.assertEquals(columns[4].dataType().simpleString(), "integer");+ Assertions.assertEquals(columns[5].dataType().simpleString(), "integer unsigned");+ Assertions.assertEquals(columns[6].dataType().simpleString(), "long");+ Assertions.assertEquals(columns[7].dataType().simpleString(), "long unsigned");+ }}diff --git a/common/src/main/java/com/datastrato/gravitino/json/JsonUtils.java b/common/src/main/java/com/datastrato/gravitino/json/JsonUtils.javaindex 9799eb5088..bf7a64fde6 100644--- a/common/src/main/java/com/datastrato/gravitino/json/JsonUtils.java+++ b/common/src/main/java/com/datastrato/gravitino/json/JsonUtils.java@@ -129,9 +129,13 @@ public class JsonUtils {ImmutableList.of(Types.BooleanType.get(),Types.ByteType.get(),+ Types.ByteType.unsigned(),Types.ShortType.get(),+ Types.ShortType.unsigned(),Types.IntegerType.get(),+ Types.IntegerType.unsigned(),Types.LongType.get(),+ Types.LongType.unsigned(),Types.FloatType.get(),Types.DoubleType.get(),Types.DateType.get(),diff --git a/docs/jdbc-mysql-catalog.md b/docs/jdbc-mysql-catalog.mdindex 8d7f34ab33..88b131bc54 100644--- a/docs/jdbc-mysql-catalog.md+++ b/docs/jdbc-mysql-catalog.md@@ -87,22 +87,26 @@ Refer to [Manage Relational Metadata Using Gravitino](./manage-relational-metada#### Table column types-| Gravitino Type | MySQL Type |-|------------------|-------------|-| `Byte` | `Tinyint` |-| `Short` | `Smallint` |-| `Integer` | `Int` |-| `Long` | `Bigint` |-| `Float` | `Float` |-| `Double` | `Double` |-| `String` | `Text` |-| `Date` | `Date` |-| `Time` | `Time` |-| `Timestamp` | `Timestamp` |-| `Decimal` | `Decimal` |-| `VarChar` | `VarChar` |-| `FixedChar` | `FixedChar` |-| `Binary` | `Binary` |+| Gravitino Type | MySQL Type |+|------------------|---------------------|+| `Byte` | `Tinyint` |+| `Byte(false)` | `Tinyint Unsigned` |+| `Short` | `Smallint` |+| `Short(false)` | `Smallint Unsigned` |+| `Integer` | `Int` |+| `Integer(false)` | `Int Unsigned` |+| `Long` | `Bigint` |+| `Long(false)` | `Bigint Unsigned` |+| `Float` | `Float` |+| `Double` | `Double` |+| `String` | `Text` |+| `Date` | `Date` |+| `Time` | `Time` |+| `Timestamp` | `Timestamp` |+| `Decimal` | `Decimal` |+| `VarChar` | `VarChar` |+| `FixedChar` | `FixedChar` |+| `Binary` | `Binary` |:::infoMySQL doesn't support Gravitino `Boolean` `Fixed` `Struct` `List` `Map` `Timestamp_tz` `IntervalDay` `IntervalYear` `Union` `UUID` type.diff --git a/docs/manage-relational-metadata-using-gravitino.md b/docs/manage-relational-metadata-using-gravitino.mdindex 7b0e9c46f2..98b7ada4f5 100644--- a/docs/manage-relational-metadata-using-gravitino.md+++ b/docs/manage-relational-metadata-using-gravitino.md@@ -696,31 +696,35 @@ 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 |-| Short | `Types.ShortType.get()` | `short` | Short type, indicates a numerical value of 2 bytes |-| Integer | `Types.IntegerType.get()` | `integer` | Integer type, indicates a numerical value of 4 bytes |-| Long | `Types.LongType.get()` | `long` | Long type, indicates a 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 |+| 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 |The related java doc is [here](pathname:///docs/0.5.1/api/java/com/datastrato/gravitino/rel/types/Type.html).diff --git a/docs/open-api/datatype.yaml b/docs/open-api/datatype.yamlindex d1d0cd933a..d3983f4b68 100644--- a/docs/open-api/datatype.yaml+++ b/docs/open-api/datatype.yaml@@ -21,9 +21,13 @@ components:example:- "boolean"- "byte"+ - "byte unsigned"- "short"+ - "short unsigned"- "integer"+ - "integer unsigned"- "long"+ - "long unsigned"- "float"- "double"- "decimal(10,2)"diff --git a/spark-connector/spark-common/src/main/java/com/datastrato/gravitino/spark/connector/SparkTypeConverter.java b/spark-connector/spark-common/src/main/java/com/datastrato/gravitino/spark/connector/SparkTypeConverter.javaindex 40c0e1fe24..0e79ca7946 100644--- a/spark-connector/spark-common/src/main/java/com/datastrato/gravitino/spark/connector/SparkTypeConverter.java+++ b/spark-connector/spark-common/src/main/java/com/datastrato/gravitino/spark/connector/SparkTypeConverter.java@@ -97,13 +97,29 @@ public class SparkTypeConverter {public DataType toSparkType(Type gravitinoType) {if (gravitinoType instanceof Types.ByteType) {- return DataTypes.ByteType;+ if (((Types.ByteType) gravitinoType).signed()) {+ return DataTypes.ByteType;+ } else {+ return DataTypes.ShortType;+ }} else if (gravitinoType instanceof Types.ShortType) {- return DataTypes.ShortType;+ if (((Types.ShortType) gravitinoType).signed()) {+ return DataTypes.ShortType;+ } else {+ return DataTypes.IntegerType;+ }} else if (gravitinoType instanceof Types.IntegerType) {- return DataTypes.IntegerType;+ if (((Types.IntegerType) gravitinoType).signed()) {+ return DataTypes.IntegerType;+ } else {+ return DataTypes.LongType;+ }} else if (gravitinoType instanceof Types.LongType) {- return DataTypes.LongType;+ if (((Types.LongType) gravitinoType).signed()) {+ return DataTypes.LongType;+ } else {+ return DataTypes.createDecimalType(20, 0);+ }} else if (gravitinoType instanceof Types.FloatType) {return DataTypes.FloatType;} else if (gravitinoType instanceof Types.DoubleType) {diff --git a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/util/GeneralDataTypeTransformer.java b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/util/GeneralDataTypeTransformer.javaindex 888c1fd81b..0f5788f237 100644--- a/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/util/GeneralDataTypeTransformer.java+++ b/trino-connector/src/main/java/com/datastrato/gravitino/trino/connector/util/GeneralDataTypeTransformer.java@@ -46,13 +46,29 @@ public class GeneralDataTypeTransformer {case BOOLEAN:return BOOLEAN;case BYTE:- return TinyintType.TINYINT;+ if (((Types.ByteType) type).signed()) {+ return TinyintType.TINYINT;+ } else {+ return SmallintType.SMALLINT;+ }case SHORT:- return SmallintType.SMALLINT;+ if (((Types.ShortType) type).signed()) {+ return SmallintType.SMALLINT;+ } else {+ return INTEGER;+ }case INTEGER:- return INTEGER;+ if (((Types.IntegerType) type).signed()) {+ return INTEGER;+ } else {+ return BIGINT;+ }case LONG:- return BIGINT;+ if (((Types.LongType) type).signed()) {+ return BIGINT;+ } else {+ return io.trino.spi.type.DecimalType.createDecimalType(20, 0);+ }case FLOAT:return RealType.REAL;case DOUBLE:diff --git a/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/catalog/jdbc/mysql/TestMySQLDataTypeTransformer.java b/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/catalog/jdbc/mysql/TestMySQLDataTypeTransformer.javaindex 7e45850908..2e7a418611 100644--- a/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/catalog/jdbc/mysql/TestMySQLDataTypeTransformer.java+++ b/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/catalog/jdbc/mysql/TestMySQLDataTypeTransformer.java@@ -62,4 +62,28 @@ public class TestMySQLDataTypeTransformer {generalDataTypeTransformer.getTrinoType(stringType),io.trino.spi.type.VarcharType.createUnboundedVarcharType());}++ @Test+ public void testGravitinoIntegerToTrinoType() {+ GeneralDataTypeTransformer generalDataTypeTransformer = new MySQLDataTypeTransformer();++ Type integerType = Types.IntegerType.get();+ Assertions.assertEquals(+ generalDataTypeTransformer.getTrinoType(integerType),+ io.trino.spi.type.IntegerType.INTEGER);++ Type unsignedIntegerType = Types.IntegerType.unsigned();+ Assertions.assertEquals(+ generalDataTypeTransformer.getTrinoType(unsignedIntegerType),+ io.trino.spi.type.BigintType.BIGINT);++ Type bigintType = Types.LongType.get();+ Assertions.assertEquals(+ generalDataTypeTransformer.getTrinoType(bigintType), io.trino.spi.type.BigintType.BIGINT);++ Type unsignBigintType = Types.LongType.unsigned();+ Assertions.assertEquals(+ generalDataTypeTransformer.getTrinoType(unsignBigintType),+ io.trino.spi.type.DecimalType.createDecimalType(20, 0));+ }}diff --git a/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/util/TestDataTypeTransformer.java b/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/util/TestDataTypeTransformer.javaindex 319846dfb7..7c198ddcc1 100644--- a/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/util/TestDataTypeTransformer.java+++ b/trino-connector/src/test/java/com/datastrato/gravitino/trino/connector/util/TestDataTypeTransformer.java@@ -129,6 +129,16 @@ public class TestDataTypeTransformer {dataTypeTransformer.getTrinoType(Types.DecimalType.of(10, 2)),DecimalType.createDecimalType(10, 2));+ Assertions.assertEquals(+ dataTypeTransformer.getTrinoType(Types.ByteType.unsigned()), SmallintType.SMALLINT);+ Assertions.assertEquals(+ dataTypeTransformer.getTrinoType(Types.ShortType.unsigned()), IntegerType.INTEGER);+ Assertions.assertEquals(+ dataTypeTransformer.getTrinoType(Types.IntegerType.unsigned()), BigintType.BIGINT);+ Assertions.assertEquals(+ dataTypeTransformer.getTrinoType(Types.LongType.unsigned()),+ DecimalType.createDecimalType(20, 0));+Assertions.assertEquals(dataTypeTransformer.getTrinoType(Types.FixedCharType.of(10)), CharType.createCharType(10));Assertions.assertEquals(