blob: e69f5ab12ac6f7c39d7b1075e2526d7581583772 [file] [log] [blame]
<!doctype html>
<html lang="zh-CN" data-theme="light">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="generator" content="VuePress 2.0.0-rc.0" />
<meta name="theme" content="VuePress Theme Hope 2.0.0-rc.2" />
<style>
html {
background: var(--bg-color, #fff);
}
html[data-theme="dark"] {
background: var(--bg-color, #1d1e1f);
}
body {
background: var(--bg-color);
}
</style>
<script>
const userMode = localStorage.getItem("vuepress-theme-hope-scheme");
const systemDarkMode =
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
if (userMode === "dark" || (userMode !== "light" && systemDarkMode)) {
document.documentElement.setAttribute("data-theme", "dark");
}
</script>
<link rel="alternate" hreflang="en-us" href="https://iotdb.apache.org/UserGuide/Master/User-Manual/IoTDB-View_timecho.html"><meta property="og:url" content="https://iotdb.apache.org/zh/UserGuide/Master/User-Manual/IoTDB-View_timecho.html"><meta property="og:site_name" content="IoTDB Website"><meta property="og:title" content="视图"><meta property="og:description" content="一、 序列视图应用背景 1.1 应用场景1 时间序列重命名(PI资产管理) 实际应用中,采集数据的设备可能使用人类难以理解的标识号来命名,这给业务层带来了查询上的困难。 而序列视图能够重新组织管理这些序列,在不改变原有序列内容、无需新建或拷贝序列的情况下,使用新的模型结构来访问他们。 例如:一台云端设备使用自己的网卡MAC地址组成实体编号,存储数据时写..."><meta property="og:type" content="article"><meta property="og:locale" content="zh-CN"><meta property="og:locale:alternate" content="en-US"><meta property="og:updated_time" content="2024-03-29T10:50:02.000Z"><meta property="article:modified_time" content="2024-03-29T10:50:02.000Z"><script type="application/ld+json">{"@context":"https://schema.org","@type":"Article","headline":"视图","image":[""],"dateModified":"2024-03-29T10:50:02.000Z","author":[]}</script><link rel="icon" href="/favicon.ico"><meta name="Description" content="Apache IoTDB: Time Series Database for IoT"><meta name="Keywords" content="TSDB, time series, time series database, IoTDB, IoT database, IoT data management,时序数据库, 时间序列管理, IoTDB, 物联网数据库, 实时数据库, 物联网数据管理, 物联网数据"><meta name="baidu-site-verification" content="wfKETzB3OT"><meta name="google-site-verification" content="mZWAoRY0yj_HAr-s47zHCGHzx5Ju-RVm5wDbPnwQYFo"><script type="text/javascript">
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="https://analytics.apache.org/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '56']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script><title>视图 | IoTDB Website</title><meta name="description" content="一、 序列视图应用背景 1.1 应用场景1 时间序列重命名(PI资产管理) 实际应用中,采集数据的设备可能使用人类难以理解的标识号来命名,这给业务层带来了查询上的困难。 而序列视图能够重新组织管理这些序列,在不改变原有序列内容、无需新建或拷贝序列的情况下,使用新的模型结构来访问他们。 例如:一台云端设备使用自己的网卡MAC地址组成实体编号,存储数据时写...">
<link rel="preload" href="/assets/style-vuIfcoxv.css" as="style"><link rel="stylesheet" href="/assets/style-vuIfcoxv.css">
<link rel="modulepreload" href="/assets/app-z4N-28Th.js"><link rel="modulepreload" href="/assets/IoTDB-View_timecho.html-FxXlLTsm.js"><link rel="modulepreload" href="/assets/IoTDB-View_timecho.html-EG1ndF44.js">
</head>
<body>
<div id="app"><!--[--><!--[--><!--[--><span tabindex="-1"></span><a href="#main-content" class="vp-skip-link sr-only">跳至主要內容</a><!--]--><!--[--><div class="theme-container no-sidebar has-toc"><!--[--><header id="navbar" class="vp-navbar hide-icon"><div class="vp-navbar-start"><button type="button" class="vp-toggle-sidebar-button" title="Toggle Sidebar"><span class="icon"></span></button><!--[--><!----><!--]--><!--[--><a class="vp-link vp-brand vp-brand" href="/zh/"><img class="vp-nav-logo" src="/logo.png" alt="IoTDB Website"><!----><span class="vp-site-name hide-in-pad">IoTDB Website</span></a><!--]--><!--[--><!----><!--]--></div><div class="vp-navbar-center"><!--[--><!----><!--]--><!--[--><!--]--><!--[--><!----><!--]--></div><div class="vp-navbar-end"><!--[--><!----><!--]--><!--[--><div id="docsearch-container"></div><nav class="vp-nav-links"><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button type="button" class="dropdown-title" aria-label="文档"><span class="title"><!---->文档</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a aria-label="v1.3.x" class="vp-link nav-link nav-link" href="/zh/UserGuide/latest/QuickStart/QuickStart.html"><!---->v1.3.x<!----></a></li><li class="dropdown-item"><a aria-label="v1.2.x" class="vp-link nav-link nav-link" href="/zh/UserGuide/V1.2.x/QuickStart/QuickStart.html"><!---->v1.2.x<!----></a></li><li class="dropdown-item"><a aria-label="v1.1.x" class="vp-link nav-link nav-link" href="/zh/UserGuide/V1.1.x/QuickStart/QuickStart.html"><!---->v1.1.x<!----></a></li><li class="dropdown-item"><a aria-label="v1.0.x" class="vp-link nav-link nav-link" href="/zh/UserGuide/V1.0.x/QuickStart/QuickStart.html"><!---->v1.0.x<!----></a></li><li class="dropdown-item"><a aria-label="v0.13.x" class="vp-link nav-link nav-link" href="/zh/UserGuide/V0.13.x/QuickStart/QuickStart.html"><!---->v0.13.x<!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=177051872" rel="noopener noreferrer" target="_blank" aria-label="系统设计" class="nav-link"><!---->系统设计<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></div><div class="nav-item hide-in-mobile"><a aria-label="下载" class="vp-link nav-link nav-link" href="/zh/Download/"><!---->下载<!----></a></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button type="button" class="dropdown-title" aria-label="社区"><span class="title"><!---->社区</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a aria-label="关于社区" class="vp-link nav-link nav-link" href="/zh/Community/About.html"><!---->关于社区<!----></a></li><li class="dropdown-item"><a aria-label="交流与反馈" class="vp-link nav-link nav-link" href="/zh/Community/Feedback.html"><!---->交流与反馈<!----></a></li><li class="dropdown-item"><a aria-label="活动与报告" class="vp-link nav-link nav-link" href="/zh/Community/Materials.html"><!---->活动与报告<!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button type="button" class="dropdown-title" aria-label="开发"><span class="title"><!---->开发</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a aria-label="成为开发者" class="vp-link nav-link nav-link" href="/zh/Development/Community-Project-Committers.html"><!---->成为开发者<!----></a></li><li class="dropdown-item"><a aria-label="开发指南" class="vp-link nav-link nav-link" href="/zh/Development/Development-Guide.html"><!---->开发指南<!----></a></li><li class="dropdown-item"><a aria-label="Power by" class="vp-link nav-link nav-link" href="/zh/Development/Powered-By.html"><!---->Power by<!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><div class="dropdown-wrapper"><button type="button" class="dropdown-title" aria-label="ASF"><span class="title"><!---->ASF</span><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a href="https://www.apache.org/" rel="noopener noreferrer" target="_blank" aria-label="基金会" class="nav-link"><!---->基金会<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://www.apache.org/licenses/" rel="noopener noreferrer" target="_blank" aria-label="许可证" class="nav-link"><!---->许可证<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://www.apache.org/security/" rel="noopener noreferrer" target="_blank" aria-label="安全" class="nav-link"><!---->安全<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://www.apache.org/foundation/sponsorship.html" rel="noopener noreferrer" target="_blank" aria-label="赞助" class="nav-link"><!---->赞助<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://www.apache.org/foundation/thanks.html" rel="noopener noreferrer" target="_blank" aria-label="致谢" class="nav-link"><!---->致谢<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://www.apache.org/events/current-event" rel="noopener noreferrer" target="_blank" aria-label="活动" class="nav-link"><!---->活动<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li><li class="dropdown-item"><a href="https://privacy.apache.org/policies/privacy-policy-public.html" rel="noopener noreferrer" target="_blank" aria-label="隐私" class="nav-link"><!---->隐私<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></li></ul></button></div></div></nav><div class="nav-item"><div class="dropdown-wrapper i18n-dropdown"><button type="button" class="dropdown-title" aria-label="选择语言"><!--[--><svg xmlns="http://www.w3.org/2000/svg" class="icon i18n-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="i18n icon" style="width:1rem;height:1rem;vertical-align:middle;"><path d="M379.392 460.8 494.08 575.488l-42.496 102.4L307.2 532.48 138.24 701.44l-71.68-72.704L234.496 460.8l-45.056-45.056c-27.136-27.136-51.2-66.56-66.56-108.544h112.64c7.68 14.336 16.896 27.136 26.112 35.84l45.568 46.08 45.056-45.056C382.976 312.32 409.6 247.808 409.6 204.8H0V102.4h256V0h102.4v102.4h256v102.4H512c0 70.144-37.888 161.28-87.04 210.944L378.88 460.8zM576 870.4 512 1024H409.6l256-614.4H768l256 614.4H921.6l-64-153.6H576zM618.496 768h196.608L716.8 532.48 618.496 768z"></path></svg><!--]--><span class="arrow"></span><ul class="nav-dropdown"><li class="dropdown-item"><a aria-label="English" class="vp-link nav-link nav-link" href="/UserGuide/Master/User-Manual/IoTDB-View_timecho.html"><!---->English<!----></a></li><li class="dropdown-item"><a aria-label="简体中文" class="vp-link nav-link active nav-link active" href="/zh/UserGuide/Master/User-Manual/IoTDB-View_timecho.html"><!---->简体中文<!----></a></li></ul></button></div></div><div class="nav-item hide-in-mobile"><button type="button" id="appearance-switch"><svg xmlns="http://www.w3.org/2000/svg" class="icon auto-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="auto icon" style="display:block;"><path d="M512 992C246.92 992 32 777.08 32 512S246.92 32 512 32s480 214.92 480 480-214.92 480-480 480zm0-840c-198.78 0-360 161.22-360 360 0 198.84 161.22 360 360 360s360-161.16 360-360c0-198.78-161.22-360-360-360zm0 660V212c165.72 0 300 134.34 300 300 0 165.72-134.28 300-300 300z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="dark icon" style="display:none;"><path d="M524.8 938.667h-4.267a439.893 439.893 0 0 1-313.173-134.4 446.293 446.293 0 0 1-11.093-597.334A432.213 432.213 0 0 1 366.933 90.027a42.667 42.667 0 0 1 45.227 9.386 42.667 42.667 0 0 1 10.24 42.667 358.4 358.4 0 0 0 82.773 375.893 361.387 361.387 0 0 0 376.747 82.774 42.667 42.667 0 0 1 54.187 55.04 433.493 433.493 0 0 1-99.84 154.88 438.613 438.613 0 0 1-311.467 128z"></path></svg><svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="light icon" style="display:none;"><path d="M952 552h-80a40 40 0 0 1 0-80h80a40 40 0 0 1 0 80zM801.88 280.08a41 41 0 0 1-57.96-57.96l57.96-58a41.04 41.04 0 0 1 58 58l-58 57.96zM512 752a240 240 0 1 1 0-480 240 240 0 0 1 0 480zm0-560a40 40 0 0 1-40-40V72a40 40 0 0 1 80 0v80a40 40 0 0 1-40 40zm-289.88 88.08-58-57.96a41.04 41.04 0 0 1 58-58l57.96 58a41 41 0 0 1-57.96 57.96zM192 512a40 40 0 0 1-40 40H72a40 40 0 0 1 0-80h80a40 40 0 0 1 40 40zm30.12 231.92a41 41 0 0 1 57.96 57.96l-57.96 58a41.04 41.04 0 0 1-58-58l58-57.96zM512 832a40 40 0 0 1 40 40v80a40 40 0 0 1-80 0v-80a40 40 0 0 1 40-40zm289.88-88.08 58 57.96a41.04 41.04 0 0 1-58 58l-57.96-58a41 41 0 0 1 57.96-57.96z"></path></svg></button></div><div class="nav-item vp-repo"><a class="vp-repo-link" href="https://github.com/apache/iotdb" target="_blank" rel="noopener noreferrer" aria-label="GitHub"><svg xmlns="http://www.w3.org/2000/svg" class="icon github-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="github icon" style="width:1.25rem;height:1.25rem;vertical-align:middle;"><path d="M511.957 21.333C241.024 21.333 21.333 240.981 21.333 512c0 216.832 140.544 400.725 335.574 465.664 24.49 4.395 32.256-10.07 32.256-23.083 0-11.69.256-44.245 0-85.205-136.448 29.61-164.736-64.64-164.736-64.64-22.315-56.704-54.4-71.765-54.4-71.765-44.587-30.464 3.285-29.824 3.285-29.824 49.195 3.413 75.179 50.517 75.179 50.517 43.776 75.008 114.816 53.333 142.762 40.79 4.523-31.66 17.152-53.377 31.19-65.537-108.971-12.458-223.488-54.485-223.488-242.602 0-53.547 19.114-97.323 50.517-131.67-5.035-12.33-21.93-62.293 4.779-129.834 0 0 41.258-13.184 134.912 50.346a469.803 469.803 0 0 1 122.88-16.554c41.642.213 83.626 5.632 122.88 16.554 93.653-63.488 134.784-50.346 134.784-50.346 26.752 67.541 9.898 117.504 4.864 129.834 31.402 34.347 50.474 78.123 50.474 131.67 0 188.586-114.73 230.016-224.042 242.09 17.578 15.232 33.578 44.672 33.578 90.454v135.85c0 13.142 7.936 27.606 32.854 22.87C862.25 912.597 1002.667 728.747 1002.667 512c0-271.019-219.648-490.667-490.71-490.667z"></path></svg></a></div><!--]--><!--[--><!----><!--]--><button type="button" class="vp-toggle-navbar-button" aria-label="Toggle Navbar" aria-expanded="false" aria-controls="nav-screen"><span><span class="vp-top"></span><span class="vp-middle"></span><span class="vp-bottom"></span></span></button></div></header><!----><!--]--><!----><div class="toggle-sidebar-wrapper"><span class="arrow start"></span></div><aside id="sidebar" class="vp-sidebar"><!--[--><!----><!--]--><ul class="vp-sidebar-links"></ul><!--[--><!----><!--]--></aside><!--[--><main id="main-content" class="vp-page"><!--[--><!--[--><!----><!--]--><!----><nav class="vp-breadcrumb disable"></nav><div class="vp-page-title"><h1><!---->视图</h1><div class="page-info"><!----><!----><span class="page-date-info" aria-label="写作日期"><svg xmlns="http://www.w3.org/2000/svg" class="icon calendar-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="calendar icon"><path d="M716.4 110.137c0-18.753-14.72-33.473-33.472-33.473-18.753 0-33.473 14.72-33.473 33.473v33.473h66.993v-33.473zm-334.87 0c0-18.753-14.72-33.473-33.473-33.473s-33.52 14.72-33.52 33.473v33.473h66.993v-33.473zm468.81 33.52H716.4v100.465c0 18.753-14.72 33.473-33.472 33.473a33.145 33.145 0 01-33.473-33.473V143.657H381.53v100.465c0 18.753-14.72 33.473-33.473 33.473a33.145 33.145 0 01-33.473-33.473V143.657H180.6A134.314 134.314 0 0046.66 277.595v535.756A134.314 134.314 0 00180.6 947.289h669.74a134.36 134.36 0 00133.94-133.938V277.595a134.314 134.314 0 00-133.94-133.938zm33.473 267.877H147.126a33.145 33.145 0 01-33.473-33.473c0-18.752 14.72-33.473 33.473-33.473h736.687c18.752 0 33.472 14.72 33.472 33.473a33.145 33.145 0 01-33.472 33.473z"></path></svg><span><!----></span><meta property="datePublished" content="2024-03-29T10:50:02.000Z"></span><!----><span class="page-reading-time-info" aria-label="阅读时间"><svg xmlns="http://www.w3.org/2000/svg" class="icon timer-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="timer icon"><path d="M799.387 122.15c4.402-2.978 7.38-7.897 7.38-13.463v-1.165c0-8.933-7.38-16.312-16.312-16.312H256.33c-8.933 0-16.311 7.38-16.311 16.312v1.165c0 5.825 2.977 10.874 7.637 13.592 4.143 194.44 97.22 354.963 220.201 392.763-122.204 37.542-214.893 196.511-220.2 389.397-4.661 5.049-7.638 11.651-7.638 19.03v5.825h566.49v-5.825c0-7.379-2.849-13.981-7.509-18.9-5.049-193.016-97.867-351.985-220.2-389.527 123.24-37.67 216.446-198.453 220.588-392.892zM531.16 450.445v352.632c117.674 1.553 211.787 40.778 211.787 88.676H304.097c0-48.286 95.149-87.382 213.728-88.676V450.445c-93.077-3.107-167.901-81.297-167.901-177.093 0-8.803 6.99-15.793 15.793-15.793 8.803 0 15.794 6.99 15.794 15.793 0 80.261 63.69 145.635 142.01 145.635s142.011-65.374 142.011-145.635c0-8.803 6.99-15.793 15.794-15.793s15.793 6.99 15.793 15.793c0 95.019-73.789 172.82-165.96 177.093z"></path></svg><span>大约 16 分钟</span><meta property="timeRequired" content="PT16M"></span><!----><!----></div><hr></div><div class="toc-place-holder"><aside id="toc"><!--[--><!----><!--]--><div class="toc-header">此页内容<button type="button" class="print-button" title="打印"><svg xmlns="http://www.w3.org/2000/svg" class="icon print-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="print icon"><path d="M819.2 364.8h-44.8V128c0-17.067-14.933-32-32-32H281.6c-17.067 0-32 14.933-32 32v236.8h-44.8C145.067 364.8 96 413.867 96 473.6v192c0 59.733 49.067 108.8 108.8 108.8h44.8V896c0 17.067 14.933 32 32 32h460.8c17.067 0 32-14.933 32-32V774.4h44.8c59.733 0 108.8-49.067 108.8-108.8v-192c0-59.733-49.067-108.8-108.8-108.8zM313.6 160h396.8v204.8H313.6V160zm396.8 704H313.6V620.8h396.8V864zM864 665.6c0 25.6-19.2 44.8-44.8 44.8h-44.8V588.8c0-17.067-14.933-32-32-32H281.6c-17.067 0-32 14.933-32 32v121.6h-44.8c-25.6 0-44.8-19.2-44.8-44.8v-192c0-25.6 19.2-44.8 44.8-44.8h614.4c25.6 0 44.8 19.2 44.8 44.8v192z"></path></svg></button></div><div class="toc-wrapper"><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#一、-序列视图应用背景">一、 序列视图应用背景</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_1-1-应用场景1-时间序列重命名-pi资产管理">1.1 应用场景1 时间序列重命名(PI资产管理)</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_1-2-应用场景2-简化业务层查询逻辑">1.2 应用场景2 简化业务层查询逻辑</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_1-3-应用场景3-辅助权限管理">1.3 应用场景3 辅助权限管理</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_1-4-设计序列视图功能的动机">1.4 设计序列视图功能的动机</a></li><!----><!--]--></ul></li><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#二、序列视图概念">二、序列视图概念</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_2-1-术语概念">2.1 术语概念</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_2-2-序列视图">2.2 序列视图</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_2-3-别名序列">2.3 别名序列</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_2-4-嵌套视图">2.4 嵌套视图</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_2-5-iotdb中对序列视图的一些约束">2.5 IoTDB中对序列视图的一些约束</a></li><!----><!--]--></ul></li><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#三、序列视图功能介绍">三、序列视图功能介绍</a></li><li><ul class="toc-list"><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_3-1-创建视图">3.1 创建视图</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_3-2-视图数据查询">3.2 视图数据查询</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_3-3-视图修改">3.3 视图修改</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_3-4-视图同步">3.4 视图同步</a></li><!----><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level3 toc-link level3" href="#_3-5-视图元数据查询">3.5 视图元数据查询</a></li><!----><!--]--></ul></li><!--]--><!--[--><li class="toc-item"><a class="vp-link toc-link level2 toc-link level2" href="#四、faq">四、FAQ</a></li><!----><!--]--></ul><div class="toc-marker" style="top:-1.7rem;"></div></div><!--[--><!----><!--]--></aside></div><!--[--><!----><!--]--><div class="theme-hope-content"><!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
--><h1 id="视图" tabindex="-1"><a class="header-anchor" href="#视图" aria-hidden="true">#</a> 视图</h1><h2 id="一、-序列视图应用背景" tabindex="-1"><a class="header-anchor" href="#一、-序列视图应用背景" aria-hidden="true">#</a> 一、 序列视图应用背景</h2><h3 id="_1-1-应用场景1-时间序列重命名-pi资产管理" tabindex="-1"><a class="header-anchor" href="#_1-1-应用场景1-时间序列重命名-pi资产管理" aria-hidden="true">#</a> 1.1 应用场景1 时间序列重命名(PI资产管理)</h3><p>实际应用中,采集数据的设备可能使用人类难以理解的标识号来命名,这给业务层带来了查询上的困难。</p><p>而序列视图能够重新组织管理这些序列,在不改变原有序列内容、无需新建或拷贝序列的情况下,使用新的模型结构来访问他们。</p><p><strong>例如</strong>:一台云端设备使用自己的网卡MAC地址组成实体编号,存储数据时写入如下时间序列:<code>root.db.0800200A8C6D.xvjeifg</code>.</p><p>对于用户来说,它是难以理解的。但此时,用户能够使用序列视图功能对它重命名,将它映射到一个序列视图中去,使用<code>root.view.device001.temperature</code>来访问采集到的数据。</p><h3 id="_1-2-应用场景2-简化业务层查询逻辑" tabindex="-1"><a class="header-anchor" href="#_1-2-应用场景2-简化业务层查询逻辑" aria-hidden="true">#</a> 1.2 应用场景2 简化业务层查询逻辑</h3><p>有时用户有大量设备,管理着大量时间序列。在进行某项业务时,用户希望仅处理其中的部分序列,此时就可以通过序列视图功能挑选出关注重点,方便反复查询、写入。</p><p><strong>例如</strong>:用户管理一条产品流水线,各环节的设备有大量时间序列。温度检测员仅需要关注设备温度,就可以抽取温度相关的序列,组成序列视图。</p><h3 id="_1-3-应用场景3-辅助权限管理" tabindex="-1"><a class="header-anchor" href="#_1-3-应用场景3-辅助权限管理" aria-hidden="true">#</a> 1.3 应用场景3 辅助权限管理</h3><p>生产过程中,不同业务负责的范围一般不同,出于安全考虑往往需要通过权限管理来限制业务员的访问范围。</p><p><strong>例如</strong>:安全管理部门现在仅需要监控某生产线上各设备的温度,但这些数据与其他机密数据存放在同一数据库。此时,就可以创建若干新的视图,视图中仅含有生产线上与温度有关的时间序列,接着,向安全员只赋予这些序列视图的权限,从而达到权限限制的目的。</p><h3 id="_1-4-设计序列视图功能的动机" tabindex="-1"><a class="header-anchor" href="#_1-4-设计序列视图功能的动机" aria-hidden="true">#</a> 1.4 设计序列视图功能的动机</h3><p>结合上述两类使用场景,设计序列视图功能的动机,主要有:</p><ol><li>时间序列重命名。</li><li>简化业务层查询逻辑。</li><li>辅助权限管理,通过视图向特定用户开放数据。</li></ol><h2 id="二、序列视图概念" tabindex="-1"><a class="header-anchor" href="#二、序列视图概念" aria-hidden="true">#</a> 二、序列视图概念</h2><h3 id="_2-1-术语概念" tabindex="-1"><a class="header-anchor" href="#_2-1-术语概念" aria-hidden="true">#</a> 2.1 术语概念</h3><p>约定:若无特殊说明,本文档所指定的视图均是<strong>序列视图</strong>,未来可能引入设备视图等新功能。</p><h3 id="_2-2-序列视图" tabindex="-1"><a class="header-anchor" href="#_2-2-序列视图" aria-hidden="true">#</a> 2.2 序列视图</h3><p>序列视图是一种组织管理时间序列的方式。</p><p>在传统关系型数据库中,数据都必须存放在一个表中,而在IoTDB等时序数据库中,序列才是存储单元。因此,IoTDB中序列视图的概念也是建立在序列上的。</p><p>一个序列视图就是一条虚拟的时间序列,每条虚拟的时间序列都像是一条软链接或快捷方式,映射到某个视图外部的序列或者某种计算逻辑。换言之,一个虚拟序列要么映射到某个确定的外部序列,要么由多个外部序列运算得来。</p><p>用户可以使用复杂的SQL查询创建视图,此时序列视图就像一条被存储的查询语句,当从视图中读取数据时,就把被存储的查询语句作为数据来源,放在FROM子句中。</p><h3 id="_2-3-别名序列" tabindex="-1"><a class="header-anchor" href="#_2-3-别名序列" aria-hidden="true">#</a> 2.3 别名序列</h3><p>在序列视图中,有一类特殊的存在,他们满足如下所有条件:</p><ol><li>数据来源为单一的时间序列</li><li>没有任何计算逻辑</li><li>没有任何筛选条件(例如无WHERE子句的限制)</li></ol><p>这样的序列视图,被称为<strong>别名序列</strong>,或别名序列视图。不完全满足上述所有条件的序列视图,就称为非别名序列视图。他们之间的区别是:只有别名序列支持写入功能。</p><p><strong>所有序列视图包括别名序列目前均不支持触发器功能(Trigger)。</strong></p><h3 id="_2-4-嵌套视图" tabindex="-1"><a class="header-anchor" href="#_2-4-嵌套视图" aria-hidden="true">#</a> 2.4 嵌套视图</h3><p>用户可能想从一个现有的序列视图中选出若干序列,组成一个新的序列视图,就称之为嵌套视图。</p><p><strong>当前版本不支持嵌套视图功能</strong></p><h3 id="_2-5-iotdb中对序列视图的一些约束" tabindex="-1"><a class="header-anchor" href="#_2-5-iotdb中对序列视图的一些约束" aria-hidden="true">#</a> 2.5 IoTDB中对序列视图的一些约束</h3><h4 id="限制1-序列视图必须依赖于一个或者若干个时间序列" tabindex="-1"><a class="header-anchor" href="#限制1-序列视图必须依赖于一个或者若干个时间序列" aria-hidden="true">#</a> 限制1 序列视图必须依赖于一个或者若干个时间序列</h4><p>一个序列视图有两种可能的存在形式:</p><ol><li>它映射到一条时间序列</li><li>它由一条或若干条时间序列计算得来</li></ol><p>前种存在形式已在前文举例,易于理解;而此处的后一种存在形式,则是因为序列视图允许计算逻辑的存在。</p><p>比如,用户在同一个锅炉安装了两个温度计,现在需要计算两个温度值的平均值作为测量结果。用户采集到的是如下两个序列:<code>root.db.d01.temperature01</code><code>root.db.d01.temperature02</code></p><p>此时,用户可以使用两个序列求平均值,作为视图中的一条序列:<code>root.db.d01.avg_temperature</code></p><p>该例子会3.1.2详细展开。</p><h4 id="限制2-非别名序列视图是只读的" tabindex="-1"><a class="header-anchor" href="#限制2-非别名序列视图是只读的" aria-hidden="true">#</a> 限制2 非别名序列视图是只读的</h4><p>不允许向非别名序列视图写入。</p><p>只有别名序列视图是支持写入的。</p><h4 id="限制3-不允许嵌套视图" tabindex="-1"><a class="header-anchor" href="#限制3-不允许嵌套视图" aria-hidden="true">#</a> 限制3 不允许嵌套视图</h4><p>不能选定现有序列视图中的某些列来创建序列视图,无论是直接的还是间接的。</p><p>本限制将在3.1.3给出示例。</p><h4 id="限制4-序列视图与时间序列不能重名" tabindex="-1"><a class="header-anchor" href="#限制4-序列视图与时间序列不能重名" aria-hidden="true">#</a> 限制4 序列视图与时间序列不能重名</h4><p>序列视图和时间序列都位于同一棵树下,所以他们不能重名。</p><p>任何一条序列的名称(路径)都应该是唯一确定的。</p><h4 id="限制5-序列视图与时间序列的时序数据共用-标签等元数据不共用" tabindex="-1"><a class="header-anchor" href="#限制5-序列视图与时间序列的时序数据共用-标签等元数据不共用" aria-hidden="true">#</a> 限制5 序列视图与时间序列的时序数据共用,标签等元数据不共用</h4><p>序列视图是指向时间序列的映射,所以它们完全共用时序数据,由时间序列负责持久化存储。</p><p>但是它们的tag、attributes等元数据不共用。</p><p>这是因为进行业务查询时,面向视图的用户关心的是当前视图的结构,而如果使用group by tag等方式做查询,显然希望是得到视图下含有对应tag的分组效果,而非时间序列的tag的分组效果(用户甚至对那些时间序列毫无感知)。</p><h2 id="三、序列视图功能介绍" tabindex="-1"><a class="header-anchor" href="#三、序列视图功能介绍" aria-hidden="true">#</a> 三、序列视图功能介绍</h2><h3 id="_3-1-创建视图" tabindex="-1"><a class="header-anchor" href="#_3-1-创建视图" aria-hidden="true">#</a> 3.1 创建视图</h3><p>创建一个序列视图与创建一条时间序列类似,区别在于需要通过AS关键字指定数据来源,即原始序列。</p><h4 id="_3-1-1-创建视图的sql" tabindex="-1"><a class="header-anchor" href="#_3-1-1-创建视图的sql" aria-hidden="true">#</a> 3.1.1. 创建视图的SQL</h4><p>用户可以选取一些序列创建一个视图:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.view.device.status
AS
SELECT s01
FROM root.db.device
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>它表示用户从现有设备<code>root.db.device</code>中选出了<code>s01</code>这条序列,创建了序列视图<code>root.view.device.status</code></p><p>序列视图可以与时间序列存在于同一实体下,例如:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.device.status
AS
SELECT s01
FROM root.db.device
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这样,<code>root.db.device</code>下就有了<code>s01</code>的一份虚拟拷贝,但是使用不同的名字<code>status</code></p><p>可以发现,上述两个例子中的序列视图,都是别名序列,我们给用户提供一种针对该序列的更方便的创建方式:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.view.device.status
AS
root.db.device.s01
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="_3-1-2-创建含有计算逻辑的视图" tabindex="-1"><a class="header-anchor" href="#_3-1-2-创建含有计算逻辑的视图" aria-hidden="true">#</a> 3.1.2 创建含有计算逻辑的视图</h4><p>沿用2.2章节限制1中的例子:</p><blockquote><p>用户在同一个锅炉安装了两个温度计,现在需要计算两个温度值的平均值作为测量结果。用户采集到的是如下两个序列:<code>root.db.d01.temperature01</code><code>root.db.d01.temperature02</code></p><p>此时,用户可以使用两个序列求平均值,作为视图中的一条序列:<code>root.view.device01.avg_temperature</code></p></blockquote><p>如果不使用视图,用户可以这样查询两个温度的平均值:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>SELECT (temperature01 + temperature02) / 2
FROM root.db.d01
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>而如果使用序列视图,用户可以这样创建一个视图来简化将来的查询:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.d01.avg_temperature
AS
SELECT (temperature01 + temperature02) / 2
FROM root.db.d01
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>然后用户可以这样查询:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>SELECT avg_temperature FROM root.db.d01
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h4 id="_3-1-3-不支持嵌套序列视图" tabindex="-1"><a class="header-anchor" href="#_3-1-3-不支持嵌套序列视图" aria-hidden="true">#</a> 3.1.3 不支持嵌套序列视图</h4><p>继续沿用3.1.2中的例子,现在用户想使用序列视图<code>root.db.d01.avg_temperature</code>创建一个新的视图,这是不允许的。我们目前不支持嵌套视图,无论它是否是别名序列,都不支持。</p><p>比如下列SQL语句会报错:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.view.device.avg_temp_copy
AS
root.db.d01.avg_temperature -- 不支持。不允许嵌套视图
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="_3-1-4-一次创建多条序列视图" tabindex="-1"><a class="header-anchor" href="#_3-1-4-一次创建多条序列视图" aria-hidden="true">#</a> 3.1.4 一次创建多条序列视图</h4><p>一次只能指定一个序列视图对用户来说使用不方便,则可以一次指定多条序列,比如:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.device.status, root.db.device.sub.hardware
AS
SELECT s01, s02
FROM root.db.device
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>此外,上述写法可以做简化:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.device(status, sub.hardware)
AS
SELECT s01, s02
FROM root.db.device
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>上述两条语句都等价于如下写法:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.device.status
AS
SELECT s01
FROM root.db.device;
CREATE VIEW root.db.device.sub.hardware
AS
SELECT s02
FROM root.db.device
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>也等价于如下写法</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.device.status, root.db.device.sub.hardware
AS
root.db.device.s01, root.db.device.s02
-- 或者
CREATE VIEW root.db.device(status, sub.hardware)
AS
root.db.device(s01, s02)
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="所有序列间的映射关系为静态存储" tabindex="-1"><a class="header-anchor" href="#所有序列间的映射关系为静态存储" aria-hidden="true">#</a> 所有序列间的映射关系为静态存储</h5><p>有时,SELECT子句中可能包含运行时才能确定的语句个数,比如如下的语句:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>SELECT s01, s02
FROM root.db.d01, root.db.d02
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>上述语句能匹配到的序列数量是并不确定的,和系统状态有关。即便如此,用户也可以使用它创建视图。</p><p>不过需要特别注意,所有序列间的映射关系为静态存储(创建时固定)!请看以下示例:</p><p>当前数据库中仅含有<code>root.db.d01.s01</code><code>root.db.d02.s01</code><code>root.db.d02.s02</code>三条序列,接着创建视图:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.view.d(alpha, beta, gamma)
AS
SELECT s01, s02
FROM root.db.d01, root.db.d02
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>时间序列之间映射关系如下:</p><table><thead><tr><th>序号</th><th>时间序列</th><th>序列视图</th></tr></thead><tbody><tr><td>1</td><td><code>root.db.d01.s01</code></td><td>root.view.d.alpha</td></tr><tr><td>2</td><td><code>root.db.d02.s01</code></td><td>root.view.d.beta</td></tr><tr><td>3</td><td><code>root.db.d02.s02</code></td><td>root.view.d.gamma</td></tr></tbody></table><p>此后,用户新增了序列<code>root.db.d01.s02</code>,则它不对应到任何视图;接着,用户删除<code>root.db.d01.s01</code>,则查询<code>root.view.d.alpha</code>会直接报错,它也不会对应到<code>root.db.d01.s02</code></p><p>请时刻注意,序列间映射关系是静态地、固化地存储的。</p><h4 id="_3-1-5-批量创建序列视图" tabindex="-1"><a class="header-anchor" href="#_3-1-5-批量创建序列视图" aria-hidden="true">#</a> 3.1.5 批量创建序列视图</h4><p>现有若干个设备,每个设备都有一个温度数值,例如:</p><ol><li>root.db.d1.temperature</li><li>root.db.d2.temperature</li><li>...</li></ol><p>这些设备下可能存储了很多其他序列(例如<code>root.db.d1.speed</code>),但目前可以创建一个视图,只包含这些设备的温度值,而不关系其他序列:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.view(${2}_temperature)
AS
SELECT temperature FROM root.db.*
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>这里仿照了查询写回(<code>SELECT INTO</code>)对命名规则的约定,使用变量占位符来指定命名规则。可以参考:<a href="/zh/UserGuide/Master/User-Manual/Query-Data.html#%E6%9F%A5%E8%AF%A2%E5%86%99%E5%9B%9E%EF%BC%88INTO-%E5%AD%90%E5%8F%A5%EF%BC%89" class="">查询写回(SELECT INTO)</a></p><p>这里<code>root.db.*.temperature</code>指定了有哪些时间序列会被包含在视图中;<code>${2}</code>则指定了从时间序列中的哪个节点提取出名字来命名序列视图。</p><p>此处,<code>${2}</code>指代的是<code>root.db.*.temperature</code>的层级2(从 0 开始),也就是<code>*</code>的匹配结果;<code>${2}_temperature</code>则是将匹配结果与<code>temperature</code>通过下划线拼接了起来,构成视图下各序列的节点名称。</p><p>上述创建视图的语句,和下列写法是等价的:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.view(${2}_${3})
AS
SELECT temperature from root.db.*
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>最终视图中含有这些序列:</p><ol><li>root.db.view.d1_temperature</li><li>root.db.view.d2_temperature</li><li>...</li></ol><p>使用通配符创建,只会存储创建时刻的静态映射关系。</p><h4 id="_3-1-6-创建视图时select子句受到一定限制" tabindex="-1"><a class="header-anchor" href="#_3-1-6-创建视图时select子句受到一定限制" aria-hidden="true">#</a> 3.1.6 创建视图时SELECT子句受到一定限制</h4><p>创建序列视图时,使用的SELECT子句受到一定限制。主要限制如下:</p><ol><li>不能使用<code>WHERE</code>子句。</li><li>不能使用<code>GROUP BY</code>子句。</li><li>不能使用<code>MAX_VALUE</code>等聚合函数。</li></ol><p>简单来说,<code>AS</code>后只能使用<code>SELECT ... FROM ... </code>的结构,且该查询语句的结果必须能构成一条时间序列。</p><h3 id="_3-2-视图数据查询" tabindex="-1"><a class="header-anchor" href="#_3-2-视图数据查询" aria-hidden="true">#</a> 3.2 视图数据查询</h3><p>对于可以支持的数据查询功能,在执行时序数据查询时,序列视图与时间序列可以无差别使用,行为完全一致。</p><p><strong>目前序列视图不支持的查询类型如下:</strong></p><ol><li><strong>align by device 查询</strong></li><li><strong>group by tags 查询</strong></li></ol><p>用户也可以在同一个SELECT语句中混合查询时间序列与序列视图,比如:</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>SELECT temperature01, temperature02, avg_temperature
FROM root.db.d01
WHERE temperature01 &lt; temperature02
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>但是,如果用户想要查询序列的元数据,例如tag、attributes等,则查询到的是序列视图的结果,而并非序列视图所引用的时间序列的结果。</p><p>此外,对于别名序列,如果用户想要得到时间序列的tag、attributes等信息,则需要先查询视图列的映射,找到对应的时间序列,再向时间序列查询tag、attributes等信息。查询视图列的映射的方法将会在3.5部分说明。</p><h3 id="_3-3-视图修改" tabindex="-1"><a class="header-anchor" href="#_3-3-视图修改" aria-hidden="true">#</a> 3.3 视图修改</h3><p>对视图的修改,例如改名、修改计算逻辑、删除等操作,都和创建新的视图类似,需要重新指定整个视图的全部列相关的描述。</p><h4 id="_3-3-1-修改视图数据来源" tabindex="-1"><a class="header-anchor" href="#_3-3-1-修改视图数据来源" aria-hidden="true">#</a> 3.3.1 修改视图数据来源</h4><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER VIEW root.view.device.status
AS
SELECT s01
FROM root.ln.wf.d01
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="_3-3-2-修改视图的计算逻辑" tabindex="-1"><a class="header-anchor" href="#_3-3-2-修改视图的计算逻辑" aria-hidden="true">#</a> 3.3.2 修改视图的计算逻辑</h4><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER VIEW root.db.d01.avg_temperature
AS
SELECT (temperature01 + temperature02 + temperature03) / 3
FROM root.db.d01
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="_3-3-3-标签点管理" tabindex="-1"><a class="header-anchor" href="#_3-3-3-标签点管理" aria-hidden="true">#</a> 3.3.3 标签点管理</h4><ul><li>添加新的标签</li></ul><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER view root.turbine.d1.s1 ADD TAGS tag3=v3, tag4=v4
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>添加新的属性</li></ul><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER view root.turbine.d1.s1 ADD ATTRIBUTES attr3=v3, attr4=v4
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>重命名标签或属性</li></ul><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER view root.turbine.d1.s1 RENAME tag1 TO newTag1
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>重新设置标签或属性的值</li></ul><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER view root.turbine.d1.s1 SET newTag1=newV1, attr1=newV1
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>删除已经存在的标签或属性</li></ul><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER view root.turbine.d1.s1 DROP tag1, tag2
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><ul><li>更新插入别名,标签和属性</li></ul><blockquote><p>如果该别名,标签或属性原来不存在,则插入,否则,用新值更新原来的旧值</p></blockquote><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>ALTER view root.turbine.d1.s1 UPSERT TAGS(tag2=newV2, tag3=v3) ATTRIBUTES(attr3=v3, attr4=v4)
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h4 id="_3-3-4-删除视图" tabindex="-1"><a class="header-anchor" href="#_3-3-4-删除视图" aria-hidden="true">#</a> 3.3.4 删除视图</h4><p>因为一个视图就是一条序列,因此可以像删除时间序列一样删除一个视图。</p><p>扩充原有删除时间序列的方法,不新增<code>DELETE VIEW</code>的语句。</p><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>DELETE VIEW root.view.device.avg_temperatue
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="_3-4-视图同步" tabindex="-1"><a class="header-anchor" href="#_3-4-视图同步" aria-hidden="true">#</a> 3.4 视图同步</h3><p>序列视图的数据总是经由实时的查询获得,因此天然支持数据同步。</p><h4 id="如果依赖的原序列被删除了" tabindex="-1"><a class="header-anchor" href="#如果依赖的原序列被删除了" aria-hidden="true">#</a> 如果依赖的原序列被删除了</h4><p>当序列视图查询时(序列解析时),如果依赖的时间序列不存在,则<strong>返回空结果集</strong></p><p>这和查询一个不存在的序列的反馈类似,但是有区别:如果依赖的时间序列无法解析,空结果集是包含表头的,以此来提醒用户该视图是存在问题的。</p><p>此外,被依赖的时间序列删除时,不会去查找是否有依赖于该列的视图,用户不会收到任何警告。</p><h4 id="不支持非别名序列的数据写入" tabindex="-1"><a class="header-anchor" href="#不支持非别名序列的数据写入" aria-hidden="true">#</a> 不支持非别名序列的数据写入</h4><p>不支持向非别名序列的写入。</p><p>详情请参考前文 2.1.6 限制2</p><h4 id="序列的元数据不共用" tabindex="-1"><a class="header-anchor" href="#序列的元数据不共用" aria-hidden="true">#</a> 序列的元数据不共用</h4><p>详情请参考前文2.1.6 限制5</p><h3 id="_3-5-视图元数据查询" tabindex="-1"><a class="header-anchor" href="#_3-5-视图元数据查询" aria-hidden="true">#</a> 3.5 视图元数据查询</h3><p>视图元数据查询,特指查询视图本身的元数据(例如视图有多少列),以及数据库内视图的信息(例如有哪些视图)。</p><h4 id="_3-5-1-查看当前的视图列" tabindex="-1"><a class="header-anchor" href="#_3-5-1-查看当前的视图列" aria-hidden="true">#</a> 3.5.1 查看当前的视图列</h4><p>用户有两种查询方式:</p><ol><li>使用<code>SHOW TIMESERIES</code>进行查询,该查询既包含时间序列,也包含序列视图。但是只能显示视图的部分属性</li><li>使用<code>SHOW VIEW</code>进行查询,该查询只包含序列视图。能完整显示序列视图的属性。</li></ol><p>举例:</p><div class="language-Shell line-numbers-mode" data-ext="Shell"><pre class="language-Shell"><code>IoTDB&gt; show timeseries;
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
| Timeseries|Alias|Database|DataType|Encoding|Compression|Tags|Attributes|Deadband|DeadbandParameters|ViewType|
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.db.device.s01 | null| root.db| INT32| RLE| SNAPPY|null| null| null| null| BASE|
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.db.view.status | null| root.db| INT32| RLE| SNAPPY|null| null| null| null| VIEW|
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.db.d01.temp01 | null| root.db| FLOAT| RLE| SNAPPY|null| null| null| null| BASE|
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.db.d01.temp02 | null| root.db| FLOAT| RLE| SNAPPY|null| null| null| null| BASE|
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
|root.db.d01.avg_temp| null| root.db| FLOAT| null| null|null| null| null| null| VIEW|
+--------------------+-----+--------+--------+--------+-----------+----+----------+--------+------------------+--------+
Total line number = 5
It costs 0.789s
IoTDB&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>最后一列<code>ViewType</code>中显示了该序列的类型,时间序列为BASE,序列视图是VIEW。</p><p>此外,某些序列视图的属性会缺失,比如<code>root.db.d01.avg_temp</code>是由温度均值计算得来,所以<code>Encoding</code><code>Compression</code>属性都为空值。</p><p>此外,<code>SHOW TIMESERIES</code>语句的查询结果主要分为两部分:</p><ol><li>时序数据的信息,例如数据类型,压缩方式,编码等</li><li>其他元数据信息,例如tag,attribute,所属database等</li></ol><p>对于序列视图,展示的时序数据信息与其原始序列一致或者为空值(比如计算得到的平均温度有数据类型但是无压缩方式);展示的元数据信息则是视图的内容。</p><p>如果要得知视图的更多信息,需要使用<code>SHOW ``VIEW</code><code>SHOW ``VIEW</code>中展示视图的数据来源等。</p><div class="language-Shell line-numbers-mode" data-ext="Shell"><pre class="language-Shell"><code>IoTDB&gt; show VIEW root.**;
+--------------------+--------+--------+----+----------+--------+-----------------------------------------+
| Timeseries|Database|DataType|Tags|Attributes|ViewType| SOURCE|
+--------------------+--------+--------+----+----------+--------+-----------------------------------------+
|root.db.view.status | root.db| INT32|null| null| VIEW| root.db.device.s01|
+--------------------+--------+--------+----+----------+--------+-----------------------------------------+
|root.db.d01.avg_temp| root.db| FLOAT|null| null| VIEW|(root.db.d01.temp01+root.db.d01.temp02)/2|
+--------------------+--------+--------+----+----------+--------+-----------------------------------------+
Total line number = 2
It costs 0.789s
IoTDB&gt;
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>最后一列<code>SOURCE</code>显示了该序列视图的数据来源,列出了创建该序列的SQL语句。</p><h5 id="关于数据类型" tabindex="-1"><a class="header-anchor" href="#关于数据类型" aria-hidden="true">#</a> 关于数据类型</h5><p>上述两种查询都涉及视图的数据类型。视图的数据类型是根据定义视图的查询语句或别名序列的原始时间序列类型推断出来的。这个数据类型是根据当前系统的状态实时计算出来的,因此在不同时刻查询到的数据类型可能是改变的。</p><h2 id="四、faq" tabindex="-1"><a class="header-anchor" href="#四、faq" aria-hidden="true">#</a> 四、FAQ</h2><h4 id="q1-我想让视图实现类型转换的功能。例如-原有一个int32类型的时间序列-和其他int64类型的序列被放在了同一个视图中。我现在希望通过视图查询到的数据-都能自动转换为int64类型。" tabindex="-1"><a class="header-anchor" href="#q1-我想让视图实现类型转换的功能。例如-原有一个int32类型的时间序列-和其他int64类型的序列被放在了同一个视图中。我现在希望通过视图查询到的数据-都能自动转换为int64类型。" aria-hidden="true">#</a> Q1:我想让视图实现类型转换的功能。例如,原有一个int32类型的时间序列,和其他int64类型的序列被放在了同一个视图中。我现在希望通过视图查询到的数据,都能自动转换为int64类型。</h4><blockquote><p>Ans:这不是序列视图的职能范围。但是可以使用<code>CAST</code>进行转换,比如:</p></blockquote><div class="language-SQL line-numbers-mode" data-ext="SQL"><pre class="language-SQL"><code>CREATE VIEW root.db.device.int64_status
AS
SELECT CAST(s1, &#39;type&#39;=&#39;INT64&#39;) from root.db.device
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote><p>这样,查询<code>root.view.status</code>时,就会得到int64类型的结果。</p><p>请特别注意,上述例子中,序列视图的数据是通过<code>CAST</code>转换得到的,因此<code>root.db.device.int64_status</code>并不是一条别名序列,也就<strong>不支持写入</strong></p></blockquote><h4 id="q2-是否支持默认命名-选择若干时间序列-创建视图-但是我不指定每条序列的名字-由数据库自动命名" tabindex="-1"><a class="header-anchor" href="#q2-是否支持默认命名-选择若干时间序列-创建视图-但是我不指定每条序列的名字-由数据库自动命名" aria-hidden="true">#</a> Q2:是否支持默认命名?选择若干时间序列,创建视图;但是我不指定每条序列的名字,由数据库自动命名?</h4><blockquote><p>Ans:不支持。用户必须明确指定命名。</p></blockquote><h4 id="q3-在原有体系中-创建时间序列root-db-device-s01-可以发现自动创建了databaseroot-db-自动创建了deviceroot-db-device。接着删除时间序列root-db-device-s01-可以发现root-db-device被自动删除-root-db却还是保留的。对于创建视图-会沿用这一机制吗-出于什么考虑呢" tabindex="-1"><a class="header-anchor" href="#q3-在原有体系中-创建时间序列root-db-device-s01-可以发现自动创建了databaseroot-db-自动创建了deviceroot-db-device。接着删除时间序列root-db-device-s01-可以发现root-db-device被自动删除-root-db却还是保留的。对于创建视图-会沿用这一机制吗-出于什么考虑呢" aria-hidden="true">#</a> Q3:在原有体系中,创建时间序列<code>root.db.device.s01</code>,可以发现自动创建了database<code>root.db</code>,自动创建了device<code>root.db.device</code>。接着删除时间序列<code>root.db.device.s01</code>,可以发现<code>root.db.device</code>被自动删除,<code>root.db</code>却还是保留的。对于创建视图,会沿用这一机制吗?出于什么考虑呢?</h4><blockquote><p>Ans:保持原有的行为不变,引入视图功能不会改变原有的这些逻辑。</p></blockquote><h4 id="q4-是否支持序列视图重命名" tabindex="-1"><a class="header-anchor" href="#q4-是否支持序列视图重命名" aria-hidden="true">#</a> Q4:是否支持序列视图重命名?</h4><blockquote><p>A:当前版本不支持重命名,可以自行创建新名称的视图投入使用。</p></blockquote></div><!--[--><!----><!--]--><footer class="page-meta"><div class="meta-item edit-link"><a href="https://github.com/apache/iotdb-docs/edit/main/src/zh/UserGuide/Master/User-Manual/IoTDB-View_timecho.md" rel="noopener noreferrer" target="_blank" aria-label="发现错误?在 GitHub 上编辑此页" class="nav-link label"><!--[--><svg xmlns="http://www.w3.org/2000/svg" class="icon edit-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="edit icon"><path d="M430.818 653.65a60.46 60.46 0 0 1-50.96-93.281l71.69-114.012 7.773-10.365L816.038 80.138A60.46 60.46 0 0 1 859.225 62a60.46 60.46 0 0 1 43.186 18.138l43.186 43.186a60.46 60.46 0 0 1 0 86.373L588.879 565.55l-8.637 8.637-117.466 68.234a60.46 60.46 0 0 1-31.958 11.229z"></path><path d="M728.802 962H252.891A190.883 190.883 0 0 1 62.008 771.98V296.934a190.883 190.883 0 0 1 190.883-192.61h267.754a60.46 60.46 0 0 1 0 120.92H252.891a69.962 69.962 0 0 0-69.098 69.099V771.98a69.962 69.962 0 0 0 69.098 69.098h475.911A69.962 69.962 0 0 0 797.9 771.98V503.363a60.46 60.46 0 1 1 120.922 0V771.98A190.883 190.883 0 0 1 728.802 962z"></path></svg><!--]-->发现错误?在 GitHub 上编辑此页<span><svg class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a></div><div class="meta-item git-info"><div class="update-time"><span class="label">上次编辑于: </span><!----></div><div class="contributors"><span class="label">贡献者: </span><!--[--><!--[--><span class="contributor" title="email: 105700158+wanghui42@users.noreply.github.com">wanghui42</span><!--]--><!--]--></div></div></footer><!----><!----><!--[--><!----><!--]--><!--]--></main><!--]--><footer style="padding-bottom:2rem;"><span id="doc-version" style="display:none;">latest</span><p style="text-align:center;color:#909399;font-size:12px;margin:0 30px;">Copyright © 2024 The Apache Software Foundation.<br> Apache and the Apache feather logo are trademarks of The Apache Software Foundation</p><p style="text-align:center;margin-top:10px;color:#909399;font-size:12px;margin:0 30px;"><strong>Have a question?</strong> Connect with us on QQ, WeChat, or Slack. <a href="https://github.com/apache/iotdb/issues/1995">Join the community</a> now.</p></footer></div><!--]--><!--]--><!----><!--]--></div>
<script type="module" src="/assets/app-z4N-28Th.js" defer></script>
</body>
</html>