Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5659] improvement(catalog-mysql) : support load MySQL BOOLEAN data in Trino #5773

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/** Type converter for MySQL. */
public class MysqlTypeConverter extends JdbcTypeConverter {

static final String BIT = "bit";
static final String TINYINT = "tinyint";
static final String TINYINT_UNSIGNED = "tinyint unsigned";
static final String SMALLINT = "smallint";
Expand All @@ -43,6 +44,11 @@ public class MysqlTypeConverter extends JdbcTypeConverter {
@Override
public Type toGravitino(JdbcTypeBean typeBean) {
switch (typeBean.getTypeName().toLowerCase()) {
case BIT:
if (typeBean.getColumnSize() == null || typeBean.getColumnSize() == 1) {
return Types.BooleanType.get();
}
return Types.BinaryType.get();
case TINYINT:
return Types.ByteType.get();
case TINYINT_UNSIGNED:
Expand Down Expand Up @@ -139,6 +145,8 @@ public String fromGravitino(Type type) {
return type.simpleString();
} else if (type instanceof Types.BinaryType) {
return type.simpleString();
} else if (type instanceof Types.BooleanType) {
return BIT;
} else if (type instanceof Types.ExternalType) {
return ((Types.ExternalType) type).catalogString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ void testColumnTypeConverter() {
+ " varchar20_col varchar(20),\n"
+ " text_col text,\n"
+ " binary_col binary,\n"
+ " blob_col blob\n"
+ " blob_col blob,\n"
+ " bit_col_8 bit(8),\n"
+ " bit_col bit\n"
+ ");\n";

mysqlService.executeQuery(sql);
Expand Down Expand Up @@ -694,6 +696,12 @@ void testColumnTypeConverter() {
case "binary_col":
Assertions.assertEquals(Types.BinaryType.get(), column.dataType());
break;
case "bit_col_8":
Assertions.assertEquals(Types.BinaryType.get(), column.dataType());
break;
case "bit_col":
Assertions.assertEquals(Types.BooleanType.get(), column.dataType());
break;
case "blob_col":
Assertions.assertEquals(Types.ExternalType.of("BLOB"), column.dataType());
break;
Expand Down Expand Up @@ -1691,13 +1699,13 @@ void testMySQLSchemaNameCaseSensitive() {
}

@Test
void testUnparsedTypeConverter() {
void testParsedBitTypeConverter() {
String tableName = GravitinoITUtils.genRandomName("test_unparsed_type");
mysqlService.executeQuery(
String.format("CREATE TABLE %s.%s (bit_col bit);", schemaName, tableName));
Table loadedTable =
catalog.asTableCatalog().loadTable(NameIdentifier.of(schemaName, tableName));
Assertions.assertEquals(Types.ExternalType.of("BIT"), loadedTable.columns()[0].dataType());
Assertions.assertEquals(Types.BooleanType.get(), loadedTable.columns()[0].dataType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ public void testCreateNotSupportTypeTable() {
List<JdbcColumn> columns = new ArrayList<>();
List<Type> notSupportType =
Arrays.asList(
Types.BooleanType.get(),
Types.FixedType.of(10),
Types.IntervalDayType.get(),
Types.IntervalYearType.get(),
Expand Down
3 changes: 2 additions & 1 deletion docs/jdbc-mysql-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ Refer to [Manage Relational Metadata Using Gravitino](./manage-relational-metada
| `VarChar` | `VarChar` |
| `FixedChar` | `FixedChar` |
| `Binary` | `Binary` |
| `BOOLEAN` | `BIT` |

:::info
MySQL doesn't support Gravitino `Boolean` `Fixed` `Struct` `List` `Map` `Timestamp_tz` `IntervalDay` `IntervalYear` `Union` `UUID` type.
MySQL doesn't support Gravitino `Fixed` `Struct` `List` `Map` `Timestamp_tz` `IntervalDay` `IntervalYear` `Union` `UUID` type.
Meanwhile, the data types other than listed above are mapped to Gravitino **[External Type](./manage-relational-metadata-using-gravitino.md#external-type)** that represents an unresolvable data type since 0.6.0-incubating.
:::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ CREATE SCHEMA gt_mysql.gt_db1;

USE gt_mysql.gt_db1;

-- Unsupported Type: BOOLEAN
CREATE TABLE tb01 (
f1 VARCHAR(200),
f2 CHAR(20),
f3 VARBINARY,
f4 DECIMAL(10, 3),
f5 REAL,
f6 DOUBLE,
f7 BOOLEAN,
f8 TINYINT,
f9 SMALLINT,
f10 INT,
Expand All @@ -23,12 +23,12 @@ CREATE TABLE tb01 (

SHOW CREATE TABLE tb01;

INSERT INTO tb01 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'Text1', x'65', 123.456, 7.89, 12.34, 1, 100, 1000, 1000, 100000, DATE '2024-01-01',
INSERT INTO tb01 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'Text1', x'65', 123.456, 7.89, 12.34, FALSE, 1, 100, 1000, 1000, 100000, DATE '2024-01-01',
TIME '08:00:00', TIMESTAMP '2024-01-01 08:00:00', TIMESTAMP '2024-01-01 08:00:00 UTC');

INSERT INTO tb01 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULl);
INSERT INTO tb01 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULl, NULl);

select * from tb01 order by f1;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tb2 need to update too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tb2 need to update too

fixed

Expand All @@ -39,6 +39,7 @@ CREATE TABLE tb02 (
f4 DECIMAL(10, 3) NOT NULL ,
f5 REAL NOT NULL ,
f6 DOUBLE NOT NULL ,
f7 BOOLEAN NOT NULL ,
f8 TINYINT NOT NULL ,
f9 SMALLINT NOT NULL ,
f10 INT NOT NULL ,
Expand All @@ -52,23 +53,23 @@ CREATE TABLE tb02 (

show create table tb02;

INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'Text1', x'65', 123.456, 7.89, 12.34, 1, 100, 1000, 1000, 100000, DATE '2024-01-01',
INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'Text1', x'65', 123.456, 7.89, 12.34, FALSE, 1, 100, 1000, 1000, 100000, DATE '2024-01-01',
TIME '08:00:00', TIMESTAMP '2024-01-01 08:00:00', TIMESTAMP '2024-01-01 08:00:00 UTC');

INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', NULL, x'65', 123.456, 7.89, 12.34, 1, 100, 1000, 1000, 100000, DATE '2024-01-01',
INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', NULL, x'65', 123.456, 7.89, 12.34, FALSE, 1, 100, 1000, 1000, 100000, DATE '2024-01-01',
TIME '08:00:00', TIMESTAMP '2024-01-01 08:00:00', TIMESTAMP '2024-01-01 08:00:00 UTC');

INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'same3', x'65', 123.456, 7.89, 12.34, 1, 100, 1000, 1000, NULl, DATE '2024-01-01',
INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'same3', x'65', 123.456, 7.89, 12.34, FALSE, 1, 100, 1000, 1000, NULl, DATE '2024-01-01',
TIME '08:00:00', TIMESTAMP '2024-01-01 08:00:00', TIMESTAMP '2024-01-01 08:00:00 UTC');

INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'same9', x'65', 123.456, 7.89, 12.34, 1, 100, 1000, 1000, 1992382342, DATE '2024-01-01',
INSERT INTO tb02 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16)
VALUES ('Sample text 1', 'same9', x'65', 123.456, 7.89, 12.34, FALSE, 1, 100, 1000, 1000, 1992382342, DATE '2024-01-01',
NULL, TIMESTAMP '2024-01-01 08:00:00', TIMESTAMP '2024-01-01 08:00:00 UTC');

drop table tb01;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CREATE TABLE
f4 decimal(10, 3),
f5 real,
f6 double,
f7 boolean,
f8 tinyint,
f9 smallint,
f10 integer,
Expand All @@ -30,8 +31,8 @@ INSERT: 1 row

INSERT: 1 row

"Sample text 1","Text1 ","65","123.456","7.89","12.34","1","100","1000","1000","100000","2024-01-01","08:00:00","2024-01-01 08:00:00","2024-01-01 08:00:00 UTC"
"","","","","","","","","","","","","","",""
"Sample text 1","Text1 ","65","123.456","7.89","12.34","false","1","100","1000","1000","100000","2024-01-01","08:00:00","2024-01-01 08:00:00","2024-01-01 08:00:00 UTC"
"","","","","","","","","","","","","","","",""

CREATE TABLE

Expand All @@ -42,6 +43,7 @@ CREATE TABLE
f4 decimal(10, 3) NOT NULL,
f5 real NOT NULL,
f6 double NOT NULL,
f7 boolean NOT NULL,
f8 tinyint NOT NULL,
f9 smallint NOT NULL,
f10 integer NOT NULL,
Expand Down
Loading