Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -66,8 +66,7 @@ public Rule build() {

// 1. handle bottom projects
Set<Alias> existedAlias = ExpressionUtils.collect(outputs, Alias.class::isInstance);
Set<Expression> toBePushedDown = collectExpressionsToBePushedDown(outputs.stream()
.filter(expr -> !expr.isConstant()).collect(Collectors.toList()));
Set<Expression> toBePushedDown = collectExpressionsToBePushedDown(outputs);
NormalizeToSlotContext context = NormalizeToSlotContext.buildContext(existedAlias, toBePushedDown);
// set toBePushedDown exprs as NamedExpression, e.g. (a+1) -> Alias(a+1)
Set<NamedExpression> bottomProjects = context.pushDownToNamedExpression(toBePushedDown);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.base.Preconditions;

import java.time.LocalDateTime;
import java.util.Objects;

/**
* date time v2 literal for nereids
Expand Down Expand Up @@ -219,4 +220,19 @@ public static Expression fromJavaDateType(LocalDateTime dateTime, int precision)
dateTime.getMinute(), dateTime.getSecond(),
(dateTime.getNano() / 1000) / value * value);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
DateTimeV2Literal literal = (DateTimeV2Literal) o;
return Objects.equals(dataType, literal.dataType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,19 @@ private static void checkPrecisionAndScale(int precision, int scale, BigDecimal
precision, scale, realPrecision, realScale));
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
DecimalLiteral literal = (DecimalLiteral) o;
return Objects.equals(dataType, literal.dataType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,19 @@ private static void checkPrecisionAndScale(int precision, int scale, BigDecimal
precision, scale, realPrecision, realScale));
}
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
DecimalV3Literal literal = (DecimalV3Literal) o;
return Objects.equals(dataType, literal.dataType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ void testSimplifyCastRule() {

// decimal literal
assertRewrite(new Cast(new TinyIntLiteral((byte) 1), DecimalV2Type.createDecimalV2Type(15, 9)),
new DecimalLiteral(new BigDecimal("1.000000000")));
new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000")));
assertRewrite(new Cast(new SmallIntLiteral((short) 1), DecimalV2Type.createDecimalV2Type(15, 9)),
new DecimalLiteral(new BigDecimal("1.000000000")));
new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000")));
assertRewrite(new Cast(new IntegerLiteral(1), DecimalV2Type.createDecimalV2Type(15, 9)),
new DecimalLiteral(new BigDecimal("1.000000000")));
new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000")));
assertRewrite(new Cast(new BigIntLiteral(1L), DecimalV2Type.createDecimalV2Type(15, 9)),
new DecimalLiteral(new BigDecimal("1.000000000")));
new DecimalLiteral(DecimalV2Type.createDecimalV2Type(15, 9), new BigDecimal("1.000000000")));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,32 +426,32 @@ void testIrregularDateTimeHourMinuteSecondMicrosecond() {
void testDateTimeV2Scale() {
Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123"),
new DateTimeV2Literal("2016-07-02 00:00:00.123"));
new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123"));

Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123456"),
new DateTimeV2Literal("2016-07-02 00:00:00.123"));
new DateTimeV2Literal(DateTimeV2Type.of(3), "2016-07-02 00:00:00.123"));

Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(4), "2016-07-02 00:00:00.12345"),
new DateTimeV2Literal("2016-07-02 00:00:00.12345"));
new DateTimeV2Literal(DateTimeV2Type.of(4), "2016-07-02 00:00:00.1235"));

Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:00.12345"),
new DateTimeV2Literal("2016-07-02 00:00:00.0"));
new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:00"));

Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:00.5123"),
new DateTimeV2Literal("2016-07-02 00:00:01.0"));
new DateTimeV2Literal(DateTimeV2Type.of(0), "2016-07-02 00:00:01"));

Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-07-02 00:00:00.999999"),
new DateTimeV2Literal("2016-07-02 00:00:01.0"));
new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-07-02 00:00:01.00000"));

// test overflow
Assertions.assertEquals(
new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-12-31 23:59:59.999999"),
new DateTimeV2Literal("2017-01-01 00:00:00.0"));
new DateTimeV2Literal(DateTimeV2Type.of(5), "2017-01-01 00:00:00.00000"));
}

@Test
Expand Down