提交 0212fd85 编写于 作者: B Boris 提交者: Jialin Qiao

Move show version to server-side (#630)

* move show version to the server and use antlr to parse it.
上级 919cbcab
......@@ -24,8 +24,6 @@ public class Constant {
public static final String GLOBAL_DB_NAME = "IoTDB";
static final String GLOBAL_VERSION = "VERSION";
public static final String GLOBAL_COLUMN_REQ = "COLUMN";
static final String GLOBAL_SHOW_DEVICES_REQ = "SHOW_DEVICES";
......@@ -50,7 +48,6 @@ public class Constant {
public static final String CATALOG_STORAGE_GROUP = "sg";
public static final String CATALOG_DEVICES = "devices";
public static final String CATALOG_CHILD_PATHS = "cp";
public static final String CATALOG_VERSION = "version";
static final String COUNT_TIMESERIES = "cntts";
static final String COUNT_NODE_TIMESERIES = "cntnodets";
......
......@@ -161,20 +161,6 @@ 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.");
......
......@@ -24,7 +24,7 @@ import java.sql.SQLException;
import java.sql.Types;
/*
TsfileMetadataResultMetadata implements a similar api like TsFileQueryResultSet
IoTDBMetadataResultMetadata implements a similar api like IoTDBQueryResultSet
to display column metadata.
*/
......
......@@ -44,7 +44,6 @@ public class IoTDBMetadataResultSet extends IoTDBQueryResultSet {
private String currentStorageGroup;
private String currentDevice;
private String currentChildPath;
private String currentVersion;
private List<String> currentTimeseries;
private List<String> timeseriesNumList;
private List<String> nodesNumList;
......@@ -282,10 +281,6 @@ 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;
}
......
......@@ -53,7 +53,6 @@ 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;
......@@ -316,10 +315,6 @@ 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, stmtId);
TSExecuteStatementResp execResp = client.executeStatement(execReq);
......
......@@ -69,11 +69,11 @@ statement
| SHOW ALL TTL #showAllTTLStatement
| SHOW FLUSH TASK INFO #showFlushTaskInfo
| SHOW DYNAMIC PARAMETER #showDynamicParameter
| SHOW VERSION #showVersion
| LOAD CONFIGURATION #loadConfigurationStatement
| LOAD FILE autoCreateSchema? #loadFiles
| REMOVE FILE#removeFile
| REMOVE FILE #removeFile
| MOVE FILE FILE #moveFile
| SELECT INDEX func=ID //not support yet
LR_BRACKET
p1=timeseriesPath COMMA p2=timeseriesPath COMMA n1=timeValue COMMA n2=timeValue COMMA
......@@ -621,6 +621,11 @@ PARAMETER
: P A R A M E T E R
;
VERSION
: V E R S I O N
;
REMOVE
: R E M O V E
;
......
......@@ -128,6 +128,7 @@ public class SQLConstant {
public static final int TOK_LOAD_FILES = 69;
public static final int TOK_REMOVE_FILE = 70;
public static final int TOK_MOVE_FILE = 71;
public static final int TOK_VERSION = 72;
public static final Map<Integer, String> tokenSymbol = new HashMap<>();
public static final Map<Integer, String> tokenNames = new HashMap<>();
......
......@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.iotdb.db.conf.IoTDBConstant;
import org.apache.iotdb.db.conf.IoTDBDescriptor;
import org.apache.iotdb.db.conf.adapter.CompressionRatio;
import org.apache.iotdb.db.conf.adapter.IoTDBConfigDynamicAdapter;
......@@ -40,13 +41,18 @@ import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.metadata.MManager;
import org.apache.iotdb.db.metadata.MNode;
import org.apache.iotdb.db.qp.physical.PhysicalPlan;
import org.apache.iotdb.db.qp.physical.crud.*;
import org.apache.iotdb.db.qp.physical.crud.AggregationPlan;
import org.apache.iotdb.db.qp.physical.crud.DeletePlan;
import org.apache.iotdb.db.qp.physical.crud.FillQueryPlan;
import org.apache.iotdb.db.qp.physical.crud.GroupByPlan;
import org.apache.iotdb.db.qp.physical.crud.QueryPlan;
import org.apache.iotdb.db.qp.physical.sys.AuthorPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowPlan;
import org.apache.iotdb.db.qp.physical.sys.ShowTTLPlan;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.dataset.DeviceIterateDataSet;
import org.apache.iotdb.db.query.dataset.ListDataSet;
import org.apache.iotdb.db.query.dataset.SingleDataSet;
import org.apache.iotdb.db.query.executor.EngineQueryRouter;
import org.apache.iotdb.db.query.executor.IEngineQueryRouter;
import org.apache.iotdb.tsfile.exception.filter.QueryFilterOptimizationException;
......@@ -58,15 +64,6 @@ import org.apache.iotdb.tsfile.read.expression.QueryExpression;
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.apache.iotdb.tsfile.utils.Binary;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.apache.iotdb.db.conf.IoTDBConstant.STORAGE_GROUP;
import static org.apache.iotdb.db.conf.IoTDBConstant.TTL;
public abstract class AbstractQueryProcessExecutor implements IQueryProcessExecutor {
IEngineQueryRouter queryRouter = new EngineQueryRouter();
......@@ -93,6 +90,8 @@ public abstract class AbstractQueryProcessExecutor implements IQueryProcessExecu
return processShowDynamicParameterQuery();
case FLUSH_TASK_INFO:
return processShowFlushTaskInfo();
case VERSION:
return processShowVersion();
default:
throw new QueryProcessException(String.format("Unrecognized show plan %s", showPlan));
}
......@@ -134,6 +133,20 @@ public abstract class AbstractQueryProcessExecutor implements IQueryProcessExecu
return listDataSet;
}
private QueryDataSet processShowVersion() {
List<Path> paths = new ArrayList<>();
List<TSDataType> dataTypes = new ArrayList<>();
paths.add(new Path("root"));
dataTypes.add(TSDataType.TEXT);
SingleDataSet singleDataSet = new SingleDataSet(paths, dataTypes);
Field field = new Field(TSDataType.TEXT);
field.setBinaryV(new Binary(IoTDBConstant.VERSION));
RowRecord rowRecord = new RowRecord(0);
rowRecord.addField(field);
singleDataSet.setRecord(rowRecord);
return singleDataSet;
}
private QueryDataSet processShowDynamicParameterQuery() {
List<Path> paths = new ArrayList<>();
paths.add(new Path(PARAMETER));
......
......@@ -49,7 +49,7 @@ public class ShowPlan extends PhysicalPlan {
}
public enum ShowContentType {
DYNAMIC_PARAMETER, FLUSH_TASK_INFO, TTL
DYNAMIC_PARAMETER, FLUSH_TASK_INFO, TTL, VERSION
}
}
......@@ -120,6 +120,7 @@ import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SetStorageGroupContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SetTTLStatementContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.ShowAllTTLStatementContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.ShowTTLStatementContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.ShowVersionContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SlimitClauseContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SoffsetClauseContext;
import org.apache.iotdb.db.qp.strategy.SqlBaseParser.SuffixPathContext;
......@@ -191,14 +192,14 @@ public class LogicalGenerator extends SqlBaseBaseListener {
@Override
public void enterMoveFile(MoveFileContext ctx) {
super.enterMoveFile(ctx);
initializedOperator = new MoveFileOperator(new File(ctx.getChild(1).getText()),
new File(ctx.getChild(2).getText()));
initializedOperator = new MoveFileOperator(new File(ctx.FILE(0).getText()),
new File(ctx.FILE(1).getText()));
}
@Override
public void enterRemoveFile(RemoveFileContext ctx) {
super.enterRemoveFile(ctx);
initializedOperator = new RemoveFileOperator(new File(ctx.getChild(1).getText()));
initializedOperator = new RemoveFileOperator(new File(ctx.FILE().getText()));
}
@Override
......@@ -207,6 +208,12 @@ public class LogicalGenerator extends SqlBaseBaseListener {
initializedOperator = new LoadConfigurationOperator();
}
@Override
public void enterShowVersion(ShowVersionContext ctx) {
super.enterShowVersion(ctx);
initializedOperator = new ShowOperator(SQLConstant.TOK_VERSION);
}
@Override
public void enterShowDynamicParameter(SqlBaseParser.ShowDynamicParameterContext ctx) {
super.enterShowDynamicParameter(ctx);
......
......@@ -168,6 +168,8 @@ public class PhysicalGenerator {
return new ShowPlan(ShowContentType.DYNAMIC_PARAMETER);
case SQLConstant.TOK_FLUSH_TASK_INFO:
return new ShowPlan(ShowContentType.FLUSH_TASK_INFO);
case SQLConstant.TOK_VERSION:
return new ShowPlan(ShowContentType.VERSION);
default:
throw new LogicalOperatorException(String
.format("not supported operator type %s in show operation.", operator.getType()));
......
/*
* 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.
*/
package org.apache.iotdb.db.query.dataset;
import java.io.IOException;
import java.util.List;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.read.common.Path;
import org.apache.iotdb.tsfile.read.common.RowRecord;
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
public class SingleDataSet extends QueryDataSet {
private RowRecord record;
private int i = 0;
public SingleDataSet(List<Path> paths,
List<TSDataType> dataTypes) {
super(paths, dataTypes);
}
public void setRecord(RowRecord record) {
this.record = record;
}
@Override
protected boolean hasNextWithoutConstraint() throws IOException {
return i == 0;
}
@Override
protected RowRecord nextWithoutConstraint() throws IOException {
i++;
return record;
}
}
......@@ -24,7 +24,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.exception.path.PathException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.query.context.QueryContext;
import org.apache.iotdb.db.query.dataset.groupby.GroupByWithValueFilterDataSet;
......@@ -40,7 +39,6 @@ import org.apache.iotdb.tsfile.read.expression.impl.BinaryExpression;
import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression;
import org.apache.iotdb.tsfile.read.expression.util.ExpressionOptimizer;
import org.apache.iotdb.tsfile.read.filter.GroupByFilter;
import org.apache.iotdb.tsfile.read.filter.TimeFilter;
import org.apache.iotdb.tsfile.read.filter.factory.FilterType;
import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
import org.apache.iotdb.tsfile.utils.Pair;
......
......@@ -24,7 +24,6 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.iotdb.db.exception.StorageEngineException;
import org.apache.iotdb.db.exception.path.PathException;
import org.apache.iotdb.db.exception.query.QueryProcessException;
import org.apache.iotdb.db.metadata.MManager;
import org.apache.iotdb.db.query.context.QueryContext;
......
......@@ -378,10 +378,6 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
getNodeTimeseriesNum(getNodesList(req.getColumnPath(), req.getNodeLevel())));
status = getStatus(TSStatusCode.SUCCESS_STATUS);
break;
case "VERSION":
resp.setVersion(getVersion());
status = getStatus(TSStatusCode.SUCCESS_STATUS);
break;
default:
status = getStatus(TSStatusCode.METADATA_ERROR, req.getType());
break;
......@@ -422,10 +418,6 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
return MManager.getInstance().getChildNodePathInNextLevel(path);
}
private String getVersion() throws SQLException {
return IoTDBConstant.VERSION;
}
private List<List<String>> getTimeSeriesForPath(String path)
throws PathException {
return MManager.getInstance().getShowTimeseriesPath(path);
......@@ -669,6 +661,8 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
return executeShowFlushTaskInfo();
case DYNAMIC_PARAMETER:
return executeShowDynamicParameter();
case VERSION:
return executeShowVersion();
default:
logger.error("Unsupported show content type: {}", showPlan.getShowContentType());
throw new Exception("Unsupported show content type:" + showPlan.getShowContentType());
......@@ -720,6 +714,19 @@ public class TSServiceImpl implements TSIService.Iface, ServerContext {
return resp;
}
private TSExecuteStatementResp executeShowVersion() {
TSExecuteStatementResp resp =
getTSExecuteStatementResp(getStatus(TSStatusCode.SUCCESS_STATUS));
resp.setIgnoreTimeStamp(true);
List<String> columns = new ArrayList<>();
List<String> columnTypes = new ArrayList<>();
columns.add("version ");
columnTypes.add(TSDataType.TEXT.toString());
resp.setColumns(columns);
resp.setDataTypeList(columnTypes);
return resp;
}
private TSExecuteStatementResp getAuthQueryColumnHeaders(PhysicalPlan plan) {
TSExecuteStatementResp resp = getTSExecuteStatementResp(getStatus(TSStatusCode.SUCCESS_STATUS));
resp.setIgnoreTimeStamp(true);
......
......@@ -208,8 +208,8 @@ public class IoTDBMetadataFetchIT {
boolean hasResultSet = statement.execute(sql);
if(hasResultSet) {
try(ResultSet resultSet = statement.getResultSet()) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
Assert.assertEquals(resultSetMetaData.getColumnLabel(1), IoTDBConstant.VERSION);
resultSet.next();
Assert.assertEquals(resultSet.getString(2), IoTDBConstant.VERSION);
}
}
} catch (Exception e) {
......
......@@ -32,6 +32,7 @@ Last Updated on October 27th, 2019 by Lei Rui.
| Delete struct TSSetStorageGroupReq | Jialin Qiao |
| Remove struct TSDataValue | Lei Rui |
| Remove struct TSRowRecord | Lei Rui |
| Remove optional string version in TSFetchMetadataResp | Genius_pig |
......
......@@ -198,7 +198,6 @@ struct TSFetchMetadataResp{
9: optional list<string> nodesList
10: optional map<string, string> nodeTimeseriesNum
11: optional set<string> childPaths
12: optional string version
}
struct TSFetchMetadataReq{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册