Github user hyunsik commented on a diff in the pull request:

    https://github.com/apache/tajo/pull/624#discussion_r36580081
  
    --- Diff: 
tajo-catalog/tajo-catalog-server/src/main/java/org/apache/tajo/catalog/store/AbstractDBStore.java
 ---
    @@ -2114,6 +2114,127 @@ private void setPartitionKeys(int pid, 
PartitionDescProto.Builder partitionDesc)
       }
     
       @Override
    +  public boolean existPartitions(String databaseName, String tableName) 
throws CatalogException {
    +    Connection conn = null;
    +    ResultSet res = null;
    +    PreparedStatement pstmt = null;
    +    boolean result = false;
    +
    +    try {
    +      String sql = "SELECT COUNT(*) CNT FROM "
    +        + TB_PARTTIONS +" WHERE " + COL_TABLES_PK + " = ?  ";
    +
    +      if (LOG.isDebugEnabled()) {
    +        LOG.debug(sql);
    +      }
    +
    +      int databaseId = getDatabaseId(databaseName);
    +      int tableId = getTableId(databaseId, databaseName, tableName);
    +
    +      conn = getConnection();
    +      pstmt = conn.prepareStatement(sql);
    +      pstmt.setInt(1, tableId);
    +      res = pstmt.executeQuery();
    +
    +      if (res.next()) {
    +        if (res.getInt("CNT") > 0) {
    +          result = true;
    +        }
    +      }
    +    } catch (SQLException se) {
    +      throw new TajoInternalError(se);
    +    } finally {
    +      CatalogUtil.closeQuietly(pstmt, res);
    +    }
    +    return result;
    +  }
    +
    +  @Override
    +  public List<TablePartitionProto> 
getPartitionsByDirectSql(GetPartitionsWithDirectSQLRequest request)
    --- End diff --
    
    Catalog API is public. In terms of this point, this API design does not 
make sense due to the following problems:
     * Users should know table schemas, their relationship, which underlying 
persistent storage.
      * Users should make SQL statements for all persistent storages.
     * This approach is very prone to SQL injection.
    
    The solution is that you can use some intermediate representation, using 
string or java objects. They should be transformed into SQL statements 
depending on persistent storages in each catalog driver.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to