wgy8283335 opened a new issue #2670: One suggestion about the implementation in the "SQLSegmentsExtractorEngine.extract()" method. URL: https://github.com/apache/incubator-shardingsphere/issues/2670 ## One suggestion about the implementation in the "SQLSegmentsExtractorEngine.extract()" method. The method "extract()" in the class SQLSegmentsExtractorEngine has two parameters. Below is the defination of the method: ``` public Collection<SQLSegment> extract(final SQLAST ast, final Map<ParserRuleContext, Integer> parameterMarkerIndexes) { Collection<SQLSegment> result = new LinkedList<>(); for (SQLSegmentExtractor each : ast.getSqlStatementRule().getExtractors()) { if (each instanceof OptionalSQLSegmentExtractor) { Optional<? extends SQLSegment> sqlSegment = ((OptionalSQLSegmentExtractor) each).extract(ast.getParserRuleContext(), parameterMarkerIndexes); if (sqlSegment.isPresent()) { result.add(sqlSegment.get()); } } else if (each instanceof CollectionSQLSegmentExtractor) { result.addAll(((CollectionSQLSegmentExtractor) each).extract(ast.getParserRuleContext(), parameterMarkerIndexes)); } } return result; } ``` As parameterMarkerIndexes is a member of ast object. Refer to "Clean Code" book , the method could be modified as below: ``` public Collection<SQLSegment> extract(final SQLAST ast) { Collection<SQLSegment> result = new LinkedList<>(); for (SQLSegmentExtractor each : ast.getSqlStatementRule().getExtractors()) { if (each instanceof OptionalSQLSegmentExtractor) { Optional<? extends SQLSegment> sqlSegment = ((OptionalSQLSegmentExtractor) each).extract(ast.getParserRuleContext(), ast.getParameterMarkerIndexes()); if (sqlSegment.isPresent()) { result.add(sqlSegment.get()); } } else if (each instanceof CollectionSQLSegmentExtractor) { result.addAll(((CollectionSQLSegmentExtractor) each).extract(ast.getParserRuleContext(), ast.getParameterMarkerIndexes())); } } return result; } ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
