Commit 99368440 authored by HTH's avatar HTH

init

parents
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="本地" uuid="c1267967-97b6-49bc-96e1-35babb401a1b">
<driver-ref>clickhouse</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>ru.yandex.clickhouse.ClickHouseDriver</jdbc-driver>
<jdbc-url>jdbc:clickhouse://localhost:8123/</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="运维测试环境" uuid="b152edc5-14e2-4e8f-8b23-b3bb14498a26">
<driver-ref>clickhouse</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>ru.yandex.clickhouse.ClickHouseDriver</jdbc-driver>
<jdbc-url>jdbc:clickhouse://39.108.185.243:18123</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/test.iml" filepath="$PROJECT_DIR$/.idea/test.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="DBE_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
select avg(value)
from meter_data
where time between '2021-01-01 00:00:00' and '2022-01-01 00:00:00'
and attr_id=77243;
select count(1)
from meter_data
where time between '2021-01-01 00:00:00' and '2022-01-01 00:00:00';
select *
from meter_data
where time between '2021-01-01 00:00:00' and '2022-01-01 00:00:00'
limit 100;
select toDate(time) as t
from meter_data
group by toDate(time);
select toDate(time) as t, avg(value)
from meter_data
where time between '2021-01-01 00:00:00' and '2022-01-01 00:00:00'
and attr_id in(64800,64802,64804,64806,64807)
group by toDate(time);
select version(), timezone();
\ No newline at end of file
-- 创建
CREATE MATERIALIZED VIEW meter_analyze_hour
ENGINE = AggregatingMergeTree() PARTITION BY toYYYYMM(time) ORDER BY (time, attr_id)
AS SELECT
toStartOfHour(time) as time
,attr_id
,countState(1) as count
,sumState(value) as sum
,avgState(value) as avg
,maxState(value) as max
,minState(value) as min
FROM meter_data
GROUP BY time,attr_id;
-- 插入数据
insert into meter_data values(now(),2,77);
-- 查询
select time,attr_id,sumMerge(sum),countMerge(count),avgMerge(avg),maxMerge(max) as max,minMerge(min) as min,max-min
from meter_analyze_hour
GROUP BY time,attr_id;
\ No newline at end of file
-- 表存储容量统计
select
database,
table,
formatReadableSize(size) as size,
formatReadableSize(bytes_on_disk) as bytes_on_disk,
formatReadableSize(data_uncompressed_bytes) as data_uncompressed_bytes,
formatReadableSize(data_compressed_bytes) as data_compressed_bytes,
compress_rate,
rows,
days,
formatReadableSize(avgDaySize) as avgDaySize
from
(
select
database,
table,
sum(bytes) as size,
sum(rows) as rows,
min(min_date) as min_date,
max(max_date) as max_date,
sum(bytes_on_disk) as bytes_on_disk,
sum(data_uncompressed_bytes) as data_uncompressed_bytes,
sum(data_compressed_bytes) as data_compressed_bytes,
(data_compressed_bytes / data_uncompressed_bytes) * 100 as compress_rate,
max_date - min_date as days,
size / (max_date - min_date) as avgDaySize
from system.parts
where active
and database = 'hth'
and table = 'meter_data'
group by
database,
table
);
-- 数据库容量统计
select
sum(rows) as rows,--总行数
formatReadableSize(sum(data_uncompressed_bytes)) as ysq,--原始大小
formatReadableSize(sum(data_compressed_bytes)) as ysh,--压缩大小
round(sum(data_compressed_bytes) / sum(data_uncompressed_bytes) * 100, 0) ys_rate--压缩率
from system.parts;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment