Skip to content

Commit 232916b

Browse files
committed
Remove redundant cast
1 parent 739aeff commit 232916b

File tree

8 files changed

+15
-22
lines changed

8 files changed

+15
-22
lines changed

core/trino-main/src/main/java/io/trino/json/PathEvaluationVisitor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ private static TypedValue getDouble(TypedValue typedValue)
723723
if (type instanceof DecimalType decimalType) {
724724
int precision = decimalType.getPrecision();
725725
int scale = decimalType.getScale();
726-
if (((DecimalType) type).isShort()) {
726+
if (decimalType.isShort()) {
727727
long tenToScale = longTenToNth(DecimalConversions.intScale(scale));
728728
return new TypedValue(DOUBLE, shortDecimalToDouble(typedValue.getLongValue(), precision, scale, tenToScale));
729729
}
@@ -852,7 +852,7 @@ protected List<Object> visitIrKeyValueMethod(IrKeyValueMethod node, PathEvaluati
852852

853853
// non-unique keys are not supported. if they were, we should follow the spec here on handling them.
854854
// see the comment in `visitIrMemberAccessor` method.
855-
((JsonNode) object).fields().forEachRemaining(
855+
jsonNode.fields().forEachRemaining(
856856
field -> outputSequence.add(new ObjectNode(
857857
JsonNodeFactory.instance,
858858
ImmutableMap.of(

core/trino-main/src/main/java/io/trino/sql/planner/DomainTranslator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ private Optional<ExtractionResult> tryVisitStartsWithFunction(Call node, Boolean
10731073
}
10741074

10751075
Symbol symbol = Symbol.from(target);
1076-
Slice constantPrefix = (Slice) ((Constant) prefix).value();
1076+
Slice constantPrefix = (Slice) literal.value();
10771077

10781078
return createRangeDomain(type, constantPrefix).map(domain -> new ExtractionResult(TupleDomain.withColumnDomains(ImmutableMap.of(symbol, domain)), node));
10791079
}

core/trino-main/src/main/java/io/trino/sql/planner/TranslationMap.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ private io.trino.sql.ir.Expression translate(AtTimeZone node)
849849
if (valueType instanceof TimeType type) {
850850
call = BuiltinFunctionCallBuilder.resolve(plannerContext.getMetadata())
851851
.setName("$at_timezone")
852-
.addArgument(createTimeWithTimeZoneType(type.getPrecision()), new io.trino.sql.ir.Cast(value, createTimeWithTimeZoneType(((TimeType) valueType).getPrecision())))
852+
.addArgument(createTimeWithTimeZoneType(type.getPrecision()), new io.trino.sql.ir.Cast(value, createTimeWithTimeZoneType(type.getPrecision())))
853853
.addArgument(timeZoneType, timeZone)
854854
.build();
855855
}
@@ -863,7 +863,7 @@ else if (valueType instanceof TimeWithTimeZoneType) {
863863
else if (valueType instanceof TimestampType type) {
864864
call = BuiltinFunctionCallBuilder.resolve(plannerContext.getMetadata())
865865
.setName("at_timezone")
866-
.addArgument(createTimestampWithTimeZoneType(type.getPrecision()), new io.trino.sql.ir.Cast(value, createTimestampWithTimeZoneType(((TimestampType) valueType).getPrecision())))
866+
.addArgument(createTimestampWithTimeZoneType(type.getPrecision()), new io.trino.sql.ir.Cast(value, createTimestampWithTimeZoneType(type.getPrecision())))
867867
.addArgument(timeZoneType, timeZone)
868868
.build();
869869
}

core/trino-main/src/main/java/io/trino/sql/planner/optimizations/PlanNodeDecorrelator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ private boolean isSimpleInjectiveCast(Expression expression)
542542
Symbol sourceSymbol = Symbol.from(cast.expression());
543543

544544
Type sourceType = sourceSymbol.type();
545-
Type targetType = ((Cast) expression).type();
545+
Type targetType = cast.type();
546546

547547
return typeCoercion.isInjectiveCoercion(sourceType, targetType);
548548
}

core/trino-parser/src/main/java/io/trino/sql/SqlFormatter.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,7 @@ protected Void visitTableArgument(TableFunctionTableArgument node, Integer inden
527527
builder.append("TABLE(");
528528
process(unaliased, indent);
529529
builder.append(")");
530-
if (relation instanceof AliasedRelation) {
531-
AliasedRelation aliasedRelation = (AliasedRelation) relation;
530+
if (relation instanceof AliasedRelation aliasedRelation) {
532531
builder.append(" AS ")
533532
.append(formatName(aliasedRelation.getAlias()));
534533
appendAliasColumns(builder, aliasedRelation.getColumnNames());
@@ -851,14 +850,12 @@ protected Void visitJoin(Join node, Integer indent)
851850
process(node.getRight(), indent);
852851

853852
if (node.getType() != Join.Type.CROSS && node.getType() != Join.Type.IMPLICIT) {
854-
if (criteria instanceof JoinUsing) {
855-
JoinUsing using = (JoinUsing) criteria;
853+
if (criteria instanceof JoinUsing using) {
856854
builder.append(" USING (")
857855
.append(Joiner.on(", ").join(using.getColumns()))
858856
.append(")");
859857
}
860-
else if (criteria instanceof JoinOn) {
861-
JoinOn on = (JoinOn) criteria;
858+
else if (criteria instanceof JoinOn on) {
862859
builder.append(" ON ")
863860
.append(formatExpression(on.getExpression()));
864861
}
@@ -1596,12 +1593,10 @@ protected Void visitCreateTable(CreateTable node, Integer indent)
15961593
String elementIndent = indentString(indent + 1);
15971594
String columnList = node.getElements().stream()
15981595
.map(element -> {
1599-
if (element instanceof ColumnDefinition) {
1600-
ColumnDefinition column = (ColumnDefinition) element;
1596+
if (element instanceof ColumnDefinition column) {
16011597
return elementIndent + formatColumnDefinition(column);
16021598
}
1603-
if (element instanceof LikeClause) {
1604-
LikeClause likeClause = (LikeClause) element;
1599+
if (element instanceof LikeClause likeClause) {
16051600
StringBuilder builder = new StringBuilder(elementIndent);
16061601
builder.append("LIKE ")
16071602
.append(formatName(likeClause.getTableName()));

core/trino-parser/src/main/java/io/trino/sql/tree/ExpressionTreeRewriter.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ private List<SortItem> rewriteSortItems(List<SortItem> sortItems, Context<C> con
544544

545545
private Window rewriteWindow(Window window, Context<C> context)
546546
{
547-
if (window instanceof WindowReference) {
548-
WindowReference windowReference = (WindowReference) window;
547+
if (window instanceof WindowReference windowReference) {
549548
Identifier rewrittenName = rewrite(windowReference.getName(), context.get());
550549
if (windowReference.getName() != rewrittenName) {
551550
return new WindowReference(rewrittenName);
@@ -986,8 +985,7 @@ protected Expression visitGenericDataType(GenericDataType node, Context<C> conte
986985
if (argument instanceof NumericParameter) {
987986
arguments.add(argument);
988987
}
989-
else if (argument instanceof TypeParameter) {
990-
TypeParameter parameter = (TypeParameter) argument;
988+
else if (argument instanceof TypeParameter parameter) {
991989
DataType value = (DataType) process(parameter.getValue(), context);
992990

993991
if (value != parameter.getValue()) {

plugin/trino-hive/src/test/java/io/trino/plugin/hive/TestHiveFileFormats.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1427,7 +1427,7 @@ else if (type instanceof CharType charType) {
14271427
if (object instanceof HiveChar) {
14281428
object = ((HiveChar) object).getValue();
14291429
}
1430-
charType.writeSlice(builder, truncateToLengthAndTrimSpaces(utf8Slice((String) object), ((CharType) type).getLength()));
1430+
charType.writeSlice(builder, truncateToLengthAndTrimSpaces(utf8Slice((String) object), charType.getLength()));
14311431
}
14321432
else if (type == DATE) {
14331433
long days = ((Date) object).toEpochDay();

plugin/trino-tpch/src/test/java/io/trino/plugin/tpch/EstimateAssertion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void assertClose(Object actual, Object expected, String comparedValue)
6363
assertThat(actual.getClass())
6464
.describedAs(comparedValue)
6565
.isEqualTo(expected.getClass());
66-
assertThat(((Slice) actual).toStringUtf8())
66+
assertThat(actualSlice.toStringUtf8())
6767
.isEqualTo(((Slice) expected).toStringUtf8());
6868
}
6969
else if (actual instanceof DoubleRange actualRange) {

0 commit comments

Comments
 (0)