-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2569] improvement(trino): Optimize char/varchar mapping for Iceberg…
… catalog between Gravitino and Trino (#2579) ### What changes were proposed in this pull request? Changing the char/varchar conversion for Iceberg catalog between Gravitino and Trino. ### Why are the changes needed? We need to make type conversion more exactly. Fix: #2569 ### Does this PR introduce _any_ user-facing change? N/A. ### How was this patch tested? UT and ITs
- Loading branch information
Showing
7 changed files
with
146 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ion-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00007_varchar.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE SCHEMA "test.gt_iceberg".varchar_db1; | ||
|
||
USE "test.gt_iceberg".varchar_db1; | ||
|
||
CREATE TABLE tb01 (id int, name char(20)); | ||
|
||
CREATE TABLE tb02 (id int, name char); | ||
|
||
CREATE TABLE tb03 (id int, name varchar(233)); | ||
|
||
CREATE TABLE tb04 (id int, name varchar); | ||
|
||
SHOW CREATE TABLE "test.gt_iceberg".varchar_db1.tb04; | ||
|
||
drop table "test.gt_iceberg".varchar_db1.tb04; | ||
|
||
drop schema "test.gt_iceberg".varchar_db1; | ||
|
21 changes: 21 additions & 0 deletions
21
...ion-test/src/test/resources/trino-ci-testset/testsets/lakehouse-iceberg/00007_varchar.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE SCHEMA | ||
|
||
USE | ||
|
||
<QUERY_FAILED> Iceberg does not support the datatype CHAR | ||
|
||
<QUERY_FAILED> Iceberg does not support the datatype CHAR | ||
|
||
<QUERY_FAILED> Iceberg does not support the datatype VARCHAR with length | ||
|
||
CREATE TABLE | ||
|
||
"CREATE TABLE ""test.gt_iceberg"".varchar_db1.tb04 ( | ||
id integer, | ||
name varchar | ||
) | ||
COMMENT ''" | ||
|
||
DROP TABLE | ||
|
||
DROP SCHEMA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../datastrato/gravitino/trino/connector/catalog/iceberg/TestIcebergDataTypeTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
|
||
package com.datastrato.gravitino.trino.connector.catalog.iceberg; | ||
|
||
import com.datastrato.gravitino.rel.types.Types; | ||
import com.datastrato.gravitino.trino.connector.util.GeneralDataTypeTransformer; | ||
import io.trino.spi.TrinoException; | ||
import io.trino.spi.type.VarcharType; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class TestIcebergDataTypeTransformer { | ||
|
||
@Test | ||
public void testTrinoTypeToGravitinoType() { | ||
GeneralDataTypeTransformer generalDataTypeTransformer = new IcebergDataTypeTransformer(); | ||
io.trino.spi.type.Type charTypeWithLengthOne = io.trino.spi.type.CharType.createCharType(1); | ||
|
||
Exception e = | ||
Assert.expectThrows( | ||
TrinoException.class, | ||
() -> generalDataTypeTransformer.getGravitinoType(charTypeWithLengthOne)); | ||
Assert.assertTrue(e.getMessage().contains("Iceberg does not support the datatype CHAR")); | ||
|
||
io.trino.spi.type.Type varcharType = io.trino.spi.type.VarcharType.createVarcharType(1); | ||
e = | ||
Assert.expectThrows( | ||
TrinoException.class, () -> generalDataTypeTransformer.getGravitinoType(varcharType)); | ||
Assert.assertTrue( | ||
e.getMessage().contains("Iceberg does not support the datatype VARCHAR with length")); | ||
|
||
io.trino.spi.type.Type varcharTypeWithoutLength = VarcharType.VARCHAR; | ||
|
||
Assert.assertEquals( | ||
generalDataTypeTransformer.getGravitinoType(varcharTypeWithoutLength), | ||
Types.StringType.get()); | ||
} | ||
} |