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 14a811a3417ed0..be7405c2d5dad2 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 @@ private void handleQueryStmt() throws Exception { 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 @@ private void handleQueryStmt() throws Exception { 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 @@ private void handleQueryStmt() throws Exception { break; } } + if (!isSendFields && !isOutfileQuery) { + sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs()); + } statisticsForAuditLog = batch.getQueryStatistics(); if (!isOutfileQuery) {