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

    https://github.com/apache/incubator-phoenix/pull/27#discussion_r11697205
  
    --- Diff: 
phoenix-core/src/main/java/org/apache/phoenix/util/PhoenixRuntime.java ---
    @@ -342,6 +346,111 @@ private static PTable getTable(Connection conn, 
String name) throws SQLException
         }
         
         /**
    +     * Get list of ColumnInfos that contain Column Name and its associated
    +     * PDataType for an import. The supplied list of columns can be null 
-- if it is non-null,
    +     * it represents a user-supplied list of columns to be imported.
    +     *
    +     * @param conn Phoenix connection from which metadata will be read
    +     * @param tableName Phoenix table name whose columns are to be 
checked. Can include a schema
    +     *                  name
    +     * @param columns user-supplied list of import columns, can be null
    +     */
    +    public static List<ColumnInfo> generateColumnInfo(Connection conn,
    +            String tableName, List<String> columns)
    +            throws SQLException {
    +
    +        PTable table = PhoenixRuntime.getTable(conn, tableName);
    +        List<ColumnInfo> columnInfoList = Lists.newArrayList();
    +        Set<String> unresolvedColumnNames = new TreeSet<String>();
    +        if (columns == null) {
    +            // use all columns in the table
    +            for(PColumn pColumn : table.getColumns()) {
    +               int sqlType = pColumn.getDataType().getResultSetSqlType();  
      
    +               columnInfoList.add(new ColumnInfo(pColumn.toString(), 
sqlType));
    +            }
    +        } else {
    +            // Leave "null" as indication to skip b/c it doesn't exist
    +            for (int i = 0; i < columns.size(); i++) {
    +                String columnName = columns.get(i);
    +                try {
    +                    ColumnInfo columnInfo = 
PhoenixRuntime.getColumnInfo(table, columnName);
    +                    columnInfoList.add(columnInfo);
    +                } catch (ColumnNotFoundException cnfe) {
    +                    unresolvedColumnNames.add(columnName.trim());
    +                }
    +            }
    +                
    +            if (unresolvedColumnNames.size()>0) {
    +                StringBuilder exceptionMessage = new StringBuilder();
    +                boolean first = true;
    +                exceptionMessage.append("Unable to resolve these column 
names:\n");
    +                for (String col : unresolvedColumnNames) {
    +                    if (first) first = false;
    +                    else exceptionMessage.append(",");
    +                    exceptionMessage.append(col);
    +                }
    +                exceptionMessage.append("\nAvailable columns with column 
families:\n");
    +                first = true;
    +                for (PColumn pColumn : table.getColumns()) {
    +                    if (first) first = false;
    +                    else exceptionMessage.append(",");
    +                    exceptionMessage.append(pColumn.toString());
    +                }
    +                throw new SQLException(exceptionMessage.toString()); 
    +            }
    +                
    +        }
    +        return columnInfoList;
    +    }
    +
    +    /**
    +     * Returns the column info for the given column for the given table.
    +     * 
    +     * @param table
    +     * @param columnName User-specified column name. May be 
family-qualified or bare.
    +     * @return columnInfo associated with the column in the table
    +     * @throws SQLException if parameters are null, or if column is not 
found.
    --- End diff --
    
    or if column is ambiguous


---
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