Github user JamesRTaylor commented on a diff in the pull request:
https://github.com/apache/incubator-phoenix/pull/27#discussion_r11697228
--- 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) {
--- End diff --
What about ColumnAmbiguousException? How is that being handled?
---
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.
---