Skip to content

Commit bfb065a

Browse files
committed
glue logic for CoralCatalog in coral-trino
1 parent 7116972 commit bfb065a

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

coral-hive/src/test/java/com/linkedin/coral/common/IcebergTableConverterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ private org.apache.iceberg.Table createMockIcebergTable() {
6262
// TimestampType.withoutZone() represents microsecond precision (6 digits)
6363
Schema icebergSchema = new Schema(Types.NestedField.required(1, "id", Types.LongType.get()),
6464
Types.NestedField.required(2, "event_time", Types.TimestampType.withoutZone()),
65-
Types.NestedField.optional(3, "name", Types.StringType.get()));
65+
Types.NestedField.optional(3, "name", Types.StringType.get()),
66+
Types.NestedField.optional(4, "binaryfield", Types.BinaryType.get()));
6667

6768
// Mock the Iceberg Table interface using Mockito
6869
org.apache.iceberg.Table mockTable = mock(org.apache.iceberg.Table.class);
@@ -99,7 +100,7 @@ public void testIcebergTableWithTimestampPrecision() {
99100

100101
// Check that we have 3 columns: id, event_time, name
101102
List<RelDataTypeField> fields = relNode.getRowType().getFieldList();
102-
assertEquals(fields.size(), 3, "Should have 3 columns");
103+
assertEquals(fields.size(), 4, "Should have 3 columns");
103104

104105
// Verify column names
105106
assertEquals(fields.get(0).getName(), "id");

coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/DataTypeDerivedSqlCallConverter.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022-2024 LinkedIn Corporation. All rights reserved.
2+
* Copyright 2022-2025 LinkedIn Corporation. All rights reserved.
33
* Licensed under the BSD-2 Clause license.
44
* See LICENSE in the project root for license information.
55
*/
@@ -11,6 +11,7 @@
1111
import org.apache.calcite.sql.util.SqlShuttle;
1212

1313
import com.linkedin.coral.common.HiveMetastoreClient;
14+
import com.linkedin.coral.common.catalog.CoralCatalog;
1415
import com.linkedin.coral.common.functions.Function;
1516
import com.linkedin.coral.common.transformers.SqlCallTransformers;
1617
import com.linkedin.coral.common.utils.TypeDerivationUtil;
@@ -48,6 +49,17 @@ public DataTypeDerivedSqlCallConverter(HiveMetastoreClient mscClient, SqlNode to
4849
new CastOperatorTransformer(typeDerivationUtil), new UnionSqlCallTransformer(typeDerivationUtil));
4950
}
5051

52+
public DataTypeDerivedSqlCallConverter(CoralCatalog coralCatalog, SqlNode topSqlNode) {
53+
toRelConverter = new HiveToRelConverter(coralCatalog);
54+
topSqlNode.accept(new RegisterDynamicFunctionsForTypeDerivation());
55+
56+
TypeDerivationUtil typeDerivationUtil = new TypeDerivationUtil(toRelConverter.getSqlValidator(), topSqlNode);
57+
operatorTransformerList = SqlCallTransformers.of(new FromUtcTimestampOperatorTransformer(typeDerivationUtil),
58+
new GenericProjectTransformer(typeDerivationUtil), new NamedStructToCastTransformer(typeDerivationUtil),
59+
new ConcatOperatorTransformer(typeDerivationUtil), new SubstrOperatorTransformer(typeDerivationUtil),
60+
new CastOperatorTransformer(typeDerivationUtil), new UnionSqlCallTransformer(typeDerivationUtil));
61+
}
62+
5163
@Override
5264
public SqlNode visit(final SqlCall call) {
5365
return operatorTransformerList.apply((SqlCall) super.visit(call));

coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017-2024 LinkedIn Corporation. All rights reserved.
2+
* Copyright 2017-2025 LinkedIn Corporation. All rights reserved.
33
* Licensed under the BSD-2 Clause license.
44
* See LICENSE in the project root for license information.
55
*/
@@ -30,6 +30,7 @@
3030

3131
import com.linkedin.coral.com.google.common.collect.ImmutableList;
3232
import com.linkedin.coral.common.HiveMetastoreClient;
33+
import com.linkedin.coral.common.catalog.CoralCatalog;
3334
import com.linkedin.coral.common.functions.CoralSqlUnnestOperator;
3435
import com.linkedin.coral.common.functions.FunctionFieldReferenceOperator;
3536
import com.linkedin.coral.transformers.CoralRelToSqlNodeConverter;
@@ -55,6 +56,7 @@ public class RelToTrinoConverter extends RelToSqlConverter {
5556
*/
5657
private Map<String, Boolean> configs = new HashMap<>();
5758
private HiveMetastoreClient _hiveMetastoreClient;
59+
private CoralCatalog _coralCatalog;
5860

5961
/**
6062
* Creates a RelToTrinoConverter.
@@ -65,6 +67,12 @@ public RelToTrinoConverter(HiveMetastoreClient mscClient) {
6567
_hiveMetastoreClient = mscClient;
6668
}
6769

70+
public RelToTrinoConverter(CoralCatalog coralCatalog) {
71+
super(CoralRelToSqlNodeConverter.INSTANCE);
72+
_coralCatalog = coralCatalog;
73+
;
74+
}
75+
6876
/**
6977
* Creates a RelToTrinoConverter.
7078
* @param mscClient client interface used to interact with the Hive Metastore service.
@@ -84,9 +92,15 @@ public RelToTrinoConverter(HiveMetastoreClient mscClient, Map<String, Boolean> c
8492
*/
8593
public String convert(RelNode relNode) {
8694
SqlNode sqlNode = convertToSqlNode(relNode);
95+
SqlNode sqlNodeWithRelDataTypeDerivedConversions;
8796

88-
SqlNode sqlNodeWithRelDataTypeDerivedConversions =
89-
sqlNode.accept(new DataTypeDerivedSqlCallConverter(_hiveMetastoreClient, sqlNode));
97+
if (_coralCatalog != null) {
98+
sqlNodeWithRelDataTypeDerivedConversions =
99+
sqlNode.accept(new DataTypeDerivedSqlCallConverter(_coralCatalog, sqlNode));
100+
} else {
101+
sqlNodeWithRelDataTypeDerivedConversions =
102+
sqlNode.accept(new DataTypeDerivedSqlCallConverter(_hiveMetastoreClient, sqlNode));
103+
}
90104

91105
SqlNode sqlNodeWithUDFOperatorConverted =
92106
sqlNodeWithRelDataTypeDerivedConversions.accept(new CoralToTrinoSqlCallConverter(configs));

0 commit comments

Comments
 (0)