Skip to content

Commit

Permalink
[VL] Use standard TPCH datatypes and queries and add UT for nested de…
Browse files Browse the repository at this point in the history
…cimal arithmetic (apache#2918)
  • Loading branch information
marin-ma authored Aug 31, 2023
1 parent fbaf8d7 commit e355c42
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 21 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ select
from
lineitem
where
l_shipdate <= '1998-9-01'
l_shipdate <= date '1998-12-01' - interval '90' day
group by
l_returnflag,
l_linestatus
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q03.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ where
c_mktsegment = 'BUILDING'
and c_custkey = o_custkey
and l_orderkey = o_orderkey
and o_orderdate < '1995-03-15'
and l_shipdate > '1995-03-15'
and o_orderdate < date '1995-03-15'
and l_shipdate > date '1995-03-15'
group by
l_orderkey,
o_orderdate,
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q04.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ select
from
orders
where
o_orderdate >= '1993-07-01'
and o_orderdate < '1993-10-01'
o_orderdate >= date '1993-07-01'
and o_orderdate < date '1993-07-01' + interval '3' month
and exists (
select
*
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q05.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ where
and s_nationkey = n_nationkey
and n_regionkey = r_regionkey
and r_name = 'ASIA'
and o_orderdate >= '1994-01-01'
and o_orderdate < '1995-01-01'
and o_orderdate >= date '1994-01-01'
and o_orderdate < date '1994-01-01' + interval '1' year
group by
n_name
order by
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q06.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ select
from
lineitem
where
l_shipdate >= '1994-01-01'
and l_shipdate < '1995-01-01'
l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
and l_discount between .06 - 0.01 and .06 + 0.01
and l_quantity < 24
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ from
(n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
)
and l_shipdate between '1995-01-01' and '1996-12-31'
and l_shipdate between date '1995-01-01' and date '1996-12-31'
) as shipping
group by
supp_nation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ from
and n1.n_regionkey = r_regionkey
and r_name = 'AMERICA'
and s_nationkey = n2.n_nationkey
and o_orderdate between '1995-01-01' and '1996-12-31'
and o_orderdate between date '1995-01-01' and date '1996-12-31'
and p_type = 'ECONOMY ANODIZED STEEL'
) as all_nations
group by
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q10.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ from
where
c_custkey = o_custkey
and l_orderkey = o_orderkey
and o_orderdate >= '1993-10-01'
and o_orderdate < '1994-01-01'
and o_orderdate >= date '1993-10-01'
and o_orderdate < date '1993-10-01' + interval '3' month
and l_returnflag = 'R'
and c_nationkey = n_nationkey
group by
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q12.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ where
and l_shipmode in ('MAIL', 'SHIP')
and l_commitdate < l_receiptdate
and l_shipdate < l_commitdate
and l_receiptdate >= '1994-01-01'
and l_receiptdate < '1995-01-01'
and l_receiptdate >= date '1994-01-01'
and l_receiptdate < date '1994-01-01' + interval '1' year
group by
l_shipmode
order by
Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q14.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ from
part
where
l_partkey = p_partkey
and l_shipdate >= '1995-09-01'
and l_shipdate < '1995-10-01'
and l_shipdate >= date '1995-09-01'
and l_shipdate < date '1995-09-01' + interval '1' month
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q15.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ with revenue0 as
from
lineitem
where
l_shipdate >= '1996-01-01'
and l_shipdate < '1996-04-01'
l_shipdate >= date '1996-01-01'
and l_shipdate < date '1996-01-01' + interval '3' month
group by
l_suppkey)

Expand Down
4 changes: 2 additions & 2 deletions backends-velox/src/test/resources/tpch-queries-velox/q20.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ where
where
l_partkey = ps_partkey
and l_suppkey = ps_suppkey
and l_shipdate >= '1994-01-01'
and l_shipdate < '1995-01-01'
and l_shipdate >= date '1994-01-01'
and l_shipdate < date '1994-01-01' + interval '1' year
)
)
and s_nationkey = n_nationkey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,25 @@ class TestOperator extends WholeStageTransformerSuite {
}
}

test("nested decimal arithmetics") {
runQueryAndCompare("""
|SELECT
| l_orderkey,
| SUM(
| (l_extendedprice * (1 - l_discount)) +
| (l_extendedprice * (1 - l_discount) * 0.05)
| ) AS total_revenue_with_tax
|FROM
| lineitem
|GROUP BY
| l_orderkey
|ORDER BY
| l_orderkey
|""".stripMargin) {
checkOperatorMatch[HashAggregateExecTransformer]
}
}

test("Cast double to decimal") {
val d = 0.034567890
val df = Seq(d, d, d, d, d, d, d, d, d, d).toDF("DecimalCol")
Expand Down
6 changes: 6 additions & 0 deletions cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,12 @@ bool SubstraitToVeloxPlanValidator::validateCast(
logValidateMsg("native validation failed due to: Casting from DATE to TIMESTAMP is not supported.");
return false;
}
if (toType->kind() != TypeKind::VARCHAR) {
logValidateMsg(fmt::format(
"native validation failed due to: Casting from DATE to {} is not supported.", toType->toString()));
return false;
}
break;
}
case TypeKind::TIMESTAMP: {
logValidateMsg(
Expand Down

0 comments on commit e355c42

Please sign in to comment.