|
13 | 13 | import java.util.Map; |
14 | 14 | import java.util.Optional; |
15 | 15 | import org.apache.calcite.rel.RelNode; |
| 16 | +import org.apache.calcite.sql.SqlCall; |
16 | 17 | import org.apache.calcite.sql.SqlIdentifier; |
17 | 18 | import org.apache.calcite.sql.SqlJoin; |
18 | 19 | import org.apache.calcite.sql.SqlNode; |
@@ -179,31 +180,38 @@ private static Optional<String> extractIndexName( |
179 | 180 | return Optional.ofNullable(extractTableNameFromSqlNode(sqlNode)); |
180 | 181 | } |
181 | 182 |
|
182 | | - /** Extracts the table name from a Calcite SqlNode parse tree. */ |
183 | | - private static String extractTableNameFromSqlNode(SqlNode sqlNode) { |
184 | | - if (sqlNode instanceof SqlSelect select) { |
185 | | - SqlNode from = select.getFrom(); |
186 | | - if (from instanceof SqlIdentifier id) { |
187 | | - return id.toString(); |
| 183 | + /** AST visitor that extracts the source index name from a Relation node (PPL path). */ |
| 184 | + private static class IndexNameExtractor extends AbstractNodeVisitor<String, Void> { |
| 185 | + @Override |
| 186 | + public String visitRelation(Relation node, Void context) { |
| 187 | + return node.getTableQualifiedName().toString(); |
| 188 | + } |
| 189 | + } |
| 190 | + |
| 191 | + /** SqlNode visitor that extracts the source table name from a SQL parse tree. */ |
| 192 | + private static class SqlTableNameExtractor |
| 193 | + extends org.apache.calcite.sql.util.SqlBasicVisitor<String> { |
| 194 | + @Override |
| 195 | + public String visit(SqlCall call) { |
| 196 | + if (call instanceof SqlSelect select) { |
| 197 | + return select.getFrom().accept(this); |
188 | 198 | } |
189 | | - if (from instanceof SqlJoin join) { |
190 | | - // For joins, extract from the left table |
191 | | - if (join.getLeft() instanceof SqlIdentifier leftId) { |
192 | | - return leftId.toString(); |
193 | | - } |
| 199 | + if (call instanceof SqlJoin join) { |
| 200 | + return join.getLeft().accept(this); |
194 | 201 | } |
| 202 | + return null; |
195 | 203 | } |
196 | | - return null; |
197 | | - } |
198 | 204 |
|
199 | | - /** AST visitor that extracts the source index name from a Relation node. */ |
200 | | - private static class IndexNameExtractor extends AbstractNodeVisitor<String, Void> { |
201 | 205 | @Override |
202 | | - public String visitRelation(Relation node, Void context) { |
203 | | - return node.getTableQualifiedName().toString(); |
| 206 | + public String visit(SqlIdentifier id) { |
| 207 | + return id.toString(); |
204 | 208 | } |
205 | 209 | } |
206 | 210 |
|
| 211 | + private static String extractTableNameFromSqlNode(SqlNode sqlNode) { |
| 212 | + return sqlNode.accept(new SqlTableNameExtractor()); |
| 213 | + } |
| 214 | + |
207 | 215 | private static RelNode addQuerySizeLimit(RelNode plan, CalcitePlanContext context) { |
208 | 216 | return LogicalSystemLimit.create( |
209 | 217 | LogicalSystemLimit.SystemLimitType.QUERY_SIZE_LIMIT, |
|
0 commit comments