From fe0c21bf933ef232689ebcb2a834349e688d88fc Mon Sep 17 00:00:00 2001 From: gengjun-git <54172532+gengjun-git@users.noreply.github.com> Date: Thu, 27 Aug 2020 12:17:24 +0800 Subject: [PATCH] [Bug] Fix mysql return bug (#4450) Send fields after first row arrived so that error packet can be send to client when exception thrown from coord.getNext(). Golang and Python can not identify error if fields packet arrived before error packet. --- .../java/org/apache/doris/qe/StmtExecutor.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index 14a811a341..be7405c2d5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -608,9 +608,6 @@ public class StmtExecutor { coord.exec(); - // if python's MysqlDb get error after sendfields, it can't catch the exception - // so We need to send fields after first batch arrived - // send result // 1. If this is a query with OUTFILE clause, eg: select * from tbl1 into outfile xxx, // We will not send real query result to client. Instead, we only send OK to client with @@ -622,13 +619,17 @@ public class StmtExecutor { RowBatch batch; MysqlChannel channel = context.getMysqlChannel(); boolean isOutfileQuery = queryStmt.hasOutFileClause(); - if (!isOutfileQuery) { - sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs()); - } + boolean isSendFields = false; while (true) { batch = coord.getNext(); // for outfile query, there will be only one empty batch send back with eos flag if (batch.getBatch() != null && !isOutfileQuery) { + // For some language driver, getting error packet after fields packet will be recognized as a success result + // so We need to send fields after first batch arrived + if (!isSendFields) { + sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs()); + isSendFields = true; + } for (ByteBuffer row : batch.getBatch().getRows()) { channel.sendOnePacket(row); } @@ -638,6 +639,9 @@ public class StmtExecutor { break; } } + if (!isSendFields && !isOutfileQuery) { + sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs()); + } statisticsForAuditLog = batch.getQueryStatistics(); if (!isOutfileQuery) {