|
29 | 29 | import org.apache.doris.catalog.Type; |
30 | 30 | import org.apache.doris.datasource.CatalogIf; |
31 | 31 | import org.apache.doris.datasource.es.EsExternalCatalog; |
| 32 | +import org.apache.doris.datasource.lance.LanceExternalCatalog; |
32 | 33 | import org.apache.doris.mysql.MysqlCommand; |
33 | 34 | import org.apache.doris.mysql.privilege.PrivPredicate; |
34 | 35 | import org.apache.doris.nereids.CascadesContext; |
|
40 | 41 | import org.apache.doris.nereids.trees.expressions.Slot; |
41 | 42 | import org.apache.doris.nereids.trees.plans.Plan; |
42 | 43 | import org.apache.doris.nereids.trees.plans.PrepareCommandPlanner; |
| 44 | +import org.apache.doris.nereids.trees.plans.commands.AlterTableCommand; |
43 | 45 | import org.apache.doris.nereids.trees.plans.commands.Command; |
| 46 | +import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand; |
44 | 47 | import org.apache.doris.nereids.trees.plans.commands.DescribeCommand; |
| 48 | +import org.apache.doris.nereids.trees.plans.commands.ExplainCommand; |
| 49 | +import org.apache.doris.nereids.trees.plans.commands.KillCommand; |
| 50 | +import org.apache.doris.nereids.trees.plans.commands.ReplayCommand; |
45 | 51 | import org.apache.doris.nereids.trees.plans.commands.ShowCreateTableCommand; |
46 | 52 | import org.apache.doris.nereids.trees.plans.commands.ShowDataCommand; |
47 | 53 | import org.apache.doris.nereids.trees.plans.commands.ShowPartitionsCommand; |
48 | 54 | import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand; |
49 | 55 | import org.apache.doris.nereids.trees.plans.commands.ShowPythonPackagesCommand; |
50 | 56 | import org.apache.doris.nereids.trees.plans.commands.ShowQueryStatsCommand; |
51 | 57 | import org.apache.doris.nereids.trees.plans.commands.ShowTableCommand; |
| 58 | +import org.apache.doris.nereids.trees.plans.commands.TransactionCommand; |
| 59 | +import org.apache.doris.nereids.trees.plans.commands.UpdateCommand; |
| 60 | +import org.apache.doris.nereids.trees.plans.commands.info.CreateIndexOp; |
| 61 | +import org.apache.doris.nereids.trees.plans.commands.info.DropIndexOp; |
| 62 | +import org.apache.doris.nereids.trees.plans.commands.insert.BatchInsertIntoTableCommand; |
| 63 | +import org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTVFCommand; |
| 64 | +import org.apache.doris.nereids.trees.plans.commands.insert.InsertIntoTableCommand; |
| 65 | +import org.apache.doris.nereids.trees.plans.commands.insert.InsertOverwriteTableCommand; |
| 66 | +import org.apache.doris.nereids.trees.plans.commands.merge.MergeIntoCommand; |
52 | 67 | import org.apache.doris.nereids.trees.plans.commands.use.SwitchCommand; |
53 | 68 | import org.apache.doris.nereids.trees.plans.commands.use.UseCommand; |
54 | 69 | import org.apache.doris.qe.ConnectContext; |
55 | 70 | import org.apache.doris.qe.QueryState; |
56 | 71 | import org.apache.doris.qe.ResultSetMetaData; |
57 | 72 | import org.apache.doris.qe.SessionVariable; |
| 73 | +import org.apache.doris.qe.ShowResultSetMetaData; |
58 | 74 | import org.apache.doris.qe.StmtExecutor; |
59 | 75 | import org.apache.doris.qe.VariableMgr; |
60 | 76 |
|
@@ -97,7 +113,20 @@ static Schema analyze(ConnectContext context, String query) throws Exception { |
97 | 113 | context.setStatementContext(null); |
98 | 114 | // Match execution's HTTP/plugin conversion before the dialect parser sees the SQL. |
99 | 115 | String converted = SqlDialectHelper.convertSqlByDialect(query, context.getSessionVariable()); |
100 | | - statements = new NereidsParser().parseSQL(converted, context.getSessionVariable()); |
| 116 | + try { |
| 117 | + statements = new NereidsParser().parseSQL(converted, context.getSessionVariable()); |
| 118 | + } catch (Exception convertedError) { |
| 119 | + if (!context.getSessionVariable().isRetryOriginSqlOnConvertFail() || converted.equals(query)) { |
| 120 | + throw convertedError; |
| 121 | + } |
| 122 | + // Match execution's parse fallback while discarding any failed parser context. |
| 123 | + StatementContext failed = context.getStatementContext(); |
| 124 | + if (failed != null) { |
| 125 | + failed.close(); |
| 126 | + context.setStatementContext(null); |
| 127 | + } |
| 128 | + statements = new NereidsParser().parseSQL(query, context.getSessionVariable()); |
| 129 | + } |
101 | 130 | Map<String, String> scopedDatabases = new HashMap<>(); |
102 | 131 | if (statements.isEmpty()) { |
103 | 132 | throw CallStatus.UNIMPLEMENTED.withDescription( |
@@ -219,7 +248,41 @@ private static ResultSetMetaData commandMetadata(ConnectContext context, Command |
219 | 248 | } else if (command instanceof ShowProcCommand) { |
220 | 249 | return ((ShowProcCommand) command).getMetaData(context); |
221 | 250 | } |
222 | | - return command.getResultSetMetaData(); |
| 251 | + if (command instanceof ExplainCommand) { |
| 252 | + // PLAN PROCESS has no Flight serialization path in StmtExecutor. |
| 253 | + if (((ExplainCommand) command).showPlanProcess()) { |
| 254 | + throw CallStatus.UNIMPLEMENTED.withDescription("EXPLAIN PLAN PROCESS is not supported over Flight SQL") |
| 255 | + .toRuntimeException(); |
| 256 | + } |
| 257 | + return stringMetadata("Explain String(Nereids Planner)"); |
| 258 | + } else if (command instanceof ReplayCommand) { |
| 259 | + return stringMetadata("Plan Replayer dump url"); |
| 260 | + } else if (command instanceof AlterTableCommand) { |
| 261 | + AlterTableCommand alter = (AlterTableCommand) command; |
| 262 | + String catalog = alter.getTbl().getCtl(); |
| 263 | + // Lance index admission returns a JobId header even for an IF no-op. Do not run |
| 264 | + // validation/admission here: those paths can resolve remote tables or allocate IDs. |
| 265 | + if (context.getCatalog(catalog == null ? context.getDefaultCatalog() : catalog) |
| 266 | + instanceof LanceExternalCatalog && alter.getNereidsOps().stream().anyMatch(op -> |
| 267 | + (op instanceof CreateIndexOp && !((CreateIndexOp) op).isAlter()) |
| 268 | + || (op instanceof DropIndexOp && !((DropIndexOp) op).isAlter()))) { |
| 269 | + return stringMetadata("JobId"); |
| 270 | + } |
| 271 | + } |
| 272 | + ResultSetMetaData metadata = command.getResultSetMetaData(); |
| 273 | + // Concrete DML commands return OK, but subclasses such as WARM UP SELECT supply rows. |
| 274 | + if (metadata != null && metadata.getColumnCount() == 0 && (command instanceof InsertIntoTableCommand |
| 275 | + || command instanceof InsertOverwriteTableCommand || command instanceof BatchInsertIntoTableCommand |
| 276 | + || command instanceof InsertIntoTVFCommand || command instanceof UpdateCommand |
| 277 | + || command instanceof DeleteFromCommand || command instanceof MergeIntoCommand |
| 278 | + || command instanceof KillCommand || command instanceof TransactionCommand)) { |
| 279 | + return stringMetadata("StatusResult"); |
| 280 | + } |
| 281 | + return metadata; |
| 282 | + } |
| 283 | + |
| 284 | + private static ResultSetMetaData stringMetadata(String name) { |
| 285 | + return ShowResultSetMetaData.builder().addColumn(new Column(name, Type.STRING)).build(); |
223 | 286 | } |
224 | 287 |
|
225 | 288 | private static void resolveNamespace(ConnectContext context, Plan plan, Map<String, String> scopedDatabases) |
|
0 commit comments