diff --git a/test/sql/test_automatic_partition/R/test_partition_prune b/test/sql/test_automatic_partition/R/test_partition_prune index 61e5c9052d3c2..11724bd2dbc49 100644 --- a/test/sql/test_automatic_partition/R/test_partition_prune +++ b/test/sql/test_automatic_partition/R/test_partition_prune @@ -12,3 +12,167 @@ explain select * from orders_new where ts=20200101; -- result: [REGEX].*partitions=1/2.* -- !result + + + + + + + + + + + + +-- name: test_range_prune +CREATE TABLE ts ( + ts INT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL ) +PARTITION BY date_trunc('month', str_to_date(CAST(ts as STRING),'%Y%m%d')); +-- result: +-- !result +insert into ts values('20200201',1,'cd'); +-- result: +-- !result +insert into ts values('20200101',1,'cd'); +-- result: +-- !result +insert into ts values('20200301',1,'cd'); +-- result: +-- !result +insert into ts values('20200401',1,'cd'); +-- result: +-- !result +explain select * from ts where ts>20200201; +-- result: +[REGEX].*partitions=3/4.* +-- !result +CREATE TABLE o ( + ts BIGINT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL +) +PARTITION BY from_unixtime(ts,'%Y%m%d'); +-- result: +-- !result +insert into o values(1727224687,1,'cd'); +-- result: +-- !result +insert into o values(1737234687,1,'cd'); +-- result: +-- !result +insert into o values(1747244687,1,'cd'); +-- result: +-- !result +insert into o values(1757254687,1,'cd'); +-- result: +-- !result +explain select * from o where ts>1737234687; +-- result: +[REGEX].*partitions=3/4.* +-- !result +CREATE TABLE t ( + ts INT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL ) +PARTITION BY id, date_trunc('month', str_to_date(CAST(ts as STRING),'%Y%m%d')); +-- result: +-- !result +insert into t values('20200201',1,'cd'); +-- result: +-- !result +insert into t values('20200101',1,'cd'); +-- result: +-- !result +insert into t values('20200301',1,'cd'); +-- result: +-- !result +insert into t values('20200401',1,'cd'); +-- result: +-- !result +insert into t values('20200201',2,'cd'); +-- result: +-- !result +insert into t values('20200101',2,'cd'); +-- result: +-- !result +insert into t values('20200301',3,'cd'); +-- result: +-- !result +insert into t values('20200401',3,'cd'); +-- result: +-- !result +explain select * from t where ts>20200201; +-- result: +[REGEX].*partitions=6/8.* +-- !result +explain select * from t where id>1; +-- result: +[REGEX].*partitions=4/8.* +-- !result +explain select * from t where id>1 and ts>20200201; +-- result: +[REGEX].*partitions=3/8.* +-- !result + + + + + + + +-- name: test_prune_value_function +CREATE TABLE o ( + ts BIGINT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL +) +PARTITION BY from_unixtime(ts,'%Y%m%d'); +-- result: +-- !result +insert into o values(unix_timestamp(),1,'cd'); +-- result: +-- !result +insert into o values(unix_timestamp()+1000000,1,'cd'); +-- result: +-- !result +insert into o values(unix_timestamp()-1000000,1,'cd'); +-- result: +-- !result +explain select * from o where ts>unix_timestamp(); +-- result: +[REGEX].*partitions=2/3.* +-- !result + + + + + + +-- name: test_prune_cast +CREATE TABLE o ( + ts STRING NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL +) +PARTITION BY from_unixtime(cast(ts as INT) + 3600); +-- result: +-- !result +insert into o values(unix_timestamp(),1,'cd'); +-- result: +-- !result +insert into o values(unix_timestamp()+1000000,1,'cd'); +-- result: +-- !result +insert into o values(unix_timestamp()-1000000,1,'cd'); +-- result: +-- !result +explain select * from o where ts>cast(unix_timestamp() as STRING); +-- result: +[REGEX].*partitions=1/3.* +-- !result +explain select * from o where ts>'1740108713'; +-- result: +[REGEX].*partitions=2/3.* +-- !result diff --git a/test/sql/test_automatic_partition/T/test_partition_prune b/test/sql/test_automatic_partition/T/test_partition_prune index 0d22e8550cc6e..2c39c37595b15 100644 --- a/test/sql/test_automatic_partition/T/test_partition_prune +++ b/test/sql/test_automatic_partition/T/test_partition_prune @@ -3,3 +3,69 @@ CREATE TABLE orders_new ( ts INT NOT NULL, id BIGINT NOT NULL, city insert into orders_new values('20200201',1,'cd'); insert into orders_new values('20200101',1,'cd'); explain select * from orders_new where ts=20200101; + +-- name: test_range_prune +CREATE TABLE ts ( + ts INT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL ) +PARTITION BY date_trunc('month', str_to_date(CAST(ts as STRING),'%Y%m%d')); +insert into ts values('20200201',1,'cd'); +insert into ts values('20200101',1,'cd'); +insert into ts values('20200301',1,'cd'); +insert into ts values('20200401',1,'cd'); +explain select * from ts where ts>20200201; + +CREATE TABLE o ( + ts BIGINT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL +) +PARTITION BY from_unixtime(ts,'%Y%m%d'); +insert into o values(1727224687,1,'cd'); +insert into o values(1737234687,1,'cd'); +insert into o values(1747244687,1,'cd'); +insert into o values(1757254687,1,'cd'); +explain select * from o where ts>1737234687; + +CREATE TABLE t ( + ts INT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL ) +PARTITION BY id, date_trunc('month', str_to_date(CAST(ts as STRING),'%Y%m%d')); +insert into t values('20200201',1,'cd'); +insert into t values('20200101',1,'cd'); +insert into t values('20200301',1,'cd'); +insert into t values('20200401',1,'cd'); +insert into t values('20200201',2,'cd'); +insert into t values('20200101',2,'cd'); +insert into t values('20200301',3,'cd'); +insert into t values('20200401',3,'cd'); +explain select * from t where ts>20200201; +explain select * from t where id>1; +explain select * from t where id>1 and ts>20200201; + +-- name: test_prune_value_function +CREATE TABLE o ( + ts BIGINT NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL +) +PARTITION BY from_unixtime(ts,'%Y%m%d'); +insert into o values(unix_timestamp(),1,'cd'); +insert into o values(unix_timestamp()+1000000,1,'cd'); +insert into o values(unix_timestamp()-1000000,1,'cd'); +explain select * from o where ts>unix_timestamp(); + +-- name: test_prune_cast +CREATE TABLE o ( + ts STRING NOT NULL, + id BIGINT NOT NULL, + city STRING NOT NULL +) +PARTITION BY from_unixtime(cast(ts as INT) + 3600); +insert into o values(unix_timestamp(),1,'cd'); +insert into o values(unix_timestamp()+1000000,1,'cd'); +insert into o values(unix_timestamp()-1000000,1,'cd'); +explain select * from o where ts>cast(unix_timestamp() as STRING); +explain select * from o where ts>'1740108713';