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 167b6545b0210ae0769d16e21583095e77f13186..a47f9fd47e2d9b6be66dbf779135c9f019523519 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 e1b380ae982a98b45bbafdca9fff82408b1dbdc1..1e03f8eceda6a63f07ccaca43de2291b235fb567 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 6f3dd3575ab820b65994e61783c752e180533198..08322d2c7f245bba75011433c608be0c4837940d 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 dfa647b59e17848bd60fa03cfc92b13f8096c12d..e4b975646959426a36469eb80b53afb4e7ecc961 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 fe8feb5b7f6447125662e10c80b5be36cdd9ff3c..578b92b7d2528a5edaaf8dfc77bd76a24e39e7f1 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