THIS PAGE IS CURRENTLY AT DRAFT STAGE.
Since Sqoop2 is primarily JAVA, we will be using the google JAVA coding standards for the most parts. Some of the custom nuances that already exist in Sqoop are also highlighted with code examples,so new contributors spend your time wisely. When in doubt, use the google guide as a reference and email the email@example.com about a convention you deem is important for us to follow.
- No wildcard imports.
- Overloads appear sequentially.
- Braces are used even when the body is empty or contains a single statement.
- 2 spaces indentation.
- Column limit can be 80 or 100 characters.
- No C-style array declarations.
- The default statement in switch statements are required.
- Modifiers appear in the order recommended by the Java Language Specification.
- Constants use CONSTANT_CASE. Note that every constant is a static final field, but not all static final fields are constants
Must Follow Rules
The Apache License info must be present for all files. So please use a simple script to check this license header exists before uploading the patch. !
Wild card imports
Unless the entire set of imports are used in the file. For example in
DerbySchemaUpgradeQuery.java every single constant in
DerbySchemaConstants is used. In this case, it is ok to use wildcard.
Column Limit and Line Wrapping
We can use the 100 character limit.
Having said that, I have to steal this line from the Kafka Style guide.
There is not a maximum line length (certainly not 80 characters, we don't work on punch cards any more), but be reasonable
Import Order and Grouping
Import statements are not line-wrapped
- All static imports in a single group
com.*imports (only if this source file is in the
- Third-party imports, one group per top-level package, in ASCII sort order
- for example:
- for example:
Method Names in APIs
Method names are typically verbs or verb phrases. For example,
stopJob. We do not recommend
Do not ignore caught Exceptions
If in case, you have very legit reason to ignore it , have a comment, DO NOT leave it blank. It's also generally a good idea to log the error message, so that we know that it happened.
Some conventions in Sqoop that you should follow!
All unit test classes should be in the exact same package hierarchy as the source java class
All unit test classes should begin with Test for instance TestCSVInternmediateFormat.java instead of CSVIntermediateFormatTest. Integration tests apparently have
If you see code duplicated, please create a JIRA and let us all know, we can collectively do the cleanup.
Do not try to catch exceptions that you do not know how to handle, let it bubble up.
Try to use the IDE to clean-up unused imports
Try not to create code with warnings. Especially when the IDE is screaming at you and telling you how to fix them!
Goes without saying, do not have functions that run 100 lines long. break them down so it is easy to read and unit test
- Use Log.DEBUG / Log.INFO statements generously in code that is not easy to follow. It helps the person debugging your code!
- Use IDE for
toStringcode generation. Use IDE for refactoring cues.
- Apache Kafka Coding Guide very beautifully documents some of the basic stuff of writing code. Kindly read it.
Few of our favorites are:
- Clear code is preferable to comments. When possible make your naming so good you don't need comments. When that isn't possible comments should be thought of as mandatory, write them to beread.
- Don't be sloppy. Don't check in commented out code: we use version control, it is still there in the history. Don't leave TODOs in the code or FIXMEs if you can help it. Don't leave println statements in the code. Hopefully this is all obvious. But if you still need to leave a TODO, create a ticket and then leave a TODO(SQOOP-1444), so we know what the details of the TODO are and who created it.
- Don't duplicate code (duh). Not even in tests. Not even constants!
- Logging, configuration, and public APIs are our "UI". Make them pretty, consistent, and usable.
Sqoopesque Conventions !
Dont ask me which coding standard/ style guide prescribes the following conventions, but it exists in Sqoop predating 1.99.4 and the committers follow this religiously!. So spend you time wisely ! Feel free to leave comments on additional things you notice that might sound very much Sqoopesque ( Conventions that are less prevalent outside of Sqoop)
- Enum classes, the semicolon needs to be in its own line.
- Also the Error codes have a format! Error codes are in the format ERROR_XXXX - four digits with leading zeros.
Before you get on to uploading the patch, also read this wiki that will help with getting through larger feature reviews quicker