Skip to content

Commit 82fcef8

Browse files
committed
Remove Long, Decimal, Boolean and Double literals
Replace them with GenericLiteral. The values are stored as native carrier type instead of String inside the object.
1 parent 2008196 commit 82fcef8

File tree

186 files changed

+2277
-2658
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+2277
-2658
lines changed

core/trino-main/src/main/java/io/trino/cost/FilterStatsCalculator.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.trino.sql.ir.ComparisonExpression;
2626
import io.trino.sql.ir.Expression;
2727
import io.trino.sql.ir.FunctionCall;
28+
import io.trino.sql.ir.GenericLiteral;
2829
import io.trino.sql.ir.InPredicate;
2930
import io.trino.sql.ir.IrUtils;
3031
import io.trino.sql.ir.IrVisitor;
@@ -260,16 +261,20 @@ private PlanNodeStatsEstimate estimateLogicalOr(List<Expression> terms)
260261
}
261262

262263
@Override
263-
protected PlanNodeStatsEstimate visitBooleanLiteral(BooleanLiteral node, Void context)
264+
protected PlanNodeStatsEstimate visitGenericLiteral(GenericLiteral node, Void context)
264265
{
265-
if (node.getValue()) {
266-
return input;
266+
if (node.getType().equals(BOOLEAN)) {
267+
if (Boolean.parseBoolean(node.getValue())) {
268+
return input;
269+
}
270+
271+
PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.builder();
272+
result.setOutputRowCount(0.0);
273+
input.getSymbolsWithKnownStatistics().forEach(symbol -> result.addSymbolStatistics(symbol, SymbolStatsEstimate.zero()));
274+
return result.build();
267275
}
268276

269-
PlanNodeStatsEstimate.Builder result = PlanNodeStatsEstimate.builder();
270-
result.setOutputRowCount(0.0);
271-
input.getSymbolsWithKnownStatistics().forEach(symbol -> result.addSymbolStatistics(symbol, SymbolStatsEstimate.zero()));
272-
return result.build();
277+
return super.visitGenericLiteral(node, context);
273278
}
274279

275280
@Override

core/trino-main/src/main/java/io/trino/sql/DynamicFilters.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import io.trino.spi.type.BooleanType;
3131
import io.trino.spi.type.Type;
3232
import io.trino.spi.type.VarcharType;
33-
import io.trino.sql.ir.BooleanLiteral;
3433
import io.trino.sql.ir.Cast;
3534
import io.trino.sql.ir.ComparisonExpression;
3635
import io.trino.sql.ir.Expression;
3736
import io.trino.sql.ir.FunctionCall;
37+
import io.trino.sql.ir.GenericLiteral;
3838
import io.trino.sql.ir.StringLiteral;
3939
import io.trino.sql.ir.SymbolReference;
4040
import io.trino.sql.planner.BuiltinFunctionCallBuilder;
@@ -179,8 +179,8 @@ public static Optional<Descriptor> getDescriptor(Expression expression)
179179
String id = ((StringLiteral) idExpression).getValue();
180180

181181
Expression nullAllowedExpression = arguments.get(3);
182-
checkArgument(nullAllowedExpression instanceof BooleanLiteral, "nullAllowedExpression is expected to be an instance of BooleanLiteral: %s", nullAllowedExpression.getClass().getSimpleName());
183-
boolean nullAllowed = ((BooleanLiteral) nullAllowedExpression).getValue();
182+
checkArgument(nullAllowedExpression instanceof GenericLiteral literal && literal.getType().equals(BooleanType.BOOLEAN), "nullAllowedExpression is expected to be a boolean constant: %s", nullAllowedExpression.getClass().getSimpleName());
183+
boolean nullAllowed = Boolean.parseBoolean(((GenericLiteral) nullAllowedExpression).getValue());
184184
return Optional.of(new Descriptor(new DynamicFilterId(id), probeSymbol, operator, nullAllowed));
185185
}
186186

core/trino-main/src/main/java/io/trino/sql/ir/BooleanLiteral.java

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,12 @@
1313
*/
1414
package io.trino.sql.ir;
1515

16-
import com.fasterxml.jackson.annotation.JsonCreator;
17-
import com.fasterxml.jackson.annotation.JsonProperty;
18-
import com.google.common.collect.ImmutableList;
19-
20-
import java.util.List;
21-
import java.util.Objects;
16+
import static io.trino.spi.type.BooleanType.BOOLEAN;
2217

2318
public final class BooleanLiteral
24-
extends Literal
2519
{
26-
public static final BooleanLiteral TRUE_LITERAL = new BooleanLiteral(true);
27-
public static final BooleanLiteral FALSE_LITERAL = new BooleanLiteral(false);
28-
29-
private final boolean value;
30-
31-
@JsonCreator
32-
public BooleanLiteral(boolean value)
33-
{
34-
this.value = value;
35-
}
36-
37-
@JsonProperty
38-
public boolean getValue()
39-
{
40-
return value;
41-
}
42-
43-
@Override
44-
public <R, C> R accept(IrVisitor<R, C> visitor, C context)
45-
{
46-
return visitor.visitBooleanLiteral(this, context);
47-
}
48-
49-
@Override
50-
public List<? extends Expression> getChildren()
51-
{
52-
return ImmutableList.of();
53-
}
54-
55-
@Override
56-
public int hashCode()
57-
{
58-
return Objects.hash(value);
59-
}
60-
61-
@Override
62-
public boolean equals(Object obj)
63-
{
64-
if (this == obj) {
65-
return true;
66-
}
67-
if (obj == null || getClass() != obj.getClass()) {
68-
return false;
69-
}
70-
BooleanLiteral other = (BooleanLiteral) obj;
71-
return Objects.equals(this.value, other.value);
72-
}
20+
public static final GenericLiteral TRUE_LITERAL = GenericLiteral.constant(BOOLEAN, true);
21+
public static final GenericLiteral FALSE_LITERAL = GenericLiteral.constant(BOOLEAN, false);
7322

74-
@Override
75-
public String toString()
76-
{
77-
return Boolean.toString(value);
78-
}
23+
private BooleanLiteral() {}
7924
}

core/trino-main/src/main/java/io/trino/sql/ir/DecimalLiteral.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

core/trino-main/src/main/java/io/trino/sql/ir/DoubleLiteral.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

core/trino-main/src/main/java/io/trino/sql/ir/Expression.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
@JsonSubTypes.Type(value = Cast.class, name = "cast"),
3333
@JsonSubTypes.Type(value = CoalesceExpression.class, name = "coalesce"),
3434
@JsonSubTypes.Type(value = ComparisonExpression.class, name = "comparison"),
35-
@JsonSubTypes.Type(value = DecimalLiteral.class, name = "decimal"),
36-
@JsonSubTypes.Type(value = DoubleLiteral.class, name = "double"),
3735
@JsonSubTypes.Type(value = FunctionCall.class, name = "call"),
3836
@JsonSubTypes.Type(value = GenericLiteral.class, name = "constant"),
3937
@JsonSubTypes.Type(value = IfExpression.class, name = "if"),
@@ -43,7 +41,6 @@
4341
@JsonSubTypes.Type(value = IsNullPredicate.class, name = "isNull"),
4442
@JsonSubTypes.Type(value = LambdaExpression.class, name = "lambda"),
4543
@JsonSubTypes.Type(value = LogicalExpression.class, name = "logicalBinary"),
46-
@JsonSubTypes.Type(value = LongLiteral.class, name = "long"),
4744
@JsonSubTypes.Type(value = NotExpression.class, name = "not"),
4845
@JsonSubTypes.Type(value = NullIfExpression.class, name = "nullif"),
4946
@JsonSubTypes.Type(value = NullLiteral.class, name = "null"),

core/trino-main/src/main/java/io/trino/sql/ir/ExpressionFormatter.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
import com.google.common.collect.ImmutableList;
1818
import com.google.common.io.BaseEncoding;
1919

20-
import java.text.DecimalFormat;
21-
import java.text.DecimalFormatSymbols;
2220
import java.util.List;
23-
import java.util.Locale;
2421
import java.util.Optional;
2522
import java.util.function.Function;
2623

@@ -30,9 +27,6 @@
3027

3128
public final class ExpressionFormatter
3229
{
33-
private static final ThreadLocal<DecimalFormat> doubleFormatter = ThreadLocal.withInitial(
34-
() -> new DecimalFormat("0.###################E0###", new DecimalFormatSymbols(Locale.US)));
35-
3630
private ExpressionFormatter() {}
3731

3832
public static String formatExpression(Expression expression)
@@ -68,14 +62,6 @@ protected String visitExpression(Expression node, Void context)
6862
throw new UnsupportedOperationException("not yet implemented: %s.visit%s".formatted(getClass().getName(), node.getClass().getSimpleName()));
6963
}
7064

71-
@Override
72-
protected String visitBooleanLiteral(BooleanLiteral node, Void context)
73-
{
74-
return literalFormatter
75-
.map(formatter -> formatter.apply(node))
76-
.orElseGet(() -> String.valueOf(node.getValue()));
77-
}
78-
7965
@Override
8066
protected String visitStringLiteral(StringLiteral node, Void context)
8167
{
@@ -106,31 +92,6 @@ protected String visitSubscriptExpression(SubscriptExpression node, Void context
10692
return formatExpression(node.getBase()) + "[" + formatExpression(node.getIndex()) + "]";
10793
}
10894

109-
@Override
110-
protected String visitLongLiteral(LongLiteral node, Void context)
111-
{
112-
return literalFormatter
113-
.map(formatter -> formatter.apply(node))
114-
.orElseGet(() -> Long.toString(node.getValue()));
115-
}
116-
117-
@Override
118-
protected String visitDoubleLiteral(DoubleLiteral node, Void context)
119-
{
120-
return literalFormatter
121-
.map(formatter -> formatter.apply(node))
122-
.orElseGet(() -> doubleFormatter.get().format(node.getValue()));
123-
}
124-
125-
@Override
126-
protected String visitDecimalLiteral(DecimalLiteral node, Void context)
127-
{
128-
return literalFormatter
129-
.map(formatter -> formatter.apply(node))
130-
// TODO return node value without "DECIMAL '..'" when FeaturesConfig#parseDecimalLiteralsAsDouble switch is removed
131-
.orElseGet(() -> "DECIMAL '" + node.getValue() + "'");
132-
}
133-
13495
@Override
13596
protected String visitGenericLiteral(GenericLiteral node, Void context)
13697
{

0 commit comments

Comments
 (0)