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 @@ -29,6 +29,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 @@ -271,4 +272,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 @@ -234,13 +234,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 @@ -71,15 +71,15 @@ public void testSimplify() {
assertRewrite(new Cast(tinyIntLiteral, TinyIntType.INSTANCE), tinyIntLiteral);
// cast tinyint as decimalv2(3,0)
assertRewrite(new Cast(tinyIntLiteral, DecimalV2Type.forType(TinyIntType.INSTANCE)),
new DecimalLiteral(new BigDecimal(12)));
new DecimalLiteral(DecimalV2Type.forType(TinyIntType.INSTANCE), new BigDecimal(12)));

assertRewrite(new Cast(tinyIntLiteral, DecimalV2Type.createDecimalV2Type(5, 1)),
new DecimalLiteral(DecimalV2Type.createDecimalV2Type(5, 1),
new BigDecimal("12.0")));

// cast tinyint as decimalv3(3,0)
assertRewrite(new Cast(tinyIntLiteral, DecimalV3Type.forType(TinyIntType.INSTANCE)),
new DecimalV3Literal(new BigDecimal(12)));
new DecimalV3Literal(DecimalV3Type.forType(TinyIntType.INSTANCE), new BigDecimal(12)));
// cast tinyint as decimalv3(5,1)
assertRewrite(new Cast(tinyIntLiteral, DecimalV3Type.createDecimalV3Type(5, 1)),
new DecimalV3Literal(DecimalV3Type.createDecimalV3Type(5, 1),
Expand Down Expand Up @@ -108,20 +108,20 @@ public void testSimplify() {
assertRewrite(new Cast(intLiteral, IntegerType.INSTANCE), intLiteral);
// cast int as decimalv2
assertRewrite(new Cast(intLiteral, DecimalV2Type.forType(IntegerType.INSTANCE)),
new DecimalLiteral(new BigDecimal(30000000)));
new DecimalLiteral(DecimalV2Type.forType(IntegerType.INSTANCE), new BigDecimal(30000000)));
// cast int as decimalv3
assertRewrite(new Cast(intLiteral, DecimalV3Type.forType(IntegerType.INSTANCE)),
new DecimalV3Literal(new BigDecimal(30000000)));
new DecimalV3Literal(DecimalV3Type.forType(IntegerType.INSTANCE), new BigDecimal(30000000)));

Expression bigIntLiteral = new BigIntLiteral(30000000000L);
// cast bigint as bigint
assertRewrite(new Cast(bigIntLiteral, BigIntType.INSTANCE), bigIntLiteral);
// cast bigint as decimalv2
assertRewrite(new Cast(bigIntLiteral, DecimalV2Type.forType(BigIntType.INSTANCE)),
new DecimalLiteral(new BigDecimal(30000000000L)));
new DecimalLiteral(DecimalV2Type.forType(BigIntType.INSTANCE), new BigDecimal(30000000000L)));
// cast bigint as decimalv3
assertRewrite(new Cast(bigIntLiteral, DecimalV3Type.forType(BigIntType.INSTANCE)),
new DecimalV3Literal(new BigDecimal(30000000000L)));
new DecimalV3Literal(DecimalV3Type.forType(BigIntType.INSTANCE), new BigDecimal(30000000000L)));

Expression varcharLiteral = new VarcharLiteral("12345");
// cast varchar(5) as varchar(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,32 +416,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
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,18 @@ suite("agg_window_project") {
sql """select a, a aa, row_number() over (partition by b) from test_window_table2;"""

sql "DROP TABLE IF EXISTS test_window_table2;"

sql """DROP TABLE IF EXISTS test_window_union_t1;"""
sql """DROP TABLE IF EXISTS test_window_union_t2;"""
sql """create table test_window_union_t1 (item_code int) distributed by hash(item_code) properties("replication_num"="1");"""
sql """insert into test_window_union_t1 values(1), (11), (111);"""

sql """create table test_window_union_t2 (orderamount_lj_tq decimalv3(38,5)) distributed by hash(orderamount_lj_tq) properties("replication_num"="1");"""
sql """insert into test_window_union_t2 values(123456.12345), (223456.12345), (323456.12345);"""

sql """
SELECT 0 AS `amount_dh_real_tq`, (CASE WHEN `t`.`item_code` IS NOT NULL THEN (1.0 / count(1) OVER (PARTITION BY `t`.`item_code`)) ELSE 0.0 END) AS `item_qty_dh_order` FROM `test_window_union_t1` t
UNION ALL
SELECT `t`.`orderamount_lj_tq` AS `amount_dh_real_tq`, 0 AS `item_qty_dh_order` FROM `test_window_union_t2` t ;
"""
}