code stringlengths 23 201k | docstring stringlengths 17 96.2k | func_name stringlengths 0 235 | language stringclasses 1
value | repo stringlengths 8 72 | path stringlengths 11 317 | url stringlengths 57 377 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
@Override
public Result visit(Join e) {
Result leftResult = this.visitChild(0, e.getLeft()).resetAlias();
Result rightResult = this.visitChild(1, e.getRight()).resetAlias();
Context leftContext = leftResult.qualifiedContext();
Context rightContext = rightResult.qualifiedContext();
SqlNode sqlCondi... | Join represents a RelNode with two child relational expressions linked by a join type.
Super's implementation uses the conversion result of the right child as is.
When the right child of a Join node is an Uncollect / TableFunction type RelNode,
this overriding implementation introduces LATERAL and AS operators as paren... | visit | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java | BSD-2-Clause |
@Override
public Result visit(Correlate e) {
final Result leftResult = visitChild(0, e.getLeft()).resetAlias();
// Add context specifying correlationId has same context as its left child
correlTableMap.put(e.getCorrelationId(), leftResult.qualifiedContext());
final Result rightResult = visitChild(1,... | Correlate represents a RelNode with two child relational expressions linked by a join type.
Super's implementation introduces a LATERAL operator and an AS operator with a single alias as parents of the conversion result of the right child.
This overriding implementation performs the same operations only when the right ... | visit | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java | BSD-2-Clause |
private SqlNode generateRightChildForSqlJoinWithLateralViews(BiRel e, Result rightResult) {
SqlNode rightSqlNode = rightResult.asFrom();
SqlNode lateralNode;
// Drop the AS operator from the rightSqlNode if it exists and append the LATERAL operator on the inner SqlNode.
if (rightSqlNode instanceof SqlC... | Correlate represents a RelNode with two child relational expressions linked by a join type.
Super's implementation introduces a LATERAL operator and an AS operator with a single alias as parents of the conversion result of the right child.
This overriding implementation performs the same operations only when the right ... | generateRightChildForSqlJoinWithLateralViews | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/RelToTrinoConverter.java | BSD-2-Clause |
private static SqlDataTypeSpec convertTypeSpec(SqlDataTypeSpec type) {
if (type instanceof SqlArrayTypeSpec) {
SqlArrayTypeSpec arrayType = (SqlArrayTypeSpec) type;
return new SqlArrayTypeSpec(convertTypeSpec(arrayType.getElementTypeSpec()), arrayType.getParserPosition());
} else if (type instanceof... | Replace Calcite data types present in the SQL query with their respective Trino data types | convertTypeSpec | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/TrinoSqlRewriter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/TrinoSqlRewriter.java | BSD-2-Clause |
@Override
public SqlNode visit(SqlDataTypeSpec type) {
return convertTypeSpec(type);
} | Replace Calcite data types present in the SQL query with their respective Trino data types | visit | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/TrinoSqlRewriter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/TrinoSqlRewriter.java | BSD-2-Clause |
@Override
public RelDataType inferReturnType(final SqlOperatorBinding opBinding) {
return genericDataType;
} | GenericFunctionTemplate is a template UDF abstract class that takes a return type and a function name.
This template is used by UDFs in Trino that have dynamic return types and a lambda function parameter.
The lambda function parameter will be represented as a string literal input.
Since these lambda functions are inte... | inferReturnType | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | BSD-2-Clause |
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
return genericDataType;
} | GenericFunctionTemplate is a template UDF abstract class that takes a return type and a function name.
This template is used by UDFs in Trino that have dynamic return types and a lambda function parameter.
The lambda function parameter will be represented as a string literal input.
Since these lambda functions are inte... | deriveType | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | BSD-2-Clause |
@Override
public boolean checkOperandTypes(SqlCallBinding callBinding, boolean throwOnFailure) {
return true;
} | GenericFunctionTemplate is a template UDF abstract class that takes a return type and a function name.
This template is used by UDFs in Trino that have dynamic return types and a lambda function parameter.
The lambda function parameter will be represented as a string literal input.
Since these lambda functions are inte... | checkOperandTypes | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | BSD-2-Clause |
@Override
protected void checkOperandCount(SqlValidator validator, SqlOperandTypeChecker argTypeChecker, SqlCall call) {
} | GenericFunctionTemplate is a template UDF abstract class that takes a return type and a function name.
This template is used by UDFs in Trino that have dynamic return types and a lambda function parameter.
The lambda function parameter will be represented as a string literal input.
Since these lambda functions are inte... | checkOperandCount | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | BSD-2-Clause |
@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
Preconditions.checkState(call.operandCount() == 1);
String lambdaFunctionString = call.operand(0).toString();
// SqlCharStringLiterals add beginning and trailing single quotation marks when passing in a literal.
... | GenericFunctionTemplate is a template UDF abstract class that takes a return type and a function name.
This template is used by UDFs in Trino that have dynamic return types and a lambda function parameter.
The lambda function parameter will be represented as a string literal input.
Since these lambda functions are inte... | unparse | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/GenericTemplateFunction.java | BSD-2-Clause |
public static String buildTrinoTypeString(RelDataType relDataType) {
switch (relDataType.getSqlTypeName()) {
case ROW:
return buildStructDataTypeString((RelRecordType) relDataType);
case ARRAY:
return buildArrayDataTypeString((ArraySqlType) relDataType);
case MAP:
return bu... | Creates a Trino type string for a given RelDataType
Some examples of Trino type strings produced for a RelDataType are as follows:
Example 1:
- RelDataType:
- map(string, string)
- Trino type String
- map(varchar, varchar)
Example 2:
- RelDataType:
- array(string)
- Trino type st... | buildTrinoTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | BSD-2-Clause |
private static String buildStructDataTypeString(RelRecordType relRecordType) {
List<String> structFieldStrings = new ArrayList<>();
for (RelDataTypeField relDataTypeField : relRecordType.getFieldList()) {
structFieldStrings
.add(String.format("%s %s", TrinoKeywordsConverter.quoteWordIfNotQuoted(... | Build a Trino struct/row string with format:
row([field_name] [field_type], ...)
@param relRecordType a given struct RelDataType
@return a string that represents the given relRecordType | buildStructDataTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | BSD-2-Clause |
private static String buildArrayDataTypeString(ArraySqlType arraySqlType) {
String elementDataTypeString = buildTrinoTypeString(arraySqlType.getComponentType());
return String.format("array(%s)", elementDataTypeString);
} | Build a Trino array string with format:
array([field_type])
@param arraySqlType a given array RelDataType
@return a string that represents the given arraySqlType | buildArrayDataTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | BSD-2-Clause |
private static String buildMapDataTypeString(MapSqlType mapSqlType) {
String keyDataTypeString = buildTrinoTypeString(mapSqlType.getKeyType());
String valueDataTypeString = buildTrinoTypeString(mapSqlType.getValueType());
return String.format("map(%s, %s)", keyDataTypeString, valueDataTypeString);
} | Build a Trino map string with format:
map([key_type], [value_type])
@param mapSqlType a given map RelDataType
@return a string that represents the given mapSqlType | buildMapDataTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/RelDataTypeToTrinoTypeStringConverter.java | BSD-2-Clause |
public static String quoteReservedKeyword(String value) {
if (RESERVED_KEYWORDS.contains(value.toUpperCase())) {
return quoteWordIfNotQuoted(value);
} else {
return value;
}
} | Quote the value iif it is a reserved Trino keyword
Note: This method is not used in Coral anymore, but we don't remove it since our internal Trino is using it
@param value input value
@return if the value is a reserved keyword, a double quote will be added as a return value | quoteReservedKeyword | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/TrinoKeywordsConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/TrinoKeywordsConverter.java | BSD-2-Clause |
public static String quoteWordIfNotQuoted(String value) {
return value.startsWith("\"") && value.endsWith("\"") ? value : ("\"" + value + "\"");
} | Add quote if the value is not quoted | quoteWordIfNotQuoted | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/TrinoKeywordsConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/TrinoKeywordsConverter.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getKind() == SqlKind.AS && sqlCall.operandCount() > 2
&& sqlCall.operand(0) instanceof SqlBasicCall && sqlCall.operand(0).getKind() == SqlKind.LATERAL;
} | This class implements the transformation of SqlCalls with AS operator in format: LATERAL UNNEST(x) AS y (z)
to their corresponding Trino-compatible versions.
For example, "LATERAL UNNEST(x) AS y (z)" is transformed to "UNNEST(x) AS y (z)" | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/AsOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/AsOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> oldAliasOperands = sqlCall.getOperandList();
List<SqlNode> newAliasOperands = new ArrayList<>();
SqlCall lateralSqlCall = sqlCall.operand(0);
// Drop the LATERAL operator when a lateralSqlCall's operand's operator is UNNEST
Sq... | This class implements the transformation of SqlCalls with AS operator in format: LATERAL UNNEST(x) AS y (z)
to their corresponding Trino-compatible versions.
For example, "LATERAL UNNEST(x) AS y (z)" is transformed to "UNNEST(x) AS y (z)" | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/AsOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/AsOperatorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getKind() == SqlKind.CAST;
} | The CAST operator in Trino has some differences compared to Hive, which are handled by this transformer:
1) Hive allows for casting of TIMESTAMP to DECIMAL, by converting it to unix time if the specified decimal
type has enough precision/scale to hold the Unix timestamp value. For example, casting to DECIMAL(10,0)
... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CastOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CastOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> operands = sqlCall.getOperandList();
final SqlNode leftOperand = operands.get(0);
final RelDataType sourceType = deriveRelDatatype(leftOperand);
final SqlDataTypeSpec targetSqlDataTypeSpec = (SqlDataTypeSpec) operands.get(1);
... | The CAST operator in Trino has some differences compared to Hive, which are handled by this transformer:
1) Hive allows for casting of TIMESTAMP to DECIMAL, by converting it to unix time if the specified decimal
type has enough precision/scale to hold the Unix timestamp value. For example, casting to DECIMAL(10,0)
... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CastOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CastOperatorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
final String operatorName = sqlCall.getOperator().getName();
return operatorName.equalsIgnoreCase(COLLECT_LIST) || operatorName.equalsIgnoreCase(COLLECT_SET);
} | This class implements the transformation from the operations "collect_list" and "collect_set" to their
respective Trino-compatible versions.
For example, "collect_list(col)" is transformed into "array_agg(col)", and
"collect_set(col)" is transformed into "array_distinct(array_agg(col))". | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CollectListOrSetFunctionTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CollectListOrSetFunctionTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
final String operatorName = sqlCall.getOperator().getName();
final SqlOperator arrayAgg = createSqlOperator(ARRAY_AGG, FunctionReturnTypes.ARRAY_OF_ARG0_TYPE);
final SqlOperator arrayDistinct = createSqlOperator(ARRAY_DISTINCT, FunctionReturnTypes.A... | This class implements the transformation from the operations "collect_list" and "collect_set" to their
respective Trino-compatible versions.
For example, "collect_list(col)" is transformed into "array_agg(col)", and
"collect_set(col)" is transformed into "array_distinct(array_agg(col))". | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CollectListOrSetFunctionTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CollectListOrSetFunctionTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getName().equalsIgnoreCase(OPERATOR_NAME);
} | This transformer is designed for SqlCalls that use the CONCAT operator.
Its purpose is to convert the data types of the operands to be compatible with Trino.
Trino only allows VARCHAR type operands for the CONCAT operator. Therefore, if there are any other data type operands present,
an extra CAST operator is added aro... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ConcatOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ConcatOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> updatedOperands = new ArrayList<>();
for (SqlNode operand : sqlCall.getOperandList()) {
RelDataType type = deriveRelDatatype(operand);
if (!OPERAND_SQL_TYPE_NAMES.contains(type.getSqlTypeName())) {
SqlNode castOperand ... | This transformer is designed for SqlCalls that use the CONCAT operator.
Its purpose is to convert the data types of the operands to be compatible with Trino.
Trino only allows VARCHAR type operands for the CONCAT operator. Therefore, if there are any other data type operands present,
an extra CAST operator is added aro... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ConcatOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ConcatOperatorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getName().equalsIgnoreCase(CURRENT_TIMESTAMP_FUNCTION_NAME);
} | This class implements the transformation for the CURRENT_TIMESTAMP function.
For example, "SELECT CURRENT_TIMESTAMP" is transformed into "SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP(3))".
This transformation ensures compatibility with Trino. | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CurrentTimestampTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CurrentTimestampTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
SqlDataTypeSpec timestampType =
new SqlDataTypeSpec(new SqlBasicTypeNameSpec(SqlTypeName.TIMESTAMP, 3, SqlParserPos.ZERO), SqlParserPos.ZERO);
return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, sqlCall, timestampType);
} | This class implements the transformation for the CURRENT_TIMESTAMP function.
For example, "SELECT CURRENT_TIMESTAMP" is transformed into "SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP(3))".
This transformation ensures compatibility with Trino. | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CurrentTimestampTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/CurrentTimestampTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getName().equalsIgnoreCase(FROM_UNIXTIME);
} | This transformer operates on SqlCalls with 'FROM_UNIXTIME(x)' Coral IR function
and transforms it to trino engine compatible function - FORMAT_DATETIME(FROM_UNIXTIME(x)).
For Example:
A SqlCall of the form: "FROM_UNIXTIME(10000)" is transformed to
"FORMAT_DATETIME(FROM_UNIXTIME(10000), 'yyyy-MM-dd HH:mm:ss')" | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUnixtimeOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUnixtimeOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
SqlOperator formatDatetimeOperator = createSqlOperator(FORMAT_DATETIME, FunctionReturnTypes.STRING);
SqlOperator fromUnixtimeOperator = createSqlOperator(FROM_UNIXTIME, explicit(TIMESTAMP));
List<SqlNode> operands = sqlCall.getOperandList();
if... | This transformer operates on SqlCalls with 'FROM_UNIXTIME(x)' Coral IR function
and transforms it to trino engine compatible function - FORMAT_DATETIME(FROM_UNIXTIME(x)).
For Example:
A SqlCall of the form: "FROM_UNIXTIME(10000)" is transformed to
"FORMAT_DATETIME(FROM_UNIXTIME(10000), 'yyyy-MM-dd HH:mm:ss')" | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUnixtimeOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUnixtimeOperatorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getName().equalsIgnoreCase(FROM_UTC_TIMESTAMP);
} | This transformer operates on SqlCalls with 'FROM_UTC_TIMESTAMP(x, timezone)' Coral IR function
and transforms it into different trino engine compatible functions based on the data type of 'x'.
For Example:
A SqlCall of the form: "FROM_UTC_TIMESTAMP(10000, 'America/Los_Angeles')" is transformed to
"CAST(AT_TIMEZONE(FROM... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> operands = sqlCall.getOperandList();
SqlNode sourceValue = operands.get(0);
SqlNode timezone = operands.get(1);
RelDataType targetType = new BasicSqlType(new HiveTypeSystem(), TIMESTAMP, 3);
RelDataType inputType = deriveRelDa... | This transformer operates on SqlCalls with 'FROM_UTC_TIMESTAMP(x, timezone)' Coral IR function
and transforms it into different trino engine compatible functions based on the data type of 'x'.
For Example:
A SqlCall of the form: "FROM_UTC_TIMESTAMP(10000, 'America/Los_Angeles')" is transformed to
"CAST(AT_TIMEZONE(FROM... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java | BSD-2-Clause |
private SqlCall castOperand(SqlNode operand, RelDataType relDataType) {
return SqlStdOperatorTable.CAST.createCall(ZERO, operand, SqlTypeUtil.convertTypeToSpec(relDataType));
} | This transformer operates on SqlCalls with 'FROM_UTC_TIMESTAMP(x, timezone)' Coral IR function
and transforms it into different trino engine compatible functions based on the data type of 'x'.
For Example:
A SqlCall of the form: "FROM_UTC_TIMESTAMP(10000, 'America/Los_Angeles')" is transformed to
"CAST(AT_TIMEZONE(FROM... | castOperand | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/FromUtcTimestampOperatorTransformer.java | BSD-2-Clause |
private String mapDataTypeString(MapSqlType fromDataType, MapSqlType toDataType, String fieldNameReference) {
String mapDataTypeArgumentString = mapDataTypeArgumentString(fromDataType, toDataType, fieldNameReference);
return String.format("transform_values(%s)", mapDataTypeArgumentString);
} | Create the transformation string for a map RelDataType to convert fromDataType to toDataType.
The transformation string follows the following format:
TRANSFORM_VALUES([selected_map_field_reference], (k, v) -> [transform v as necessary])
@param fromDataType given map RelDataType
@param toDataType desired map RelDataTy... | mapDataTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String mapDataTypeArgumentString(MapSqlType fromDataType, MapSqlType toDataType, String fieldNameReference) {
String mapKeyFieldReference = "k";
String mapValueFieldReference = "v";
String valueTransformedFieldString =
relDataTypeFieldAccessString(fromDataType.getValueType(), toDataType.getV... | Create the argument string to a TRANSFORM_VALUES() Trino UDF call to convert fromDataType to toDataType.
The argument string follows the following format:
[selected_map_field_reference], (k, v) -> [transform v as necessary]
@param fromDataType given map RelDataType
@param toDataType desired map RelDataType
@param fie... | mapDataTypeArgumentString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String arrayDataTypeString(ArraySqlType fromDataType, ArraySqlType toDataType, String fieldNameReference) {
String arrayDataTypeArgumentString = arrayDataTypeArgumentString(fromDataType, toDataType, fieldNameReference);
return String.format("transform(%s)", arrayDataTypeArgumentString);
} | Create the transformation string for an array RelDataType to convert fromDataType to toDataType.
The transformation string follows the following format:
TRANSFORM([selected_array_field_reference], x -> [transform x as necessary])
@param fromDataType given array RelDataType
@param toDataType desired array RelDataType
... | arrayDataTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String arrayDataTypeArgumentString(ArraySqlType fromDataType, ArraySqlType toDataType,
String fieldNameReference) {
String elementFieldReference = "x";
String elementTransformedFieldString = relDataTypeFieldAccessString(fromDataType.getComponentType(),
toDataType.getComponentType(), elemen... | Create the argument string to a TRANSFORM() Trino UDF call to convert fromDataType to toDataType.
The argument string follows the following format:
[selected_array_field_reference], x -> [transform x as necessary]
@param fromDataType given array RelDataType
@param toDataType desired array RelDataType
@param fieldName... | arrayDataTypeArgumentString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String structDataTypeString(RelRecordType fromDataType, RelRecordType toDataType, String fieldNameReference) {
String structDataTypeArgumentString = structDataTypeArgumentString(fromDataType, toDataType, fieldNameReference);
return (String.format("cast(%s)", structDataTypeArgumentString));
} | Create the transformation string for a struct RelDataType to convert fromDataType to toDataType.
The transformation string follows the following format:
CAST(ROW([selected_row_field_references]) AS ROW([selected_row_field_types]))
@param fromDataType given struct RelDataType
@param toDataType desired struct RelDataTy... | structDataTypeString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String structDataTypeArgumentString(RelRecordType fromDataType, RelRecordType toDataType,
String fieldNameReference) {
String structFieldsAccessString =
buildStructRelDataTypeFieldAccessString(fromDataType, toDataType, fieldNameReference);
String castToRowTypeString = RelDataTypeToTrinoTyp... | Create the argument string to a CAST() Trino UDF call to convert fromDataType to toDataType.
The argument string follows the following format:
ROW([selected_row_field_references]) AS ROW([selected_row_field_types])
@param fromDataType given array RelDataType
@param toDataType desired array RelDataType
@param fieldNam... | structDataTypeArgumentString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String relDataTypeFieldAccessString(RelDataType fromDataType, RelDataType toDataType,
String fieldNameReference) {
if (fromDataType.equals(toDataType)) {
return fieldNameReference;
}
switch (toDataType.getSqlTypeName()) {
case ROW:
return structDataTypeString((RelRecordTyp... | Delegates a string builder to transform fromDataType to toDataType.
@param fromDataType given RelDataType
@param toDataType desired RelDataType
@param fieldNameReference name of the field reference
@return string denoting the argument to a CAST UDF call | relDataTypeFieldAccessString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
private String buildStructRelDataTypeFieldAccessString(RelRecordType fromDataType, RelRecordType toDataType,
String fieldNameReference) {
List<String> structSelectedFieldStrings = new ArrayList<>();
for (RelDataTypeField toDataTypeField : toDataType.getFieldList()) {
RelDataTypeField fromDataTypeFie... | Create a struct field access string in the form of:
ROW([selected_col_field_1], [selected_col_field_2], etc.)
@param fromDataType given struct RelDataType
@param toDataType desired struct RelDataType
@param fieldNameReference name of the struct field reference
@return string denoting a row with all desired field acce... | buildStructRelDataTypeFieldAccessString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/GenericProjectTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
final SqlOperator operator = sqlCall.getOperator();
final String operatorName = operator.getName();
return operator instanceof VersionedSqlUserDefinedFunction && operatorName.contains(".")
&& !operatorName.equals(".");
} | This transformer converts the Hive UDF SqlCall name from the UDF class name to the
corresponding Trino function name.
i.e. from `com.linkedin.stdudfs.parsing.hive.Ip2Str` to `ip2str`. | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/HiveUDFTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/HiveUDFTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
final SqlOperator operator = sqlCall.getOperator();
final String trinoFunctionName = ((VersionedSqlUserDefinedFunction) operator).getShortFunctionName();
return createSqlOperator(trinoFunctionName, operator.getReturnTypeInference())
.createC... | This transformer converts the Hive UDF SqlCall name from the UDF class name to the
corresponding Trino function name.
i.e. from `com.linkedin.stdudfs.parsing.hive.Ip2Str` to `ip2str`. | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/HiveUDFTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/HiveUDFTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().kind == SqlKind.JOIN && ((SqlJoin) sqlCall).getJoinType() == JoinType.COMMA;
} | This class implements the transformation of SqlCalls with JOIN operator with COMMA JoinType to
their corresponding Trino-compatible versions.
For example, an input SqlJoin SqlCall:
SqlJoin[`default`.`complex` , UNNEST(`complex`.`c`) AS `t_alias` (`col_alias`)]
|
... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
SqlJoin joinSqlCall = (SqlJoin) sqlCall;
// Check if there's an unnest SqlCall present in the nested SqlNodes
if (isUnnestOperatorPresentInRightSqlNode(joinSqlCall.getRight())) {
// Check if the nested UNNEST SqlCall is correlated to the oute... | This class implements the transformation of SqlCalls with JOIN operator with COMMA JoinType to
their corresponding Trino-compatible versions.
For example, an input SqlJoin SqlCall:
SqlJoin[`default`.`complex` , UNNEST(`complex`.`c`) AS `t_alias` (`col_alias`)]
|
... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | BSD-2-Clause |
private static boolean isUnnestOperatorPresentInRightSqlNode(SqlNode rightSqlNode) {
return rightSqlNode instanceof SqlCall && rightSqlNode.getKind() == SqlKind.AS
&& ((SqlCall) rightSqlNode).operand(0) instanceof SqlCall
&& ((SqlCall) rightSqlNode).operand(0).getKind() == SqlKind.UNNEST;
} | Check if the input sqlNode has a nested SqlCall with UNNEST operator
@param rightSqlNode right child of a SqlJoin SqlCall
@return boolean result | isUnnestOperatorPresentInRightSqlNode | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | BSD-2-Clause |
private static SqlCall createCrossJoinSqlCall(SqlJoin sqlCall) {
return new SqlJoin(POS, (sqlCall).getLeft(), SqlLiteral.createBoolean(false, SqlParserPos.ZERO),
JoinType.CROSS.symbol(POS), (sqlCall).getRight(), JoinConditionType.NONE.symbol(SqlParserPos.ZERO), null);
} | transform sqlCall: TRANSFORM(table1.col, x -> ROW(x))
operator = "TRANSFORM"
operand = "table1.col, x -> ROW(x)" | createCrossJoinSqlCall | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/JoinSqlCallTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator() instanceof SqlMapValueConstructor;
} | This class implements the transformation from the {@link SqlMapValueConstructor} operation
to separate {@link SqlStdOperatorTable#ARRAY_VALUE_CONSTRUCTOR} operations for keys and values
in order to be compatible with Trino.
For example, "MAP['key1', 'value1', 'key2', 'value2']" is transformed into
"MAP(ARRAY['key1', '... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/MapValueConstructorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/MapValueConstructorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
final List<SqlNode> sourceOperands = sqlCall.getOperandList();
final List<SqlNode> updatedOperands = new ArrayList<>();
// Even numbers are keys
final List<SqlNode> keys = new ArrayList<>();
for (int i = 0; i < sourceOperands.size(); i += 2)... | This class implements the transformation from the {@link SqlMapValueConstructor} operation
to separate {@link SqlStdOperatorTable#ARRAY_VALUE_CONSTRUCTOR} operations for keys and values
in order to be compatible with Trino.
For example, "MAP['key1', 'value1', 'key2', 'value2']" is transformed into
"MAP(ARRAY['key1', '... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/MapValueConstructorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/MapValueConstructorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().equals(HiveNamedStructFunction.NAMED_STRUCT);
} | This transformer converts Coral IR function `named_struct` to a Trino compatible representation.
For example, the SqlCall: `named_struct('abc', 123, 'def', 'xyz')` will be transformed to
`CAST(ROW(123, 'xyz') AS ROW(`abc` INTEGER, `def` CHAR(3) CHARACTER SET `ISO-8859-1`))` | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NamedStructToCastTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NamedStructToCastTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> inputOperands = sqlCall.getOperandList();
List<SqlDataTypeSpec> rowTypes = new ArrayList<>();
List<String> fieldNames = new ArrayList<>();
for (int i = 0; i < inputOperands.size(); i += 2) {
assert inputOperands.get(i) insta... | This transformer converts Coral IR function `named_struct` to a Trino compatible representation.
For example, the SqlCall: `named_struct('abc', 123, 'def', 'xyz')` will be transformed to
`CAST(ROW(123, 'xyz') AS ROW(`abc` INTEGER, `def` CHAR(3) CHARACTER SET `ISO-8859-1`))` | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NamedStructToCastTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NamedStructToCastTransformer.java | BSD-2-Clause |
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
SqlCallBinding opBinding = new SqlCallBinding(validator, scope, call);
return inferReturnType(opBinding);
} | This transformer converts Coral IR function `named_struct` to a Trino compatible representation.
For example, the SqlCall: `named_struct('abc', 123, 'def', 'xyz')` will be transformed to
`CAST(ROW(123, 'xyz') AS ROW(`abc` INTEGER, `def` CHAR(3) CHARACTER SET `ISO-8859-1`))` | deriveType | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NamedStructToCastTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NamedStructToCastTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return (sqlCall.getOperator().kind == SqlKind.SELECT && ((SqlSelect) sqlCall).getOrderList() != null)
|| (sqlCall.getOperator().kind == SqlKind.WINDOW && ((SqlWindow) sqlCall).getOrderList() != null);
} | This class transforms the ordering in the input SqlCall to be compatible with Trino engine.
There is no need to override ASC inputs since the default null orderings of Coral IR, Hive and Trino all match.
However, "DESC NULLS LAST" need to be overridden to remove the redundant "NULLS LAST" since
Trino defaults to a NULL... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
SqlNodeList newOrderList = new SqlNodeList(POS);
for (SqlNode node : getOrderList(sqlCall)) {
SqlNode operand = ((SqlBasicCall) node).getOperandList().get(0);
if (node instanceof SqlBasicCall && ((SqlBasicCall) node).getOperator().kind == ... | This class transforms the ordering in the input SqlCall to be compatible with Trino engine.
There is no need to override ASC inputs since the default null orderings of Coral IR, Hive and Trino all match.
However, "DESC NULLS LAST" need to be overridden to remove the redundant "NULLS LAST" since
Trino defaults to a NULL... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | BSD-2-Clause |
private SqlNodeList getOrderList(SqlCall sqlCall) {
switch (sqlCall.getOperator().kind) {
case SELECT:
return ((SqlSelect) sqlCall).getOrderList();
case WINDOW:
return ((SqlWindow) sqlCall).getOrderList();
case DEFAULT:
return new SqlNodeList(POS);
}
return new Sql... | This class transforms the ordering in the input SqlCall to be compatible with Trino engine.
There is no need to override ASC inputs since the default null orderings of Coral IR, Hive and Trino all match.
However, "DESC NULLS LAST" need to be overridden to remove the redundant "NULLS LAST" since
Trino defaults to a NULL... | getOrderList | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | BSD-2-Clause |
private void setOrderList(SqlCall sqlCall, SqlNodeList newOrderList) {
switch (sqlCall.getOperator().kind) {
case SELECT:
((SqlSelect) sqlCall).setOrderBy(newOrderList);
break;
case WINDOW:
((SqlWindow) sqlCall).setOrderList(newOrderList);
break;
}
} | This class transforms the ordering in the input SqlCall to be compatible with Trino engine.
There is no need to override ASC inputs since the default null orderings of Coral IR, Hive and Trino all match.
However, "DESC NULLS LAST" need to be overridden to remove the redundant "NULLS LAST" since
Trino defaults to a NULL... | setOrderList | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/NullOrderingTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
String lowercaseOperatorName = sqlCall.getOperator().getName().toLowerCase(Locale.ROOT);
if ("date_add".equals(lowercaseOperatorName) && !configs.getOrDefault(CAST_DATEADD_TO_STRING, false)) {
return false;
}
return OPERATORS_TO_ADJUST.con... | This transformer casts the result of some Trino functions to the same return type as in Hive.
Example:
"DATEDIFF" function in Hive returns int type, but the corresponding function "DATE_DIFF" in Trino
returns bigint type. To ensure compatibility, a "CAST" is added to convert the result to the int type. | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ReturnTypeAdjustmentTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ReturnTypeAdjustmentTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
String lowercaseOperatorName = sqlCall.getOperator().getName().toLowerCase(Locale.ROOT);
SqlTypeName targetType = OPERATORS_TO_ADJUST.get(lowercaseOperatorName);
if (targetType != null) {
return createCast(sqlCall, targetType);
}
retur... | This transformer casts the result of some Trino functions to the same return type as in Hive.
Example:
"DATEDIFF" function in Hive returns int type, but the corresponding function "DATE_DIFF" in Trino
returns bigint type. To ensure compatibility, a "CAST" is added to convert the result to the int type. | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ReturnTypeAdjustmentTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ReturnTypeAdjustmentTransformer.java | BSD-2-Clause |
private SqlCall createCast(SqlNode node, SqlTypeName typeName) {
SqlDataTypeSpec targetTypeNode =
new SqlDataTypeSpec(new SqlBasicTypeNameSpec(typeName, SqlParserPos.ZERO), SqlParserPos.ZERO);
return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, node, targetTypeNode);
} | This transformer casts the result of some Trino functions to the same return type as in Hive.
Example:
"DATEDIFF" function in Hive returns int type, but the corresponding function "DATE_DIFF" in Trino
returns bigint type. To ensure compatibility, a "CAST" is added to convert the result to the int type. | createCast | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ReturnTypeAdjustmentTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ReturnTypeAdjustmentTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().kind == SqlKind.SELECT && ((SqlSelect) sqlCall).getSelectList() != null
&& ((SqlSelect) sqlCall).getSelectList().size() != 0;
} | This transformer operates on SqlSelect type sqlCalls. It appends an alias to all the projected fields with fully qualified names.
For Example: It modifies a SqlSelect sqlCall statement of the form: "SELECT foo.a FROM foo" to "SELECT foo.a AS a FROM foo". | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SqlSelectAliasAppenderTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SqlSelectAliasAppenderTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
final List<SqlNode> modifiedSelectList = new ArrayList<>();
for (SqlNode selectNode : ((SqlSelect) sqlCall).getSelectList().getList()) {
final String name = SqlValidatorUtil.getAlias(selectNode, -1);
final boolean nestedFieldAccess =
... | This transformer operates on SqlSelect type sqlCalls. It appends an alias to all the projected fields with fully qualified names.
For Example: It modifies a SqlSelect sqlCall statement of the form: "SELECT foo.a FROM foo" to "SELECT foo.a AS a FROM foo". | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SqlSelectAliasAppenderTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SqlSelectAliasAppenderTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return SUBSTRING_OPERATORS.contains(sqlCall.getOperator().getName().toLowerCase());
} | This class transforms the substr indexing in the input SqlCall to be compatible with Trino engine.
Trino uses 1-based indexing for substr, so the lowest possible index is 1. While other engines like Hive
allow for 0 as a valid index.
This transformer guarantees that starting index will always 1 or greater. | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrIndexTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrIndexTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
final List<SqlNode> operandList = sqlCall.getOperandList();
SqlNode start = operandList.get(1);
if (start instanceof SqlNumericLiteral) {
int startInt = ((SqlNumericLiteral) operandList.get(1)).getValueAs(Integer.class);
if (startInt ==... | This class transforms the substr indexing in the input SqlCall to be compatible with Trino engine.
Trino uses 1-based indexing for substr, so the lowest possible index is 1. While other engines like Hive
allow for 0 as a valid index.
This transformer guarantees that starting index will always 1 or greater. | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrIndexTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrIndexTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().getName().equalsIgnoreCase(SUBSTR_OPERATOR_NAME);
} | This class implements the transformation of SqlCalls with Coral IR function `SUBSTR`
to their corresponding Trino-compatible versions.
For example:
Given table:
t1(int_col INTEGER, time_col timestamp)
and a Coral IR SqlCall:
`SUBSTR(time_col, 12, 8)`
The transformed SqlCall would be:
`SUBSTR(CAST(ti... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> operands = sqlCall.getOperandList();
RelDataType relDataTypeOfOperand = deriveRelDatatype(operands.get(0));
// Coral IR accepts a byte array or String as an input for the `substr` operator.
// This behavior is emulated by casting ... | This class implements the transformation of SqlCalls with Coral IR function `SUBSTR`
to their corresponding Trino-compatible versions.
For example:
Given table:
t1(int_col INTEGER, time_col timestamp)
and a Coral IR SqlCall:
`SUBSTR(time_col, 12, 8)`
The transformed SqlCall would be:
`SUBSTR(CAST(ti... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/SubstrOperatorTransformer.java | BSD-2-Clause |
@Override
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) {
// for timestamp operator, we need to construct `CAST(x AS TIMESTAMP)`
Preconditions.checkState(call.operandCount() == 1);
final SqlWriter.Frame frame = writer.startFunCall("CAST");
... | This class implements the transformation from the operation of "to_date"
for example, "to_date('2023-01-01')" is transformed into "date(CAST('2023-01-01' AS TIMESTAMP))" | unparse | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ToDateOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ToDateOperatorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return !avoidTransformToDateUDF && FROM_OPERATOR_NAME.equalsIgnoreCase(sqlCall.getOperator().getName())
&& sqlCall.getOperandList().size() == NUM_OPERANDS;
} | This class implements the transformation from the operation of "to_date"
for example, "to_date('2023-01-01')" is transformed into "date(CAST('2023-01-01' AS TIMESTAMP))" | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ToDateOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ToDateOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> sourceOperands = sqlCall.getOperandList();
List<SqlNode> newOperands = new ArrayList<>();
SqlNode timestampSqlCall = createCall(TIMESTAMP_OPERATOR, sourceOperands, SqlParserPos.ZERO);
newOperands.add(timestampSqlCall);
return c... | This class implements the transformation from the operation of "to_date"
for example, "to_date('2023-01-01')" is transformed into "date(CAST('2023-01-01' AS TIMESTAMP))" | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ToDateOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/ToDateOperatorTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator().kind == SqlKind.UNION || sqlCall.getOperator().kind == SqlKind.INTERSECT
|| sqlCall.getOperator().kind == SqlKind.MINUS;
} | This transformer class is used to adapt expressions in
set statements (e.g.: `UNION`, `INTERSECT`, `MINUS`)
in case that the branches of the set statement contain fields in
char family which have different types.
The `char` fields which are differing from the expected `varchar` output
of the set statement will be adapt... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
List<SqlNode> operandsList = sqlCall.getOperandList();
if (sqlCall.getOperandList().isEmpty()) {
return sqlCall;
}
Integer selectListSize = null;
// Ensure all the operand are SELECT nodes and they have the same number of expressions p... | This transformer class is used to adapt expressions in
set statements (e.g.: `UNION`, `INTERSECT`, `MINUS`)
in case that the branches of the set statement contain fields in
char family which have different types.
The `char` fields which are differing from the expected `varchar` output
of the set statement will be adapt... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | BSD-2-Clause |
private SqlNode castNode(SqlNode node, RelDataType type) {
if (node.getKind() == SqlKind.AS) {
SqlNode expression = ((SqlCall) node).getOperandList().get(0);
SqlIdentifier identifier = (SqlIdentifier) ((SqlCall) node).getOperandList().get(1);
return SqlStdOperatorTable.AS.createCall(POS, new SqlCa... | This transformer class is used to adapt expressions in
set statements (e.g.: `UNION`, `INTERSECT`, `MINUS`)
in case that the branches of the set statement contain fields in
char family which have different types.
The `char` fields which are differing from the expected `varchar` output
of the set statement will be adapt... | castNode | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | BSD-2-Clause |
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
SqlCallBinding opBinding = new SqlCallBinding(validator, scope, call);
return inferReturnType(opBinding);
} | This transformer class is used to adapt expressions in
set statements (e.g.: `UNION`, `INTERSECT`, `MINUS`)
in case that the branches of the set statement contain fields in
char family which have different types.
The `char` fields which are differing from the expected `varchar` output
of the set statement will be adapt... | deriveType | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | BSD-2-Clause |
@Override
public RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call) {
SqlCallBinding opBinding = new SqlCallBinding(validator, scope, call);
return inferReturnType(opBinding);
} | This transformer class is used to adapt expressions in
set statements (e.g.: `UNION`, `INTERSECT`, `MINUS`)
in case that the branches of the set statement contain fields in
char family which have different types.
The `char` fields which are differing from the expected `varchar` output
of the set statement will be adapt... | deriveType | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | BSD-2-Clause |
private static SqlDataTypeSpec getSqlDataTypeSpec(RelDataType relDataType) {
final SqlTypeNameSpec typeNameSpec = new SqlBasicTypeNameSpec(relDataType.getSqlTypeName(),
relDataType.getPrecision(), relDataType.getScale(), null, ZERO);
return new SqlDataTypeSpec(typeNameSpec, ZERO);
} | This transformer class is used to adapt expressions in
set statements (e.g.: `UNION`, `INTERSECT`, `MINUS`)
in case that the branches of the set statement contain fields in
char family which have different types.
The `char` fields which are differing from the expected `varchar` output
of the set statement will be adapt... | getSqlDataTypeSpec | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnionSqlCallTransformer.java | BSD-2-Clause |
@Override
protected boolean condition(SqlCall sqlCall) {
return sqlCall.getOperator() instanceof CoralSqlUnnestOperator;
} | This class implements the transformation of SqlCalls with UNNEST operator to their
corresponding Trino-compatible versions.
When expanding an array of type struct, Coral IR returns a row set of a single column. This transformer
wraps the unnest operand with an additional ROW to enable the equivalent operation in Trino... | condition | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnnestOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnnestOperatorTransformer.java | BSD-2-Clause |
@Override
protected SqlCall transform(SqlCall sqlCall) {
CoralSqlUnnestOperator operator = (CoralSqlUnnestOperator) sqlCall.getOperator();
SqlNode unnestOperand = sqlCall.operand(0);
// Transform UNNEST(fieldName) to UNNEST(TRANSFORM(fieldName, x -> ROW(x)))
if (operator.getRelDataType() != null) {
... | This class implements the transformation of SqlCalls with UNNEST operator to their
corresponding Trino-compatible versions.
When expanding an array of type struct, Coral IR returns a row set of a single column. This transformer
wraps the unnest operand with an additional ROW to enable the equivalent operation in Trino... | transform | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnnestOperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/rel2trino/transformers/UnnestOperatorTransformer.java | BSD-2-Clause |
public static OperatorTransformer of(@Nonnull String fromOperatorName, @Nonnull SqlOperator targetOperator,
@Nullable String operandTransformers, @Nullable String resultTransformer, @Nullable String operatorTransformers) {
List<JsonObject> operands = null;
JsonObject result = null;
List<JsonObject> op... | Creates a new transformer.
@param fromOperatorName Name of the function associated with this Operator in the input IR
@param targetOperator Operator in the target language
@param operandTransformers JSON string representing the operand transformations,
null for identity transformations
@para... | of | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | BSD-2-Clause |
public SqlNode transformCall(List<SqlNode> sourceOperands) {
final SqlOperator newTargetOperator = transformTargetOperator(targetOperator, sourceOperands);
if (newTargetOperator == null || newTargetOperator.getName().isEmpty()) {
String operands = sourceOperands.stream().map(SqlNode::toString).collect(Col... | Transforms a call to the source operator.
@param sourceOperands Source operands
@return An expression calling the target operator that is equivalent to the source operator call | transformCall | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | BSD-2-Clause |
private List<SqlNode> transformOperands(List<SqlNode> sourceOperands) {
if (operandTransformers == null) {
return sourceOperands;
}
final List<SqlNode> sources = new ArrayList<>();
// Add a dummy expression for input 0
sources.add(null);
sources.addAll(sourceOperands);
final List<SqlNo... | Transforms a call to the source operator.
@param sourceOperands Source operands
@return An expression calling the target operator that is equivalent to the source operator call | transformOperands | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | BSD-2-Clause |
private SqlNode transformResult(SqlNode result, List<SqlNode> sourceOperands) {
if (resultTransformer == null) {
return result;
}
final List<SqlNode> sources = new ArrayList<>();
// Result will be input 0
sources.add(result);
sources.addAll(sourceOperands);
return transformExpression(r... | Transforms a call to the source operator.
@param sourceOperands Source operands
@return An expression calling the target operator that is equivalent to the source operator call | transformResult | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | BSD-2-Clause |
private SqlOperator transformTargetOperator(SqlOperator operator, List<SqlNode> sourceOperands) {
if (operatorTransformers == null) {
return operator;
}
for (JsonObject operatorTransformer : operatorTransformers) {
if (!operatorTransformer.has(REGEX) || !operatorTransformer.has(INPUT) || !opera... | Returns a SqlOperator with a function name based on the value of the source operands. | transformTargetOperator | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | BSD-2-Clause |
private static List<JsonObject> parseJsonObjectsFromString(String s) {
List<JsonObject> objects = new ArrayList<>();
JsonArray transformerArray = new JsonParser().parse(s).getAsJsonArray();
for (JsonElement object : transformerArray) {
objects.add(object.getAsJsonObject());
}
return objects;
... | Creates an ArrayList of JsonObjects from a string input.
The input string must be a serialized JSON array. | parseJsonObjectsFromString | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/OperatorTransformer.java | BSD-2-Clause |
@Override
public SqlNode visit(final SqlCall call) {
final String operatorName = call.getOperator().getName();
final OperatorTransformer transformer = Trino2CoralOperatorTransformerMap
.getOperatorTransformer(operatorName.toLowerCase(Locale.ROOT), call.operandCount());
if (transformer == null) {... | Rewrites the SqlNode tree to replace Trino SQL operators with Coral IR to obtain a Coral-compatible plan. | visit | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorConverter.java | BSD-2-Clause |
public static OperatorTransformer getOperatorTransformer(String trinoOpName, int numOperands) {
return TRANSFORMER_MAP.get(getKey(trinoOpName, numOperands));
} | Gets TrinoCalciteOperatorTransformer for a given Trino SQL Operator.
@param trinoOpName Name of Trino SQL operator
@param numOperands Number of operands
@return {@link OperatorTransformer} object | getOperatorTransformer | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMap.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMap.java | BSD-2-Clause |
static void createTransformerMapEntry(Map<String, OperatorTransformer> transformerMap, SqlOperator trinoOp,
int numOperands, String calciteOperatorName) {
createTransformerMapEntry(transformerMap, trinoOp, numOperands, calciteOperatorName, null, null);
} | Creates a mapping for Trino SqlOperator name to TrinoCalciteOperatorTransformer.
@param transformerMap Map to store the result
@param trinoOp Trino SQL operator
@param numOperands Number of operands
@param calciteOperatorName Name of Calcite Operator | createTransformerMapEntry | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | BSD-2-Clause |
static void createTransformerMapEntry(Map<String, OperatorTransformer> transformerMap, SqlOperator trinoOp,
int numOperands, String calciteOperatorName, String operandTransformer, String resultTransformer) {
createTransformerMapEntry(transformerMap, trinoOp, numOperands,
createOperator(calciteOperator... | Creates a mapping from Trino SqlOperator name to Calcite Operator with Calcite Operator name, operands transformer, and result transformers.
To construct Calcite SqlOperator from Calcite Operator name, this method reuses the return type inference from trinoOp,
assuming equivalence.
@param transformerMap Map to store t... | createTransformerMapEntry | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | BSD-2-Clause |
static void createTransformerMapEntry(Map<String, OperatorTransformer> transformerMap, SqlOperator trinoOp,
int numOperands, SqlOperator calciteSqlOperator, String operandTransformer, String resultTransformer) {
transformerMap.put(getKey(trinoOp.getName(), numOperands),
OperatorTransformer.of(trinoOp... | Creates a mapping from Trino SqlOperator name to Calcite UDF with Calcite SqlOperator, operands transformer, and result transformers.
@param transformerMap Map to store the result
@param trinoOp Trino SQL operator
@param numOperands Number of operands
@param calciteSqlOperator The Calcite Sql Operator that is used as ... | createTransformerMapEntry | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | BSD-2-Clause |
static SqlOperator createOperator(String functionName, SqlReturnTypeInference returnTypeInference,
SqlOperandTypeChecker operandTypeChecker) {
return new SqlUserDefinedFunction(new SqlIdentifier(functionName, SqlParserPos.ZERO), returnTypeInference, null,
operandTypeChecker, null, null);
} | Creates a mapping from Trino SqlOperator name to Calcite UDF with Calcite SqlOperator, operands transformer, and result transformers.
@param transformerMap Map to store the result
@param trinoOp Trino SQL operator
@param numOperands Number of operands
@param calciteSqlOperator The Calcite Sql Operator that is used as ... | createOperator | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | BSD-2-Clause |
static String getKey(String trinoOpName, int numOperands) {
return trinoOpName + "_" + numOperands;
} | Creates a mapping from Trino SqlOperator name to Calcite UDF with Calcite SqlOperator, operands transformer, and result transformers.
@param transformerMap Map to store the result
@param trinoOp Trino SQL operator
@param numOperands Number of operands
@param calciteSqlOperator The Calcite Sql Operator that is used as ... | getKey | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/Trino2CoralOperatorTransformerMapUtils.java | BSD-2-Clause |
public RelRoot convertQuery(SqlNode query, final boolean needsValidation, final boolean top) {
if (needsValidation) {
query = validator.validate(query);
}
RelMetadataQuery.THREAD_PROVIDERS.set(JaninoRelMetadataProvider.of(cluster.getMetadataProvider()));
RelNode result = convertQueryRecursive(que... | Class to convert Trino SQL to Calcite RelNode. This class
specializes the functionality provided by {@link SqlToRelConverter}. | convertQuery | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoSqlToRelConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoSqlToRelConverter.java | BSD-2-Clause |
@Override
protected void convertFrom(Blackboard bb, SqlNode from) {
if (from == null) {
super.convertFrom(bb, from);
return;
}
switch (from.getKind()) {
case UNNEST:
convertUnnestFrom(bb, from);
break;
default:
super.convertFrom(bb, from);
break;
... | Class to convert Trino SQL to Calcite RelNode. This class
specializes the functionality provided by {@link SqlToRelConverter}. | convertFrom | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoSqlToRelConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoSqlToRelConverter.java | BSD-2-Clause |
private void convertUnnestFrom(Blackboard bb, SqlNode from) {
final SqlCall call;
call = (SqlCall) from;
final List<SqlNode> nodes = call.getOperandList();
final SqlUnnestOperator operator = (SqlUnnestOperator) call.getOperator();
// FIXME: base class calls 'replaceSubqueries for operands here but t... | Class to convert Trino SQL to Calcite RelNode. This class
specializes the functionality provided by {@link SqlToRelConverter}. | convertUnnestFrom | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoSqlToRelConverter.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoSqlToRelConverter.java | BSD-2-Clause |
@Override
public RelRoot expandView(RelDataType rowType, String queryString, List<String> schemaPath, List<String> viewPath) {
Preconditions.checkNotNull(viewPath);
Preconditions.checkState(!viewPath.isEmpty());
String dbName = Util.last(schemaPath);
String tableName = viewPath.get(0);
SqlNode s... | Instantiates a new Trino view expander.
@param trinoToRelConverter Trino to Rel converter | expandView | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoViewExpander.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/TrinoViewExpander.java | BSD-2-Clause |
private SqlCall getUnresolvedFunction(String functionName, List<SqlNode> operands) {
SqlIdentifier functionIdentifier = CalciteUtil.createSqlIdentifier(SqlParserPos.ZERO, functionName);
return createCall(new SqlUnresolvedFunction(functionIdentifier, null, null, null, null, USER_DEFINED_FUNCTION),
operan... | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | getUnresolvedFunction | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
private SqlCall getCall(SqlOperator operator, Node node, ParserVisitorContext context) {
if (operator == null) {
throw new UnhandledASTNodeException(node, UNSUPPORTED_EXCEPTION_MSG);
}
return operator.createCall(getPos(node), getChildSqlNodeList(node, context).getList());
} | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | getCall | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitCurrentTime(CurrentTime node, ParserVisitorContext context) {
SqlParserPos pos = getPos(node);
switch (node.getFunction()) {
case TIME:
return createCall(CURRENT_TIME, Collections.emptyList(), pos);
case DATE:
return createCall(CURRENT_DATE, Collect... | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitCurrentTime | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitExtract(Extract node, ParserVisitorContext context) {
TimeUnit unit = TIME_UNIT_MAP.get(node.getField().name());
if (unit == null) {
throw new UnhandledASTNodeException(node, UNSUPPORTED_EXCEPTION_MSG);
}
return createCall(EXTRACT,
Arrays.asList(new SqlIn... | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitExtract | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitArithmeticBinary(ArithmeticBinaryExpression node, ParserVisitorContext context) {
return getCall(OPERATOR_MAP.get(node.getOperator().getValue()), node, context);
} | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitArithmeticBinary | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitBetweenPredicate(BetweenPredicate node, ParserVisitorContext context) {
return BETWEEN.createCall(getPos(node), getChildSqlNodeList(node, context).getList());
} | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitBetweenPredicate | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitCoalesceExpression(CoalesceExpression node, ParserVisitorContext context) {
return COALESCE.createCall(getPos(node), getChildSqlNodeList(node, context).getList());
} | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitCoalesceExpression | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitComparisonExpression(ComparisonExpression node, ParserVisitorContext context) {
return getCall(OPERATOR_MAP.get(node.getOperator().getValue()), node, context);
} | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitComparisonExpression | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
@Override
protected SqlNode visitDoubleLiteral(DoubleLiteral node, ParserVisitorContext context) {
return CalciteUtil.createLiteralNumber(node.getValue(), getPos(node));
} | It's used for most of the functions in the presto query. The unresolved call will be resolved in validation flow. | visitDoubleLiteral | java | linkedin/coral | coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | https://github.com/linkedin/coral/blob/master/coral-trino/src/main/java/com/linkedin/coral/trino/trino2rel/parsetree/ParseTreeBuilder.java | BSD-2-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.