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

add support for rel to trino with localMetaStore #1

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ ligradle
.DS_Store
*.patch
*/metastore_db
.pyc
.pyc
__pycache__
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/**
* Copyright 2022-2023 LinkedIn Corporation. All rights reserved.
* Copyright 2022-2024 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
package com.linkedin.coral.trino.rel2trino;

import java.util.List;
import java.util.Map;

import org.apache.calcite.sql.SqlBasicCall;
import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlNode;
Expand Down Expand Up @@ -47,6 +50,17 @@ public DataTypeDerivedSqlCallConverter(HiveMetastoreClient mscClient, SqlNode to
new UnionSqlCallTransformer(typeDerivationUtil));
}

public DataTypeDerivedSqlCallConverter(Map<String, Map<String, List<String>>> localMetaStore, SqlNode topSqlNode) {
toRelConverter = new HiveToRelConverter(localMetaStore);
topSqlNode.accept(new RegisterDynamicFunctionsForTypeDerivation());

TypeDerivationUtil typeDerivationUtil = new TypeDerivationUtil(toRelConverter.getSqlValidator(), topSqlNode);
operatorTransformerList = SqlCallTransformers.of(new FromUtcTimestampOperatorTransformer(typeDerivationUtil),
new GenericProjectTransformer(typeDerivationUtil), new NamedStructToCastTransformer(typeDerivationUtil),
new ConcatOperatorTransformer(typeDerivationUtil), new SubstrOperatorTransformer(typeDerivationUtil),
new UnionSqlCallTransformer(typeDerivationUtil));
}

@Override
public SqlNode visit(final SqlCall call) {
return operatorTransformerList.apply((SqlCall) super.visit(call));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2017-2023 LinkedIn Corporation. All rights reserved.
* Copyright 2017-2024 LinkedIn Corporation. All rights reserved.
* Licensed under the BSD-2 Clause license.
* See LICENSE in the project root for license information.
*/
Expand Down Expand Up @@ -56,6 +56,7 @@ public class RelToTrinoConverter extends RelToSqlConverter {
*/
private Map<String, Boolean> configs = new HashMap<>();
private HiveMetastoreClient _hiveMetastoreClient;
private Map<String, Map<String, List<String>>> _localMetaStore;

/**
* Creates a RelToTrinoConverter.
Expand All @@ -78,6 +79,18 @@ public RelToTrinoConverter(HiveMetastoreClient mscClient, Map<String, Boolean> c
_hiveMetastoreClient = mscClient;
}

/**
* Creates a RelToTrinoConverter.
* @param localMetaStore In-memory Hive metastore represented in a map.
* @param configs configs
*/
public RelToTrinoConverter(Map<String, Map<String, List<String>>> localMetaStore, Map<String, Boolean> configs) {
super(TrinoSqlDialect.INSTANCE);
checkNotNull(configs);
this.configs = configs;
_localMetaStore = localMetaStore;
}

/**
* Convert relational algebra to Trino's SQL
* @param relNode calcite relational algebra representation of SQL
Expand All @@ -87,8 +100,17 @@ public String convert(RelNode relNode) {
RelNode rel = convertRel(relNode, configs);
SqlNode sqlNode = convertToSqlNode(rel);

SqlNode sqlNodeWithRelDataTypeDerivedConversions =
sqlNode.accept(new DataTypeDerivedSqlCallConverter(_hiveMetastoreClient, sqlNode));
DataTypeDerivedSqlCallConverter sqlNodeWithRelDataTypeDerivedConverter;

if (_localMetaStore != null && _hiveMetastoreClient == null) {
sqlNodeWithRelDataTypeDerivedConverter = new DataTypeDerivedSqlCallConverter(_localMetaStore, sqlNode);
} else if (_hiveMetastoreClient != null && _localMetaStore == null) {
sqlNodeWithRelDataTypeDerivedConverter = new DataTypeDerivedSqlCallConverter(_hiveMetastoreClient, sqlNode);
} else {
throw new IllegalStateException("Metadata source must be provided");
}

SqlNode sqlNodeWithRelDataTypeDerivedConversions = sqlNode.accept(sqlNodeWithRelDataTypeDerivedConverter);

SqlNode sqlNodeWithUDFOperatorConverted =
sqlNodeWithRelDataTypeDerivedConversions.accept(new CoralToTrinoSqlCallConverter(configs));
Expand Down