Skip to content

Commit

Permalink
ci: Test output consistency between constant-folding vs. rendered que…
Browse files Browse the repository at this point in the history
…ry evaluations (#18812)
  • Loading branch information
nrainer-materialize committed Apr 20, 2023
1 parent 25be1e8 commit b8874da
Show file tree
Hide file tree
Showing 12 changed files with 906 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

# use mode cockroach because it "respects the scale of a Decimal type and the precision of a floating point number"
# even though mode standard would allow easier file comparisons with the other computation mode
mode cockroach

# -------------------------------
# very small numbers
# -------------------------------

statement ok
CREATE TABLE t_using_dataflow_rendering (real1 REAL, double1 DOUBLE PRECISION, numeric1 NUMERIC);

statement ok
INSERT INTO t_using_dataflow_rendering VALUES (1e-39::real, 1e-39::double, 1e-39::numeric);

# DIFF TO CONSTANT FOLDING (SELECT on types [REAL, DOUBLE])!
# to be addressed with https://github.com/MaterializeInc/materialize/issues/15186
query RRR
SELECT * FROM t_using_dataflow_rendering
UNION ALL
SELECT SUM(real1), SUM(double1), SUM(numeric1)
FROM t_using_dataflow_rendering;
----
0 0 0.000000000000000000000000000000000000001
0.000000000000000000000000000000000000001 0.000000000000000000000000000000000000001 0.000000000000000000000000000000000000001

query T multiline
EXPLAIN SELECT * FROM t_using_dataflow_rendering;
----
Explained Query:
Get materialize.public.t_using_dataflow_rendering

EOF

# -------------------------------
# very big numbers
# -------------------------------

statement ok
DELETE FROM t_using_dataflow_rendering;

statement ok
INSERT INTO t_using_dataflow_rendering VALUES (1e38::real, 1e38::double, 1e38::numeric);

# DIFF TO CONSTANT FOLDING (SELECT on types [REAL, DOUBLE])!
# to be addressed with https://github.com/MaterializeInc/materialize/issues/15186
query RRR
SELECT * FROM t_using_dataflow_rendering
UNION ALL
SELECT SUM(real1), SUM(double1), SUM(numeric1)
FROM t_using_dataflow_rendering;
----
10141205000000000000000000000000 10141204801825835000000000000000 100000000000000000000000000000000000000
100000000000000000000000000000000000000 100000000000000000000000000000000000000 100000000000000000000000000000000000000

query T multiline
EXPLAIN SELECT * FROM t_using_dataflow_rendering;
----
Explained Query:
Get materialize.public.t_using_dataflow_rendering

EOF
66 changes: 66 additions & 0 deletions test/sqllogictest/transform/fold_vs_dataflow/1_numbers_folding.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

# use mode cockroach because it "respects the scale of a Decimal type and the precision of a floating point number"
# even though mode standard would allow easier file comparisons with the other computation mode
mode cockroach

# -------------------------------
# very small numbers
# -------------------------------

statement ok
CREATE OR REPLACE VIEW v_using_constant_folding (real1, double1, numeric1) AS
SELECT
1e-39::real, 1e-39::double, 1e-39::numeric;

query RRR
SELECT * FROM v_using_constant_folding
UNION ALL
SELECT SUM(real1), SUM(double1), SUM(numeric1)
FROM v_using_constant_folding;
----
0.000000000000000000000000000000000000001 0.000000000000000000000000000000000000001 0.000000000000000000000000000000000000001
0.000000000000000000000000000000000000001 0.000000000000000000000000000000000000001 0.000000000000000000000000000000000000001

query T multiline
EXPLAIN SELECT * FROM v_using_constant_folding;
----
Explained Query (fast path):
Constant
- (0.000000000000000000000000000000000000001, 0.000000000000000000000000000000000000001, 0.000000000000000000000000000000000000001)

EOF

# -------------------------------
# very big numbers
# -------------------------------

statement ok
CREATE OR REPLACE VIEW v_using_constant_folding (real1, double1, numeric1) AS
SELECT
1e38::real, 1e38::double, 1e38::numeric;

query RRR
SELECT * FROM v_using_constant_folding
UNION ALL
SELECT SUM(real1), SUM(double1), SUM(numeric1)
FROM v_using_constant_folding;
----
100000000000000000000000000000000000000 100000000000000000000000000000000000000 100000000000000000000000000000000000000
100000000000000000000000000000000000000 100000000000000000000000000000000000000 100000000000000000000000000000000000000

query T multiline
EXPLAIN SELECT * FROM v_using_constant_folding;
----
Explained Query (fast path):
Constant
- (100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000)

EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

# use mode cockroach because it "respects the scale of a Decimal type and the precision of a floating point number"
# even though mode standard would allow easier file comparisons with the other computation mode
mode cockroach

# -------------------------------
# non-aggregate functions with big numbers
# -------------------------------

statement ok
CREATE TABLE t_using_dataflow_rendering (real1 REAL, double1 DOUBLE PRECISION, numeric1 NUMERIC, tint1 INT2, tint2 INT2);

statement ok
INSERT INTO t_using_dataflow_rendering VALUES
(1e38::real, 1e38::double, 1e38::numeric, (-32767)::INT2, (-1)::INT2),
(2, 2, 2, 32767::INT2, 1::INT2);

query IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
SELECT
real1, real1 + 1, real1 - 1,
real1 + 0, double1 + 0, numeric1 + 0,
real1 + real1, double1 + double1, numeric1 + numeric1,
SQRT(real1), SQRT(double1), SQRT(numeric1),
SQRT(real1 + real1), SQRT(double1 + double1), SQRT(numeric1 + numeric1),
tint1 / tint2, tint2 / tint1,
COALESCE(real1, NULL), COALESCE(double1, NULL), COALESCE(numeric1, NULL),
GREATEST(real1, 1), GREATEST(double1, 1), GREATEST(numeric1, 1),
LEAST(real1, 1e38::real), LEAST(double1, 1e38::double), LEAST(numeric1, 1e38::numeric),
NULLIF(real1, 1e38::real), NULLIF(double1, 1e38::double), NULLIF(numeric1, 1e38::numeric),
real1 <= 1e38::real, double1 <= 1e38::double, numeric1 <= 1e38::numeric,
real1 >= 1e38::real, double1 >= 1e38::double, numeric1 >= 1e38::numeric,
real1 < 1e38::real, double1 < 1e38::double, numeric1 < 1e38::numeric,
real1 > 1e38::real, double1 > 1e38::double, numeric1 > 1e38::numeric,
real1 = 1e38::real, double1 = 1e38::double, numeric1 = 1e38::numeric,
CASE WHEN 1=1 THEN real1 ELSE -1 END, CASE WHEN 1=1 THEN double1 ELSE -1 END, CASE WHEN 1=1 THEN numeric1 ELSE -1 END
FROM t_using_dataflow_rendering
ORDER BY real1;
----
2 3 1 2 2 2 4 4 4 1 1 1 2 2 2 32767 0 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 2 2 2
9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 9223372036854775807 9223372036854775807 200000000000000000000000000000000000000 9223372036854775807 9223372036854775807 10000000000000000000 9223372036854775807 9223372036854775807 14142135623730950488 32767 0 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 NULL NULL NULL 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000

query error
SELECT
(tint1 + tint2) / tint2
FROM t_using_dataflow_rendering;

query T multiline
EXPLAIN
SELECT
real1, real1 + 1, real1 - 1,
real1 + 0, double1 + 0, numeric1 + 0,
real1 + real1, double1 + double1, numeric1 + numeric1,
SQRT(real1), SQRT(double1), SQRT(numeric1),
SQRT(real1 + real1), SQRT(double1 + double1), SQRT(numeric1 + numeric1),
tint1 / tint2, tint2 / tint1,
COALESCE(real1, NULL), COALESCE(double1, NULL), COALESCE(numeric1, NULL),
GREATEST(real1, 1), GREATEST(double1, 1), GREATEST(numeric1, 1),
LEAST(real1, 1e38::real), LEAST(double1, 1e38::double), LEAST(numeric1, 1e38::numeric),
NULLIF(real1, 1e38::real), NULLIF(double1, 1e38::double), NULLIF(numeric1, 1e38::numeric),
real1 <= 1e38::real, double1 <= 1e38::double, numeric1 <= 1e38::numeric,
real1 >= 1e38::real, double1 >= 1e38::double, numeric1 >= 1e38::numeric,
real1 < 1e38::real, double1 < 1e38::double, numeric1 < 1e38::numeric,
real1 > 1e38::real, double1 > 1e38::double, numeric1 > 1e38::numeric,
real1 = 1e38::real, double1 = 1e38::double, numeric1 = 1e38::numeric,
CASE WHEN 1=1 THEN real1 ELSE -1 END, CASE WHEN 1=1 THEN double1 ELSE -1 END, CASE WHEN 1=1 THEN numeric1 ELSE -1 END
FROM t_using_dataflow_rendering;
----
Explained Query:
Project (#0, #5..=#20, #0..=#2, #21..=#26, #28, #30, #32..=#44, #27, #29, #31, #0..=#2)
Map ((#0 + 1), (#0 - 1), (#0 + 0), (#1 + 0), (#2 + 0), (#0 + #0), (#1 + #1), (#2 + #2), sqrtf64(real_to_double(#0)), sqrtf64(#1), sqrtnumeric(#2), sqrtf64(real_to_double(#10)), sqrtf64(#11), sqrtnumeric(#12), (#3 / #4), (#4 / #3), greatest(#0, 1), greatest(#1, 1), greatest(#2, 1), least(#0, 100000000000000000000000000000000000000), least(#1, 100000000000000000000000000000000000000), least(#2, 100000000000000000000000000000000000000), (#0 = 100000000000000000000000000000000000000), case when #27 then null else #0 end, (#1 = 100000000000000000000000000000000000000), case when #29 then null else #1 end, (#2 = 100000000000000000000000000000000000000), case when #31 then null else #2 end, (#0 <= 100000000000000000000000000000000000000), (#1 <= 100000000000000000000000000000000000000), (#2 <= 100000000000000000000000000000000000000), (#0 >= 100000000000000000000000000000000000000), (#1 >= 100000000000000000000000000000000000000), (#2 >= 100000000000000000000000000000000000000), (#0 < 100000000000000000000000000000000000000), (#1 < 100000000000000000000000000000000000000), (#2 < 100000000000000000000000000000000000000), (#0 > 100000000000000000000000000000000000000), (#1 > 100000000000000000000000000000000000000), (#2 > 100000000000000000000000000000000000000))
Get materialize.public.t_using_dataflow_rendering

EOF
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.

# use mode cockroach because it "respects the scale of a Decimal type and the precision of a floating point number"
# even though mode standard would allow easier file comparisons with the other computation mode
mode cockroach

# -------------------------------
# non-aggregate functions with big numbers
# -------------------------------

statement ok
CREATE VIEW v_using_constant_folding (real1, double1, numeric1, tint1, tint2) AS
SELECT
1e38::real, 1e38::double, 1e38::numeric, (-32767)::INT2, (-1)::INT2
UNION ALL
SELECT
2, 2, 2, 32767::INT2, 1::INT2;

query IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
SELECT
real1, real1 + 1, real1 - 1,
real1 + 0, double1 + 0, numeric1 + 0,
real1 + real1, double1 + double1, numeric1 + numeric1,
SQRT(real1), SQRT(double1), SQRT(numeric1),
SQRT(real1 + real1), SQRT(double1 + double1), SQRT(numeric1 + numeric1),
tint1 / tint2, tint2 / tint1,
COALESCE(real1, NULL), COALESCE(double1, NULL), COALESCE(numeric1, NULL),
GREATEST(real1, 1), GREATEST(double1, 1), GREATEST(numeric1, 1),
LEAST(real1, 1e38::real), LEAST(double1, 1e38::double), LEAST(numeric1, 1e38::numeric),
NULLIF(real1, 1e38::real), NULLIF(double1, 1e38::double), NULLIF(numeric1, 1e38::numeric),
real1 <= 1e38::real, double1 <= 1e38::double, numeric1 <= 1e38::numeric,
real1 >= 1e38::real, double1 >= 1e38::double, numeric1 >= 1e38::numeric,
real1 < 1e38::real, double1 < 1e38::double, numeric1 < 1e38::numeric,
real1 > 1e38::real, double1 > 1e38::double, numeric1 > 1e38::numeric,
real1 = 1e38::real, double1 = 1e38::double, numeric1 = 1e38::numeric,
CASE WHEN 1=1 THEN real1 ELSE -1 END, CASE WHEN 1=1 THEN double1 ELSE -1 END, CASE WHEN 1=1 THEN numeric1 ELSE -1 END
FROM v_using_constant_folding
ORDER BY real1;
----
2 3 1 2 2 2 4 4 4 1 1 1 2 2 2 32767 0 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 2 2 2
9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 9223372036854775807 9223372036854775807 200000000000000000000000000000000000000 9223372036854775807 9223372036854775807 10000000000000000000 9223372036854775807 9223372036854775807 14142135623730950488 32767 0 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000 NULL NULL NULL 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 9223372036854775807 9223372036854775807 100000000000000000000000000000000000000

query error
SELECT
(tint1 + tint2) / tint2
FROM v_using_constant_folding;

query T multiline
EXPLAIN
SELECT
real1, real1 + 1, real1 - 1,
real1 + 0, double1 + 0, numeric1 + 0,
real1 + real1, double1 + double1, numeric1 + numeric1,
SQRT(real1), SQRT(double1), SQRT(numeric1),
SQRT(real1 + real1), SQRT(double1 + double1), SQRT(numeric1 + numeric1),
tint1 / tint2, tint2 / tint1,
COALESCE(real1, NULL), COALESCE(double1, NULL), COALESCE(numeric1, NULL),
GREATEST(real1, 1), GREATEST(double1, 1), GREATEST(numeric1, 1),
LEAST(real1, 1e38::real), LEAST(double1, 1e38::double), LEAST(numeric1, 1e38::numeric),
NULLIF(real1, 1e38::real), NULLIF(double1, 1e38::double), NULLIF(numeric1, 1e38::numeric),
real1 <= 1e38::real, double1 <= 1e38::double, numeric1 <= 1e38::numeric,
real1 >= 1e38::real, double1 >= 1e38::double, numeric1 >= 1e38::numeric,
real1 < 1e38::real, double1 < 1e38::double, numeric1 < 1e38::numeric,
real1 > 1e38::real, double1 > 1e38::double, numeric1 > 1e38::numeric,
real1 = 1e38::real, double1 = 1e38::double, numeric1 = 1e38::numeric,
CASE WHEN 1=1 THEN real1 ELSE -1 END, CASE WHEN 1=1 THEN double1 ELSE -1 END, CASE WHEN 1=1 THEN numeric1 ELSE -1 END
FROM v_using_constant_folding;
----
Explained Query (fast path):
Constant
- (100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 200000000000000000000000000000000000000, 200000000000000000000000000000000000000, 200000000000000000000000000000000000000, 9999999840142846000, 10000000000000000000, 10000000000000000000, 14142135397658794000, 14142135623730950000, 14142135623730950488.0168872420969807857, 32767, 0, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, null, null, null, true, true, true, true, true, true, false, false, false, false, false, false, true, true, true, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000, 100000000000000000000000000000000000000)
- (2, 3, 1, 2, 2, 2, 4, 4, 4, 1.4142135623730951, 1.4142135623730951, 1.41421356237309504880168872420969807857, 2, 2, 2, 32767, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, true, true, true, false, false, false, true, true, true, false, false, false, false, false, false, 2, 2, 2)

EOF
Loading

0 comments on commit b8874da

Please sign in to comment.