Skip to content

Commit

Permalink
Introduce getUnversionedClassName to VersionedSqlUserDefinedFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
ljfgem committed Aug 20, 2024
1 parent 606473e commit 0c9ba56
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public String getViewDependentFunctionName() {
return viewDependentFunctionName;
}

public String getUnversionedClassName() {
return removeVersioningPrefix(getName());
}

// This method is called during SQL validation. The super-class implementation resets the call's sqlOperator to one
// that is looked up from the StaticHiveFunctionRegistry or inferred dynamically if it's a Dali UDF. Since UDFs in the StaticHiveFunctionRegistry are not
// versioned, this method overrides the super-class implementation to properly restore the call's operator as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
package com.linkedin.coral.trino.rel2trino.transformers;

import org.apache.calcite.sql.SqlCall;
import org.apache.calcite.sql.SqlOperator;

import com.linkedin.coral.common.transformers.OperatorRenameSqlCallTransformer;
import com.linkedin.coral.hive.hive2rel.functions.StaticHiveFunctionRegistry;
import com.linkedin.coral.hive.hive2rel.functions.utils.FunctionUtils;
import com.linkedin.coral.hive.hive2rel.functions.VersionedSqlUserDefinedFunction;


/**
Expand All @@ -21,8 +22,10 @@ public class CoralRegistryOperatorRenameSqlCallTransformer extends OperatorRenam

@Override
protected boolean condition(SqlCall sqlCall) {
return sourceOpName.equalsIgnoreCase(FunctionUtils.removeVersioningPrefix(sqlCall.getOperator().getName()))
&& sqlCall.getOperandList().size() == numOperands;
final SqlOperator operator = sqlCall.getOperator();
final String operatorName = operator instanceof VersionedSqlUserDefinedFunction
? ((VersionedSqlUserDefinedFunction) operator).getUnversionedClassName() : operator.getName();
return sourceOpName.equalsIgnoreCase(operatorName) && sqlCall.getOperandList().size() == numOperands;
}

public CoralRegistryOperatorRenameSqlCallTransformer(String sourceOpName, int numOperands, String targetOpName) {
Expand Down

0 comments on commit 0c9ba56

Please sign in to comment.