From c273f915fdea5607cf9efc08dcbf05d66d9fac6c Mon Sep 17 00:00:00 2001 From: xujp Date: Thu, 10 Nov 2022 14:54:34 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E5=87=BD=E6=95=B0=E4=B8=AD?= =?UTF-8?q?=E5=8C=85=E5=90=AB=E5=88=9B=E5=BB=BA=E8=A1=A8=E6=97=B6=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=94=9F=E6=88=90=E8=A6=86=E7=9B=96=E7=8E=87=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E7=9A=84=E9=97=AE=E9=A2=98=202.=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=A6=86=E7=9B=96=E7=8E=87=E6=8A=A5=E5=91=8A=E4=B8=AD=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E6=8C=89=E7=85=A7=E4=BB=8E=E5=B0=8F=E5=88=B0=E5=A4=A7?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改检视意见 选择系统模式时执行debug无权限创建历史表问题 修复不同schema下相同名称函数无法执行的问题.原因是直接call命令时缺少schema条件 1.导出报告时文件导出到历史名称的文件夹下面 2.修改执行语句begin或end与函数主体在同一行时执行/标记异常问题; code check --- .../mppdbide/common/DbeCommonUtils.java | 35 ++++++++++++- .../service/DebuggerReportService.java | 49 +++++++++++++++++-- .../view/coverage/CoverageService.java | 3 ++ .../handler/debug/chain/ServerExitChain.java | 4 +- .../bl/test/debug/DbeDebugerTest.java | 2 +- 5 files changed, 85 insertions(+), 8 deletions(-) diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java index 167b6545..a47f9fd4 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/common/DbeCommonUtils.java @@ -54,6 +54,13 @@ public final class DbeCommonUtils { */ public static final String END = "END"; + /** + * CREATE_TABLE + */ + public static final String CREATE_TABLE = "CREATE TABLE"; + + private static final String CREATE_TABLE_NOT = "CREATE TABLE IF NOT EXISTS"; + private static final String REPLACE_FUNCTION = "$function$"; private static final String REPLACED = "$$"; @@ -237,4 +244,30 @@ public final class DbeCommonUtils { } return index; } -} \ No newline at end of file + + /** + * getNeedDropTableName + * + * @param code code + * @return List list + */ + public static List getNeedDropTableName(String code) { + List list = new ArrayList<>(); + String newCode = code.toUpperCase(Locale.ENGLISH).replaceAll(CREATE_TABLE, CREATE_TABLE_NOT); + int index = 0; + String needCode = null; + while (true) { + index = newCode.indexOf(CREATE_TABLE_NOT); + if (index == -1) { + return list; + } + index = index + CREATE_TABLE_NOT.length(); + newCode = newCode.substring(index); + index = newCode.indexOf("("); + if (index != -1) { + needCode = newCode.substring(0, index); + list.add(needCode.trim()); + } + } + } +} diff --git a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java index e1b380ae..1e03f8ec 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.debuger/src/org/opengauss/mppdbide/debuger/service/DebuggerReportService.java @@ -22,11 +22,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import java.util.Locale; +import java.util.Set; import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.apache.commons.lang.StringUtils; import org.opengauss.mppdbide.common.DbeCommonUtils; import org.opengauss.mppdbide.common.IConnection; import org.opengauss.mppdbide.common.IConnectionProvider; @@ -59,6 +62,7 @@ public class DebuggerReportService { private static final String TABLE_FIELD_TWO = "endTime BIGINT, sourceCode VARCHAR, params VARCHAR," + " canBreakLine VARCHAR);"; private static final String INSERT = "insert into public.his_coverage VALUES(?,?,?,?,?,?,?,?);"; + private static final String DROP_SQL = "DROP TABLE IF EXISTS %s"; /** * default value @@ -68,11 +72,13 @@ public class DebuggerReportService { private IConnection serverConn; private IConnection clientConn; private IConnection queryConn; + private IConnection dropConn; private FunctionVo functionVo; private TurnOnVo turnOnVo; private DebuggerStartInfoVo startInfo; private CodeDescription baseCodeDesc = null; private CodeDescription totalCodeDesc = null; + private boolean hasExp = false; private DebuggerReportService() { @@ -131,6 +137,7 @@ public class DebuggerReportService { this.serverConn = connectProvider.getValidFreeConnection(); this.clientConn = connectProvider.getValidFreeConnection(); this.queryConn = connectProvider.getValidFreeConnection(); + this.dropConn = connectProvider.getValidFreeConnection(); this.functionVo = functionVo; } catch (SQLException e) { MPPDBIDELoggerUtility.error(e.getMessage()); @@ -187,6 +194,14 @@ public class DebuggerReportService { } catch (SQLException sqlErr) { MPPDBIDELoggerUtility.warn("reportService queryConn close failed, err=" + sqlErr.toString()); } + try { + if (dropConn != null) { + dropConn.close(); + dropConn = null; + } + } catch (SQLException sqlErr) { + MPPDBIDELoggerUtility.warn("reportService dropConn close failed, err=" + sqlErr.toString()); + } } /** @@ -201,8 +216,11 @@ public class DebuggerReportService { /** * make dbedebugger report info + * + * @param hasExp exception */ - public void makeReport() { + public void makeReport(boolean hasExp) { + this.hasExp = hasExp; startInfo = DebuggerStartVariable.getStartInfo(functionVo.oid); if (!startInfo.isMakeReport) { return; @@ -210,6 +228,7 @@ public class DebuggerReportService { List inputsParams = Arrays.asList(functionVo.oid); ResultSet rs = null; try { + dropTable(startInfo.sourceCode); // DBE_DEBUG_OFF DebugOpt opt = DebugConstants.DebugOpt.DBE_DEBUG_OFF; rs = serverConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery(); @@ -244,6 +263,21 @@ public class DebuggerReportService { } } + private void dropTable(String code) { + if (StringUtils.isBlank(code)) { + return; + } + List tableNames = DbeCommonUtils.getNeedDropTableName(code); + tableNames.forEach(item -> { + String dropSql = String.format(Locale.ENGLISH, DROP_SQL, item) ; + try { + dropConn.getStatement(dropSql).executeQuery(); + } catch (SQLException e) { + MPPDBIDELoggerUtility.error("dropTable failed: " + e.getMessage()); + } + }); + } + private void doClient() { VariableRunLine.runList.clear(); // attach @@ -262,13 +296,20 @@ public class DebuggerReportService { inputsParams = new ArrayList(); opt = DebugConstants.DebugOpt.DBE_STEP_OVER; Boolean hasNext = true; + Boolean isAdd= true; while (hasNext) { try (ResultSet rs = clientConn.getDebugOptPrepareStatement(opt, inputsParams).executeQuery()) { if (rs.next()) { AttachVo attachVo = ParseVo.parse(rs, AttachVo.class); Integer lineNo = attachVo.lineno; if (lineNo > 1) { - runLinks.add(getCurLine(lineNo)); + if (isAdd && this.hasExp && attachVo.query.toUpperCase(Locale.ENGLISH).contains(DbeCommonUtils.CREATE_TABLE)) { + runLinks.add(getCurLine(lineNo)); + isAdd = false; + } + if (isAdd) { + runLinks.add(getCurLine(lineNo)); + } } } else { hasNext = false; @@ -292,7 +333,9 @@ public class DebuggerReportService { historyList.add(endInfo); DebuggerStartVariable.setHistoryList(functionVo.oid, historyList); endInfo.canBreakLine = String.join(",", toRunLines); - createTbale(endInfo); + if (!this.hasExp) { + createTbale(endInfo); + } } private void createTbale(DebuggerEndInfoVo endInfo) { diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java index 6f3dd357..08322d2c 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/coverage/CoverageService.java @@ -20,6 +20,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -105,6 +106,8 @@ public class CoverageService implements IService { cov.remarkCoverageLinesArr = cov.coverageLinesArr.stream().map(item -> Integer.parseInt(item) + 1 + "") .filter(ite -> cov.remarkLinesArr.contains(ite)).collect(Collectors.toList()); + Collections.sort(cov.remarkCoverageLinesArr, + (o1, o2) -> Integer.valueOf(o1).compareTo(Integer.valueOf(o2))); cov.remarkCoverageLineNum = cov.remarkCoverageLinesArr.size(); Double remarkPer = Double.parseDouble(String.format("%.2f", ((double) cov.remarkCoverageLineNum * 100 / (double) cov.remarkLineNum))); diff --git a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java index dfa647b5..e4b97564 100644 --- a/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java +++ b/code/datastudio/src/org.opengauss.mppdbide.view/src/org/opengauss/mppdbide/view/handler/debug/chain/ServerExitChain.java @@ -60,9 +60,7 @@ public class ServerExitChain extends IMsgChain { Display.getDefault().asyncExec(new UpdateHighlightLineNumTask()); if (VariableRunLine.isPldebugger != null && !VariableRunLine.isPldebugger) { - if (!event.hasException()) { - reportService.makeReport(); - } + reportService.makeReport(event.hasException()); if (VariableRunLine.isContinue != null && VariableRunLine.isContinue) { Display.getDefault().asyncExec(() -> UpdateDebugPositionTask.continueDebug()); } diff --git a/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java b/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java index fe8feb5b..578b92b7 100644 --- a/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java +++ b/code/datastudio/testcode/LLT/org.opengauss.mppdbide.bl.debug.test.fragment/src/org/opengauss/mppdbide/bl/test/debug/DbeDebugerTest.java @@ -158,7 +158,7 @@ public class DbeDebugerTest extends DebugerJdbcTestCaseBase { total.append(toParam4); CodeDescription totalCode = new CodeDescription(total.toString()); debuggerReportService.setTotalCode(totalCode); - debuggerReportService.makeReport(); + debuggerReportService.makeReport(false); } @Test -- Gitee