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

[Coral-Hive] Create new object for ShiftArrayIndexTransformer (#494) #498

Merged
merged 1 commit into from
Mar 14, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* 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.
*/
Expand Down Expand Up @@ -42,16 +42,19 @@ public boolean condition(SqlCall sqlCall) {
@Override
public SqlCall transform(SqlCall sqlCall) {
final SqlNode itemNode = sqlCall.getOperandList().get(1);
SqlNode newIndex;
if (itemNode instanceof SqlNumericLiteral
&& deriveRelDatatype(itemNode).getSqlTypeName().equals(SqlTypeName.INTEGER)) {
final Integer value = ((SqlNumericLiteral) itemNode).getValueAs(Integer.class);
sqlCall.setOperand(1,
SqlNumericLiteral.createExactNumeric(new BigDecimal(value + 1).toString(), itemNode.getParserPosition()));
newIndex =
SqlNumericLiteral.createExactNumeric(new BigDecimal(value + 1).toString(), itemNode.getParserPosition());
} else {
final SqlCall oneBasedIndex = SqlStdOperatorTable.PLUS.createCall(itemNode.getParserPosition(), itemNode,
newIndex = SqlStdOperatorTable.PLUS.createCall(itemNode.getParserPosition(), itemNode,
SqlNumericLiteral.createExactNumeric("1", SqlParserPos.ZERO));
sqlCall.setOperand(1, oneBasedIndex);
}
return sqlCall;
// Create new object instead of modifying the old SqlCall to avoid transforming the same object
// multiple times if it appears multiple times in SqlNode
// TODO: Add unit test to verify the necessity of creating a new object
return SqlStdOperatorTable.ITEM.createCall(SqlParserPos.ZERO, sqlCall.getOperandList().get(0), newIndex);
}
}
Loading