11# Code Review Guidelines for OpenSearch SQL
22
3- This document provides guidelines for code reviews in the OpenSearch SQL project. These guidelines are used by CodeRabbit AI for automated code reviews and serve as a reference for human reviewers .
3+ This document provides general code review principles and standards for the OpenSearch SQL project. These guidelines apply across all file types and are used by CodeRabbit AI for automated code reviews.
44
55## Core Review Principles
66
@@ -9,19 +9,40 @@ This document provides guidelines for code reviews in the OpenSearch SQL project
99- ** Self-Documenting Code** : Code should be clear through naming and structure, not comments
1010- ** No Redundant Comments** : Avoid comments that merely restate what the code does
1111- ** Concise Implementation** : Keep code, docs, and notes short and focused on essentials
12+ - ** Code Reuse** : Identify opportunities across similar implementations
13+ - ** Maintainability** : Assess if code is easy to understand and modify
1214
1315### Java Standards
1416- ** Naming Conventions** :
1517 - Classes: ` PascalCase ` (e.g., ` QueryExecutor ` )
1618 - Methods/Variables: ` camelCase ` (e.g., ` executeQuery ` )
1719 - Constants: ` UPPER_SNAKE_CASE ` (e.g., ` MAX_RETRY_COUNT ` )
18- - ** Method Size** : Keep methods under 20 lines with single responsibility
20+ - ** Method Size** :
21+ - Target: Under 20 lines with single responsibility
22+ - Suggest refactoring: Methods >100 lines
23+ - ** Class Size** : Flag classes >500 lines for organization review
1924- ** JavaDoc Required** : All public classes and methods must have proper JavaDoc
25+ - NOT required on test methods, test helpers, override methods, or private methods
2026- ** Error Handling** : Use specific exception types with meaningful messages
2127- ** Null Safety** : Prefer ` Optional<T> ` for nullable returns
28+ - ** Resource Management** : Use try-with-resources for proper cleanup
29+ - ** Dead Code** : Check for unused imports, variables, and methods
2230
2331### Testing Requirements
24- - ** Test Coverage** : All new business logic requires unit tests
32+ - ** Test Coverage** : All new business logic requires unit tests in the same commit
33+ - ** Required Test Cases** :
34+ - NULL input tests for all new functions
35+ - Boundary condition tests (min/max values, empty inputs)
36+ - Error condition tests (invalid inputs, exceptions)
37+ - Multi-document tests for per-document operations
38+ - ** Test Naming** : Follow pattern ` test<Functionality><Condition> `
39+ - ** Test Independence** : Tests must not rely on execution order
40+ - ** Test Data** :
41+ - Use realistic data that reflects real-world scenarios
42+ - Inline test data is acceptable when it improves readability
43+ - Don't require loading from files if inline is clearer
44+ - ** Test Assertions** : Flag smoke tests without meaningful assertions only if they provide no value
45+ - ** Resource Cleanup** : Ensure proper cleanup of test resources
2546- ** Integration Tests** : End-to-end scenarios need integration tests in ` integ-test/ ` module
2647- ** Test Execution** : Verify changes with ` ./gradlew :integ-test:integTest `
2748- ** No Failing Tests** : All tests must pass before merge; fix or ask for guidance if blocked
@@ -37,7 +58,6 @@ This document provides guidelines for code reviews in the OpenSearch SQL project
3758- ** String Handling** : Use ` StringBuilder ` for concatenation in loops
3859- ** Input Validation** : Validate all user inputs, especially queries
3960- ** Logging Safety** : Sanitize data before logging to prevent injection
40- - ** Resource Management** : Use try-with-resources for proper cleanup
4161
4262## Review Focus Areas
4363
@@ -51,7 +71,7 @@ This document provides guidelines for code reviews in the OpenSearch SQL project
5171
5272### What to Flag
5373- Redundant or obvious comments
54- - Methods longer than 20 lines
74+ - Methods longer than target size (see Java Standards)
5575- Missing JavaDoc on public APIs
5676- Generic exception handling
5777- Unused imports or dead code
@@ -66,23 +86,47 @@ This document provides guidelines for code reviews in the OpenSearch SQL project
6686- Efficient algorithms and data structures
6787- Security-conscious coding practices
6888
69- ## Project-Specific Guidelines
89+ ## Project Context
7090
71- ### OpenSearch SQL Context
91+ ### OpenSearch SQL
7292- ** JDK 21** : Required for development
7393- ** Java 11 Compatibility** : Maintain when possible for OpenSearch 2.x
74- - ** Module Structure** : Respect existing module boundaries
75- - ** Integration Tests** : Use ` ./gradlew :integ-test:integTest ` for testing
94+ - ** Module Structure** : Respect existing module boundaries (core, ppl, sql, opensearch, integ-test)
7695- ** Test Naming** : ` *IT.java ` for integration tests, ` *Test.java ` for unit tests
7796
78- ### PPL Parser Changes
97+ ### Grammar and Parser Development
7998- Test new grammar rules with positive and negative cases
8099- Verify AST generation for new syntax
81100- Include edge cases and boundary conditions
82101- Update corresponding AST builder classes
102+ - Check for code reuse opportunities vs creating new rules
83103
84104### Calcite Integration
85- - If the PR is for PPL command, refer docs/dev/ppl-commands.md and verify the PR satisfy the checklist.
86- - Follow existing patterns in ` CalciteRelNodeVisitor ` and ` CalciteRexNodeVisitor `
105+ - Follow existing patterns in visitor implementations
87106- Test SQL generation and optimization paths
88107- Document Calcite-specific workarounds
108+ - Ensure version compatibility
109+
110+ ## Review Tone and Focus
111+
112+ ### Review Priorities
113+ - ** Correctness** > Performance > Maintainability > Style
114+ - Focus on functional issues, not cosmetic ones
115+ - Explain WHY when suggesting improvements, not just WHAT
116+ - Avoid repeating the same suggestion multiple times
117+
118+ ### What NOT to Flag
119+ - Minor refactorings unless code is clearly problematic (>100 lines, deeply nested, etc.)
120+ - Missing JavaDoc on test methods, test helpers, override methods, or private methods
121+ - Inline test data when it improves readability
122+ - NDJSON format as invalid JSON
123+ - Missing language identifiers in markdown code blocks (unless in documentation files)
124+ - Hard-coded test data when it's intentionally inline for clarity
125+ - Helper methods in tests unless they're truly unused
126+ - Extracting helper methods unless the method exceeds 100 lines
127+
128+ ### Keep Reviews Concise
129+ - Be direct and actionable
130+ - Focus on significant issues that impact functionality or maintainability
131+ - Avoid nitpicking on style preferences
132+ - Prioritize issues that could cause bugs or maintenance problems
0 commit comments