提交 0fd5cb50 编写于 作者: B Boris 提交者: Jialin Qiao

[IOTDB-282] add "show version" (#507)

* add "show version" query
上级 c647b184
......@@ -22,6 +22,19 @@
# 第5章 IoTDB操作指南
## SQL 参考文档
### 显示版本号
```sql
show version
```
```
+---------------------------------------------------------------------------+
| 0.9.0-SNAPSHOT|
+---------------------------------------------------------------------------+
It costs 0.001s
```
### Schema语句
* 设置存储组
......
......@@ -30,6 +30,18 @@ In this part, we will introduce you IoTDB's Query Language. IoTDB offers you a S
All of these statements are write in IoTDB's own syntax, for details about the syntax composition, please check the `Reference` section.
### Show Version
```sql
show version
```
```
+---------------------------------------------------------------------------+
| 0.9.0-SNAPSHOT|
+---------------------------------------------------------------------------+
It costs 0.001s
```
### Schema Statement
......
......@@ -24,7 +24,7 @@ public class Constant {
public static final String GLOBAL_DB_NAME = "IoTDB";
static final String GLOBAL_DB_VERSION = "0.8.0-SNAPSHOT";
static final String GLOBAL_VERSION = "VERSION";
public static final String GLOBAL_COLUMN_REQ = "COLUMN";
......@@ -47,6 +47,7 @@ public class Constant {
public static final String CATALOG_TIMESERIES = "ts";
public static final String CATALOG_STORAGE_GROUP = "sg";
public static final String CATALOG_DEVICES = "devices";
public static final String CATALOG_VERSION = "version";
static final String COUNT_TIMESERIES = "cntts";
static final String COUNT_NODE_TIMESERIES = "cntnodets";
......
......@@ -147,6 +147,20 @@ public class IoTDBDatabaseMetadata implements DatabaseMetaData {
} catch (TException e) {
throw new TException("Connection error when fetching timeseries metadata", e);
}
case Constant.CATALOG_VERSION:
req = new TSFetchMetadataReq(Constant.GLOBAL_VERSION);
req.setColumnPath(schemaPattern);
try {
TSFetchMetadataResp resp = client.fetchMetadata(req);
try {
RpcUtils.verifySuccess(resp.getStatus());
} catch (IoTDBRPCException e) {
throw new IoTDBSQLException(e.getMessage(), resp.getStatus());
}
return new IoTDBMetadataResultSet(resp.getVersion(), MetadataType.VERSION);
} catch (TException e) {
throw new TException("Connection error when fetching timeseries metadata", e);
}
default:
throw new SQLException(catalog + " is not supported. Please refer to the user guide"
+ " for more details.");
......@@ -335,8 +349,8 @@ public class IoTDBDatabaseMetadata implements DatabaseMetaData {
}
@Override
public String getDatabaseProductVersion() {
return Constant.GLOBAL_DB_VERSION;
public String getDatabaseProductVersion() throws SQLException {
throw new SQLException(METHOD_NOT_SUPPORTED_STRING);
}
@Override
......
......@@ -42,6 +42,7 @@ public class IoTDBMetadataResultSet extends IoTDBQueryResultSet {
private String currentColumn;
private String currentStorageGroup;
private String currentDevice;
private String currentVersion;
private List<String> currentTimeseries;
private List<String> timeseriesNumList;
private List<String> nodesNumList;
......@@ -109,6 +110,14 @@ public class IoTDBMetadataResultSet extends IoTDBQueryResultSet {
showLabels = new String[]{"column", "count"};
columnItr = nodeTimeseriesNumMap.entrySet().iterator();
break;
case VERSION:
String version = (String) object;
colCount = 1;
showLabels = new String[]{version};
Set<String> versionSet = new HashSet<>();
versionSet.add(version);
columnItr = versionSet.iterator();
break;
default:
throw new SQLException("TsfileMetadataResultSet constructor is wrongly used.");
}
......@@ -262,6 +271,10 @@ public class IoTDBMetadataResultSet extends IoTDBQueryResultSet {
currentNode = (String) pair.getKey();
currentNodeTimeseriesNum = (String) pair.getValue();
break;
case VERSION:
currentVersion = (String) columnItr.next();
hasNext = false;
break;
default:
break;
}
......@@ -396,6 +409,6 @@ public class IoTDBMetadataResultSet extends IoTDBQueryResultSet {
}
public enum MetadataType {
STORAGE_GROUP, TIMESERIES, COLUMN, DEVICES, COUNT_TIMESERIES, COUNT_NODES, COUNT_NODE_TIMESERIES
STORAGE_GROUP, TIMESERIES, COLUMN, DEVICES, COUNT_TIMESERIES, COUNT_NODES, COUNT_NODE_TIMESERIES, VERSION
}
}
......@@ -53,6 +53,7 @@ public class IoTDBStatement implements Statement {
private static final String COUNT_TIMESERIES_COMMAND_LOWERCASE = "count timeseries";
private static final String COUNT_NODES_COMMAND_LOWERCASE = "count nodes";
private static final String METHOD_NOT_SUPPORTED_STRING = "Method not supported";
private static final String SHOW_VERSION_COMMAND_LOWERCASE = "show version";
ZoneId zoneId;
private ResultSet resultSet = null;
......@@ -287,6 +288,10 @@ public class IoTDBStatement implements Statement {
resultSet = databaseMetaData.getNodes(Constant.COUNT_NODES, path, null, null, level);
return true;
}
} else if(sqlToLowerCase.equals(SHOW_VERSION_COMMAND_LOWERCASE)) {
IoTDBDatabaseMetadata databaseMetadata = (IoTDBDatabaseMetadata) connection.getMetaData();
resultSet = databaseMetadata.getColumns(Constant.CATALOG_VERSION, null, null, null);
return true;
} else {
TSExecuteStatementReq execReq = new TSExecuteStatementReq(sessionHandle, sql);
TSExecuteStatementResp execResp = client.executeStatement(execReq);
......
#
# 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.
#
group_size_in_byte=134217728
# The memory size for each series writer to pack page, default value is 64KB
page_size_in_byte=65536
# The maximum number of data points in a page, default 1024*1024
max_number_of_points_in_page=1048576
# Data type configuration
# Data type for input timestamp, TsFile supports INT32 or INT64
time_series_data_type=INT64
# Max size limitation of input string
max_string_length=128
# Floating-point precision
float_precision=2
# Encoder configuration
# Encoder of time series, TsFile supports TS_2DIFF, PLAIN and RLE(run-length encoding) and default value is TS_2DIFF
time_encoder=TS_2DIFF
# Encoder of value series. default value is PLAIN.
# For int, long data type, TsFile also supports TS_2DIFF and RLE(run-length encoding).
# For float, double data type, TsFile also supports TS_2DIFF, RLE(run-length encoding) and GORILLA.
# For text data type, TsFile only supports PLAIN.
value_encoder=PLAIN
# Compression configuration
# Data compression method, TsFile supports UNCOMPRESSED or SNAPPY. Default value is UNCOMPRESSED which means no compression
compressor=UNCOMPRESSED
# The acceptable error rate of bloom filter, should be in [0.01, 0.1], default is 0.05
bloom_filter_error_rate=0.05
......@@ -346,6 +346,10 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
resp.setNodeTimeseriesNum(getNodeTimeseriesNum(getNodesList(req.getColumnPath(), req.getNodeLevel())));
status = new TSStatus(getStatus(TSStatusCode.SUCCESS_STATUS));
break;
case "VERSION":
resp.setVersion(getVersion());
status = new TSStatus(getStatus(TSStatusCode.SUCCESS_STATUS));
break;
default:
status = getStatus(TSStatusCode.FETCH_METADATA_ERROR, req.getType());
break;
......@@ -384,6 +388,10 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
return MManager.getInstance().getAllDevices();
}
private String getVersion() throws SQLException {
return IoTDBConstant.VERSION;
}
private List<List<String>> getTimeSeriesForPath(String path)
throws PathErrorException {
return MManager.getInstance().getShowTimeseriesPath(path);
......
......@@ -27,6 +27,7 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.service.IoTDB;
import org.apache.iotdb.db.utils.EnvironmentUtils;
import org.apache.iotdb.jdbc.Config;
......@@ -85,7 +86,7 @@ public class IoTDBMetadataFetchIT {
}
@Test
public void showTimeseriesTest1() throws ClassNotFoundException, SQLException {
public void showTimeseriesTest() throws ClassNotFoundException, SQLException {
Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
......@@ -201,6 +202,27 @@ public class IoTDBMetadataFetchIT {
}
}
@Test
public void showVersion() throws SQLException, ClassNotFoundException {
Class.forName(Config.JDBC_DRIVER_NAME);
try (Connection connection = DriverManager
.getConnection(Config.IOTDB_URL_PREFIX + "127.0.0.1:6667/", "root", "root");
Statement statement = connection.createStatement()) {
String sql = "show version";
try {
boolean hasResultSet = statement.execute(sql);
if(hasResultSet) {
try(ResultSet resultSet = statement.getResultSet()) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
Assert.assertEquals(resultSetMetaData.getColumnLabel(1), IoTDBConstant.VERSION);
}
}
} catch (Exception e) {
fail(e.getMessage());
}
}
}
/**
* get all columns' name under a given seriesPath
*/
......@@ -307,7 +329,7 @@ public class IoTDBMetadataFetchIT {
String standard = "Storage Group,\n" + "root.ln.wf01.wt01,\n";
try (ResultSet resultSet = databaseMetaData
.getColumns(Constant.CATALOG_STORAGE_GROUP, null, null, null);) {
.getColumns(Constant.CATALOG_STORAGE_GROUP, null, null, null)) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int colCount = resultSetMetaData.getColumnCount();
StringBuilder resultStr = new StringBuilder();
......
......@@ -53,7 +53,6 @@ Last Updated on October 27th, 2019 by Lei Rui.
| Add method TSStatus deleteStorageGroups(1:list\<string> storageGroup) | Yi Tao |
## 3. Update
| Latest Changes | Related Committers |
......@@ -72,6 +71,7 @@ Last Updated on October 27th, 2019 by Lei Rui.
| Rename some fields in TSFetchMetadataResp: ~~ColumnsList~~ to columnsList, ~~showTimeseriesList~~ to timeseriesList, ~~showStorageGroups~~ to storageGroups | Zesong Sun |
| Change struct TSQueryDataSet to eliminate row-wise rpc writing | Lei Rui |
| Add optional i32 timeseriesNum in TSFetchMetadataResp | Jack Tsai |
| Add optional string version in TSFetchMetadataResp | Genius_pig |
......@@ -184,6 +184,7 @@ struct TSFetchMetadataResp{
8: optional set<string> devices
9: optional list<string> nodesList
10: optional map<string, string> nodeTimeseriesNum
11: optional string version
}
struct TSFetchMetadataReq{
......
#
# 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.
#
# Memory size threshold for flushing to disk or HDFS, default value is 128MB
group_size_in_byte=134217728
# The memory size for each series writer to pack page, default value is 1MB
page_size_in_byte=1048576
# The maximum number of data points in a page, defalut 1024*1024
max_number_of_points_in_page=1048576
# The acceptable error rate of bloom filter, should be in [0.01, 0.1]
bloom_filter_error_rate=0.05
# Data type configuration
# Data type for input timestamp, TsFile supports INT32 or INT64
time_series_data_type=INT64
# Max length limitation of input string
max_string_length=128
# Floating-point precision
float_precision=2
# Encoder configuration
# Encoder of time series, TsFile supports TS_2DIFF, PLAIN and RLE(run-length encoding) and default value is TS_2DIFF
time_series_encoder=TS_2DIFF
# Encoder of value series. default value is PLAIN.
# For int, long data type, TsFile also supports TS_2DIFF and RLE(run-length encoding).
# For float, double data type, TsFile also supports TS_2DIFF, RLE(run-length encoding) and GORILLA.
# For text data type, TsFile only supports PLAIN.
value_encoder=PLAIN
# Compression configuration
# Data compression method, TsFile supports UNCOMPRESSED or SNAPPY. Default value is UNCOMPRESSED which means no compression
compressor=UNCOMPRESSED
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册