sqoop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stanleyxu2005 <...@git.apache.org>
Subject [GitHub] sqoop pull request: Optimize toAvroIdentifier
Date Tue, 12 Apr 2016 08:21:55 GMT
Github user stanleyxu2005 commented on a diff in the pull request:

    https://github.com/apache/sqoop/pull/18#discussion_r59337930
  
    --- Diff: src/java/org/apache/sqoop/avro/AvroUtil.java ---
    @@ -114,11 +114,20 @@ public static String toAvroColumn(String column) {
        * Format candidate to avro specifics
        */
       public static String toAvroIdentifier(String candidate) {
    -    String formattedCandidate = candidate.replaceAll("\\W+", "_");
    -    if (formattedCandidate.substring(0,1).matches("[a-zA-Z_]")) {
    -      return formattedCandidate;
    +    char[] data = candidate.toCharArray();
    --- End diff --
    
    I'd suggest you create a private function `replaceWhitespace` and move your code logic
there. So it will be
    ```
      String formattedCandidate = replaceWhitespace(candidate);
    ```
    Second how can you make sure the string data has a valid length, so that `data[0]` is
valid? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message