diff --git a/dbms/src/Columns/ColumnLowCardinality.h b/dbms/src/Columns/ColumnLowCardinality.h index a125fee35ab..80fc21431df 100644 --- a/dbms/src/Columns/ColumnLowCardinality.h +++ b/dbms/src/Columns/ColumnLowCardinality.h @@ -117,7 +117,7 @@ public: void getExtremes(Field & min, Field & max) const override { - return getDictionary().index(getIndexes(), 0)->getExtremes(min, max); /// TODO: optimize + return dictionary.getColumnUnique().getNestedColumn()->index(getIndexes(), 0)->getExtremes(min, max); /// TODO: optimize } void reserve(size_t n) override { idx.reserve(n); } diff --git a/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_1.reference b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_1.reference new file mode 100644 index 00000000000..4ab40faa2dd --- /dev/null +++ b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_1.reference @@ -0,0 +1,4 @@ +a 1 6 +a 1 6 +b 3 8 +b 3 8 diff --git a/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_1.sql b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_1.sql new file mode 100644 index 00000000000..7eeebf33d6e --- /dev/null +++ b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_1.sql @@ -0,0 +1,17 @@ +SET allow_experimental_low_cardinality_type = 1; + +drop table if exists test.lc; +drop table if exists test.lc_mv; + +create table test.lc (str StringWithDictionary) engine = MergeTree order by tuple(); + +insert into test.lc values ('a'), ('bbb'), ('ab'), ('accccc'), ('baasddas'), ('bcde'); + +CREATE MATERIALIZED VIEW test.lc_mv ENGINE = AggregatingMergeTree() ORDER BY tuple() populate AS SELECT substring(str, 1, 1) as letter, min(length(str)) AS min_len, max(length(str)) AS max_len FROM test.lc GROUP BY substring(str, 1, 1); + +insert into test.lc values ('a'), ('bbb'), ('ab'), ('accccc'), ('baasddas'), ('bcde'); +select * from test.lc_mv order by letter; + +drop table if exists test.lc; +drop table if exists test.lc_mv; + diff --git a/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_2.reference b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_2.reference new file mode 100644 index 00000000000..b362d0138a0 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_2.reference @@ -0,0 +1 @@ +c 2018-10-10 15:45:00 3 10 2018-10-10 15:54:21 1 1 diff --git a/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_2.sql b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_2.sql new file mode 100644 index 00000000000..850f744a2f1 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00752_low_cardinality_mv_2.sql @@ -0,0 +1,16 @@ +SET allow_experimental_low_cardinality_type = 1; + +drop table if exists test.radacct; +drop table if exists test.mv_traffic_by_tadig15min; + +CREATE TABLE test.radacct ( radacctid UInt64, f3gppchargingid Nullable(String), f3gppggsnaddress Nullable(String), f3gppggsnmccmnc Nullable(String), f3gppgprsqos Nullable(String), f3gppimeisv Nullable(String), f3gppimsi Nullable(UInt64), f3gppimsimccmnc Nullable(String), f3gpploci Nullable(String), f3gppnsapi Nullable(String), f3gpprattype Nullable(String), f3gppsgsnaddress Nullable(String), f3gppsgsnmccmnc Nullable(String), acctdelaytime Nullable(UInt32), acctinputoctets Nullable(UInt64), acctinputpackets Nullable(UInt64), acctoutputoctets Nullable(UInt64), acctoutputpackets Nullable(UInt64), acctsessionid String, acctstatustype Nullable(String), acctuniqueid String, calledstationid Nullable(String), callingstationid Nullable(String), framedipaddress Nullable(String), nasidentifier Nullable(String), nasipaddress Nullable(String), acctstarttime Nullable(DateTime), acctstoptime Nullable(DateTime), acctsessiontime Nullable(UInt32), acctterminatecause Nullable(String), acctstartdelay Nullable(UInt32), acctstopdelay Nullable(UInt32), connectinfo_start Nullable(String), connectinfo_stop Nullable(String), timestamp DateTime, username Nullable(String), realm Nullable(String), f3gppimsi_int UInt64, f3gppsgsnaddress_int Nullable(UInt32), timestamp_date Date, tac Nullable(String), mnc Nullable(String), tadig LowCardinality(String), country LowCardinality(String), tadig_op_ip Nullable(String) DEFAULT CAST('TADIG NOT FOUND', 'Nullable(String)'), mcc Nullable(UInt16) MATERIALIZED toUInt16OrNull(substring(f3gppsgsnmccmnc, 1, 6))) ENGINE = MergeTree(timestamp_date, (timestamp, radacctid, acctuniqueid), 8192); + +insert into test.radacct values (1, 'a', 'b', 'c', 'd', 'e', 2, 'a', 'b', 'c', 'd', 'e', 'f', 3, 4, 5, 6, 7, 'a', 'Stop', 'c', 'd', 'e', 'f', 'g', 'h', '2018-10-10 15:54:21', '2018-10-10 15:54:21', 8, 'a', 9, 10, 'a', 'b', '2018-10-10 15:54:21', 'a', 'b', 11, 12, '2018-10-10', 'a', 'b', 'c', 'd', 'e'); + +create materialized view test.mv_traffic_by_tadig15min Engine=AggregatingMergeTree partition by tadig order by (ts,tadig) populate as select toStartOfFifteenMinutes(timestamp) ts,toDayOfWeek(timestamp) dow, tadig, sumState(acctinputoctets+acctoutputoctets) traffic_bytes,maxState(timestamp) last_stop, minState(radacctid) min_radacctid,maxState(radacctid) max_radacctid from test.radacct where acctstatustype='Stop' and acctinputoctets+acctoutputoctets > 0 group by tadig,ts,dow; + +select tadig, ts, dow, sumMerge(traffic_bytes), maxMerge(last_stop), minMerge(min_radacctid), maxMerge(max_radacctid) from test.mv_traffic_by_tadig15min group by tadig, ts, dow; + +drop table if exists test.radacct; +drop table if exists test.mv_traffic_by_tadig15min; +