metamodel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arjansh <...@git.apache.org>
Subject [GitHub] metamodel pull request #185: Don't support primary keys with Hive
Date Wed, 22 Aug 2018 13:12:32 GMT
Github user arjansh commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/185#discussion_r211947345
  
    --- Diff: jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcCreateTableBuilder.java ---
    @@ -115,21 +115,23 @@ private String createSqlStatement(Table table) {
                     sb.append(" NOT NULL");
                 }
             }
    -        boolean primaryKeyExists = false;
    -        for (int i = 0; i < columns.size(); i++) {
    -            if (columns.get(i).isPrimaryKey()) {
    -                if (!primaryKeyExists) {
    -                    sb.append(", PRIMARY KEY(");
    -                    sb.append(columns.get(i).getName());
    -                    primaryKeyExists = true;
    -                } else {
    -                    sb.append(",");
    -                    sb.append(columns.get(i).getName());
    +        if (queryRewriter.isPrimaryKeySupported()) {
    +            boolean primaryKeyExists = false;
    --- End diff --
    
    Not completely related to this pull request, but something that we can address in this
context anyway, because the added if statement here only adds to the cognitive complexity
of this method. Lines 119 through 134 are a carbon copy of lines 130 through 145 from the
super class `AbstractTableCreationBuilder`. So maybe it's an option to extract that code into
a separate method on the `AbstractTableCreationBuilder`, which can be invoked here too, this
both removes the copy/pasted code and reduces the cognitive complexity of this method.


---

Mime
View raw message