} else {
parser.generatePlan(context);
}
} catch (RuntimeException e) {
if (e instanceof ParserException || e instanceof SQLParseException) {
throw new DoNotRetryIOException(e.getMessage(), e);
} else {
throw new ServiceException(new IOException(e));
}
} catch (UnsupportedException e) {
throw e;
}
final long afterGenPlan = EnvironmentEdgeManager.currentTimeMillis();
((FServer) this.service).getMetrics().updateGenPlan(
afterGenPlan - beforeGenPlan);
Plan executePlan = context.getPlan();
if (executePlan instanceof DQLPlan) {
selectSQLCount.increment();
DQLPlan dqlPlan = (DQLPlan) executePlan;
dqlPlan.setFetchRows(fetchSize);
Pair<Boolean, Pair<String, Pair<List<QueryResultProto>, List<StringDataTypePair>>>> queryResults =
executeEngine.execQueryPlan(dqlPlan, sessionId, closeSession);
addReadMetricsCount(0, null, 1, EnvironmentEdgeManager.currentTimeMillis() - beforeGenPlan);
return ResponseConverter.buildExecuteResponse(queryResults.getFirst(),
queryResults.getSecond().getFirst(), queryResults.getSecond()
.getSecond());
} else if (executePlan instanceof DMLPlan) {
if (executePlan instanceof InsertPlan) {
insertSQLCount.increment();
List<WriteResultProto> writeResults = executeEngine
.execInsertPlan((InsertPlan) executePlan);
addWriteMetricsCount(0, null, 1, EnvironmentEdgeManager.currentTimeMillis()
- beforeGenPlan);
return ResponseConverter.buildExecuteResponse(writeResults);
} else if (executePlan instanceof UpdatePlan) {
updateSQLCount.increment();
List<WriteResultProto> writeResults = executeEngine
.execUpdatePlan((UpdatePlan) executePlan);
addWriteMetricsCount(0, null, 1, EnvironmentEdgeManager.currentTimeMillis()
- beforeGenPlan);
return ResponseConverter.buildExecuteResponse(writeResults);
} else if (executePlan instanceof DeletePlan) {
deleteSQLCount.increment();
List<WriteResultProto> writeResults = executeEngine
.execDeletePlan((DeletePlan) executePlan);
addWriteMetricsCount(0, null, 1, EnvironmentEdgeManager.currentTimeMillis()
- beforeGenPlan);
return ResponseConverter.buildExecuteResponse(writeResults);
} else {
throw new ServiceException(
"The instance of Plan is not supported. SQL:" + sql);
}
} else if (executePlan instanceof DDLPlan) {
MasterAdminKeepAliveConnection masterAdminKeepAliveConnection = this.connection
.getKeepAliveMasterAdmin();
if(executePlan instanceof NotingTodoPlan) {
return ResponseConverter.buildNotExecuteResponse();
} else if (executePlan instanceof AlterTablePlan) {
FTable hTableDesc = ((AlterTablePlan) executePlan).getNewTable();
return modifyTable(masterAdminKeepAliveConnection, hTableDesc);
} else if (executePlan instanceof CreateTablePlan) {
CreateTablePlan createTable = (CreateTablePlan) executePlan;
MasterAdminProtos.CreateTableResponse response = masterAdminKeepAliveConnection
.createTable(
null,
RequestConverter.buildCreateTableRequest(
createTable.getTable(), createTable.getSplitKeys()));
return ResponseConverter.buildExecuteResponse(response);
} else if (executePlan instanceof CreateIndexPlan) {
CreateIndexPlan createIndexPlan = (CreateIndexPlan) executePlan;
Index index = createIndexPlan.getIndex();
MasterAdminProtos.CreateIndexRequest request = RequestConverter
.buildCreateIndexRequest(index);
return ResponseConverter
.buildExecuteResponse(masterAdminKeepAliveConnection.createIndex(
null, request));
} else if (executePlan instanceof DropIndexPlan) {
DropIndexPlan dropIndexPlan = (DropIndexPlan) executePlan;
MasterAdminProtos.DropIndexRequest request = RequestConverter.buildDropIndexRequest(
dropIndexPlan.getTableName(), dropIndexPlan.getIndexName());
return ResponseConverter
.buildExecuteResponse(masterAdminKeepAliveConnection.deleteIndex(
null, request));
} else if (executePlan instanceof DropTablePlan) {
List<DeleteTableResponse> responses = new ArrayList<DeleteTableResponse>();
for (String tableName : ((DropTablePlan) executePlan).getTableNames()) {
byte[] byteName = Bytes.toBytes(tableName);
if (this.connection.isTableDisabled(byteName)) {
MasterAdminProtos.DeleteTableRequest request = RequestConverter
.buildDeleteTableRequest(byteName);
responses.add(masterAdminKeepAliveConnection.deleteTable(null,
request));
} else {
throw new TableNotDisabledException(tableName);
}
}
return ResponseConverter.buildListExecuteResponse(responses);
} else if (executePlan instanceof TruncateTablePlan) {
List<TruncateTableResponse> responses = new ArrayList<TruncateTableResponse>();
for (String tableName : ((TruncateTablePlan) executePlan)
.getTableNames()) {
byte[] byteName = Bytes.toBytes(tableName);
if (this.connection.isTableDisabled(byteName)) {
MasterAdminProtos.TruncateTableRequest request = RequestConverter
.buildTruncateTableRequest(byteName);
responses.add(masterAdminKeepAliveConnection.truncateTable(null,
request));
} else {
throw new TableNotDisabledException(tableName);
}
}
}
}
throw new ServiceException(new DoNotRetryIOException(
"The instance of Plan is not supported. SQL:" + sql));
} catch (ServiceException e) {
LOG.error("ServiceException ", e);
throw e;
} catch (Throwable e) {