[Fix](HttpServer) Chinese garbled characters appear when obtaining query plan (#18820)

When obtaining the query plan, the Chinese garbled characters in the predicate lead to incorrect data results.
This commit is contained in:
ZenoYang
2023-04-24 08:49:44 +08:00
committed by GitHub
parent 2d7903e2bd
commit d2f50ce3f5
3 changed files with 9 additions and 41 deletions

View File

@ -28,7 +28,7 @@ import org.apache.doris.catalog.Table;
import org.apache.doris.common.DorisHttpException;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.httpv2.entity.ResponseEntityBuilder;
import org.apache.doris.httpv2.util.HttpUtil;
import org.apache.doris.httpv2.rest.manager.HttpUtils;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.planner.PlanFragment;
import org.apache.doris.planner.Planner;
@ -92,8 +92,8 @@ public class TableQueryPlanAction extends RestBaseController {
// just allocate 2 slot for top holder map
Map<String, Object> resultMap = new HashMap<>(4);
String postContent = HttpUtil.getBody(request);
try {
String postContent = HttpUtils.getBody(request);
// may be these common validate logic should be moved to one base class
if (Strings.isNullOrEmpty(postContent)) {
return ResponseEntityBuilder.badRequest("POST body must contains [sql] root object");

View File

@ -25,6 +25,7 @@ import org.apache.doris.persist.gson.GsonUtils;
import org.apache.doris.system.Frontend;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
@ -36,10 +37,12 @@ import org.apache.http.util.EntityUtils;
import org.apache.parquet.Strings;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
/*
* used to forward http requests from manager to be.
@ -116,4 +119,8 @@ public class HttpUtils {
}
return GsonUtils.GSON.toJson(responseEntity.getData());
}
public static String getBody(HttpServletRequest request) throws IOException {
return IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
}
}

View File

@ -1,39 +0,0 @@
// 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.doris.httpv2.util;
import java.io.BufferedReader;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
public class HttpUtil {
public static String getBody(HttpServletRequest request) {
StringBuilder data = new StringBuilder();
String line = null;
BufferedReader reader = null;
try {
reader = request.getReader();
while (null != (line = reader.readLine())) {
data.append(new String(line.getBytes("utf-8")));
}
} catch (IOException e) {
// CHECKSTYLE IGNORE THIS LINE
}
return data.toString();
}
}