Skip to content

Commit

Permalink
[apache#1099] fix(trino-connector) Fix Trino doesn't support to creat…
Browse files Browse the repository at this point in the history
…e Apache Iceberg table with the location (apache#1739)

### What changes were proposed in this pull request?

Fix Trino doesn't support to create Apache Iceberg table with the
location

### Why are the changes needed?

Fix: apache#1099 

### Does this PR introduce _any_ user-facing change?

NO

### How was this patch tested?

Add a test cases

---------

Co-authored-by: Qi Yu <yuqi@datastrato.com>
  • Loading branch information
2 people authored and ch3yne committed Jan 29, 2024
1 parent 975fced commit ee8d4a7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package com.datastrato.gravitino.catalog.lakehouse.iceberg;

import static com.datastrato.gravitino.catalog.PropertyEntry.stringImmutablePropertyEntry;
import static com.datastrato.gravitino.catalog.PropertyEntry.stringReservedPropertyEntry;

import com.datastrato.gravitino.catalog.BasePropertiesMetadata;
Expand Down Expand Up @@ -32,7 +33,8 @@ public class IcebergTablePropertiesMetadata extends BasePropertiesMetadata {
ImmutableList.of(
stringReservedPropertyEntry(COMMENT, "The table comment", true),
stringReservedPropertyEntry(CREATOR, "The table creator", false),
stringReservedPropertyEntry(LOCATION, "Iceberg location for table storage", false),
stringImmutablePropertyEntry(
LOCATION, "Iceberg location for table storage", false, null, false, false),
stringReservedPropertyEntry(
CURRENT_SNAPSHOT_ID,
"The snapshot represents the current state of the table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ public void testTableProperty() {
Map<String, String> map = Maps.newHashMap();
map.put(IcebergTablePropertiesMetadata.COMMENT, "test");
map.put(IcebergTablePropertiesMetadata.CREATOR, "test");
map.put(IcebergTablePropertiesMetadata.LOCATION, "test");
map.put(IcebergTablePropertiesMetadata.CURRENT_SNAPSHOT_ID, "test");
map.put(IcebergTablePropertiesMetadata.CHERRY_PICK_SNAPSHOT_ID, "test");
map.put(IcebergTablePropertiesMetadata.SORT_ORDER, "test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ CREATE TABLE "test.gt_iceberg".gt_db2.tb05 (

show create table "test.gt_iceberg".gt_db2.tb05;

CREATE TABLE "test.gt_iceberg".gt_db2.tb06 (
name varchar,
salary int
) with (
location = '${hdfs_uri}/user/iceberg/warehouse/TrinoQueryIT/gt_iceberg/gt_db2/tb06'
);

show create table "test.gt_iceberg".gt_db2.tb06;

drop table "test.gt_iceberg".gt_db2.tb01;

drop table "test.gt_iceberg".gt_db2.tb02;
Expand All @@ -64,4 +73,6 @@ drop table "test.gt_iceberg".gt_db2.tb04;

drop table "test.gt_iceberg".gt_db2.tb05;

drop table "test.gt_iceberg".gt_db2.tb06;

drop schema "test.gt_iceberg".gt_db2;
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ WITH (
partitioning = ARRAY['name']
)"

CREATE TABLE

"CREATE TABLE ""test.gt_iceberg"".gt_db2.tb06 (
name varchar,
salary integer
)
COMMENT ''
WITH (
location = 'hdfs://%/user/iceberg/warehouse/TrinoQueryIT/gt_iceberg/gt_db2/tb06'
)"

DROP TABLE

DROP TABLE

DROP TABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class IcebergPropertyMeta implements HasPropertyMeta {

public static final String ICEBERG_PARTITIONING_PROPERTY = "partitioning";
public static final String ICEBERG_SORTED_BY_PROPERTY = "sorted_by";
public static final String ICEBERG_LOCATION_PROPERTY = "location";

// Value is whether this property is reserved and cannot be used by users
// TODO (yuqi) add more properties
Expand All @@ -44,7 +45,9 @@ public class IcebergPropertyMeta implements HasPropertyMeta {
ImmutableList.of(),
false,
value -> (List<?>) value,
value -> value));
value -> value),
PropertyMetadata.stringProperty(
ICEBERG_LOCATION_PROPERTY, "Location for table storage", null, false));

// TODO (yuqi) add more properties
public static final Map<PropertyMetadata<?>, Boolean> SCHEMA_PROPERTY_TO_RESERVED_MAP =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package com.datastrato.gravitino.trino.connector.catalog.iceberg;

import static com.datastrato.gravitino.catalog.lakehouse.iceberg.IcebergTablePropertiesMetadata.LOCATION;
import static com.datastrato.gravitino.trino.connector.catalog.iceberg.IcebergPropertyMeta.ICEBERG_LOCATION_PROPERTY;

import com.datastrato.catalog.property.PropertyConverter;
import com.datastrato.gravitino.catalog.BasePropertiesMetadata;
import com.datastrato.gravitino.catalog.PropertyEntry;
Expand All @@ -22,7 +25,10 @@ public class IcebergTablePropertyConverter extends PropertyConverter {
// TODO (yuqi) add more properties
@VisibleForTesting
static final TreeBidiMap<String, String> TRINO_KEY_TO_GRAVITINO_KEY =
new TreeBidiMap<>(new ImmutableMap.Builder<String, String>().build());
new TreeBidiMap<>(
new ImmutableMap.Builder<String, String>()
.put(ICEBERG_LOCATION_PROPERTY, LOCATION)
.build());

@Override
public TreeBidiMap<String, String> engineToGravitinoMapping() {
Expand Down

0 comments on commit ee8d4a7

Please sign in to comment.