private int addToColumnMetadataInfo(final List<String> columns , final Map<String,Integer> allColumnsInfoMap, int position) throws SQLException { Preconditions.checkNotNull(columns); Preconditions.checkNotNull(allColumnsInfoMap); for (int i = 0 ; i < columns.size() ; i++) { String columnName = SchemaUtil.normalizeIdentifier(columns.get(i).trim()); Integer sqlType = allColumnsInfoMap.get(columnName); if (sqlType == null) { throw new SQLExceptionInfo.Builder(SQLExceptionCode.COLUMN_NOT_FOUND) .setColumnName(columnName).setTableName(this.fullTableName).build().buildException(); } else { columnMetadata[position] = new ColumnInfo(columnName, sqlType); position++; } } return position; }
/** * This method creates the Upsert statement and the Column Metadata * for the Pig query using {@link PhoenixHBaseStorage}. It also * determines the batch size based on user provided options. * * @param conn * @throws SQLException */ public void setup(Connection conn) throws SQLException { // Reset batch size long batchSize = getBatchSize() <= 0 ? ((PhoenixConnection) conn).getMutateBatchSize() : getBatchSize(); conf.setLong(UPSERT_BATCH_SIZE, batchSize); if (columnMetadataList == null) { columnMetadataList = new ArrayList<ColumnInfo>(); String[] tableMetadata = getTableMetadata(getTableName()); ResultSet rs = conn.getMetaData().getColumns(null, tableMetadata[0], tableMetadata[1], null); while (rs.next()) { columnMetadataList.add(new ColumnInfo(rs.getString(QueryUtil.COLUMN_NAME_POSITION), rs.getInt(QueryUtil.DATA_TYPE_POSITION))); } } // Generating UPSERT statement without column name information. String upsertStmt = QueryUtil.constructUpsertStatement(null, getTableName(), columnMetadataList.size()); LOG.info("Phoenix Upsert Statement: " + upsertStmt); conf.set(UPSERT_STATEMENT, upsertStmt); }
columnType = new ColumnInfo[columnNameToTypeMap.size()]; for (Map.Entry<String, Integer> entry : columnNameToTypeMap.entrySet()) { columnType[i++] = new ColumnInfo(entry.getKey(),entry.getValue()); columnType[i] = new ColumnInfo(columnName, sqlType);
.setColumnName(rowkey).setTableName(fullTableName).build().buildException(); columnMetadata[position] = new ColumnInfo(rowkey, sqlType); position++;