Search in sources :

Example 16 with ColumnInfo

use of org.apache.phoenix.util.ColumnInfo in project phoenix by apache.

the class PhoenixConfigurationUtil method getUpsertColumnMetadataList.

public static List<ColumnInfo> getUpsertColumnMetadataList(final Configuration configuration) throws SQLException {
    Preconditions.checkNotNull(configuration);
    List<ColumnInfo> columnMetadataList = null;
    columnMetadataList = ColumnInfoToStringEncoderDecoder.decode(configuration);
    if (columnMetadataList != null && !columnMetadataList.isEmpty()) {
        return columnMetadataList;
    }
    final String tableName = getOutputTableName(configuration);
    Preconditions.checkNotNull(tableName);
    final Connection connection = ConnectionUtil.getOutputConnection(configuration);
    List<String> upsertColumnList = PhoenixConfigurationUtil.getUpsertColumnNames(configuration);
    if (!upsertColumnList.isEmpty()) {
        LOG.info(String.format("UseUpsertColumns=%s, upsertColumnList.size()=%s, upsertColumnList=%s ", !upsertColumnList.isEmpty(), upsertColumnList.size(), Joiner.on(",").join(upsertColumnList)));
    }
    columnMetadataList = PhoenixRuntime.generateColumnInfo(connection, tableName, upsertColumnList);
    // we put the encoded column infos in the Configuration for re usability.
    ColumnInfoToStringEncoderDecoder.encode(configuration, columnMetadataList);
    connection.close();
    return columnMetadataList;
}
Also used : Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ColumnInfo(org.apache.phoenix.util.ColumnInfo)

Example 17 with ColumnInfo

use of org.apache.phoenix.util.ColumnInfo in project phoenix by apache.

the class PhoenixIndexDBWritable method write.

@Override
public void write(PreparedStatement statement) throws SQLException {
    Preconditions.checkNotNull(values);
    Preconditions.checkNotNull(columnMetadata);
    for (int i = 0; i < values.size(); i++) {
        Object value = values.get(i);
        ColumnInfo columnInfo = columnMetadata.get(i);
        if (value == null) {
            statement.setNull(i + 1, columnInfo.getSqlType());
        } else {
            statement.setObject(i + 1, value, columnInfo.getSqlType());
        }
    }
}
Also used : ColumnInfo(org.apache.phoenix.util.ColumnInfo)

Aggregations

ColumnInfo (org.apache.phoenix.util.ColumnInfo)17 SQLException (java.sql.SQLException)6 Test (org.junit.Test)5 Connection (java.sql.Connection)4 Configuration (org.apache.hadoop.conf.Configuration)4 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)3 IOException (java.io.IOException)2 PDataType (org.apache.phoenix.schema.types.PDataType)2 ResourceFieldSchema (org.apache.pig.ResourceSchema.ResourceFieldSchema)2 Function (com.google.common.base.Function)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Path (org.apache.hadoop.fs.Path)1 ColumnProjector (org.apache.phoenix.compile.ColumnProjector)1 QueryPlan (org.apache.phoenix.compile.QueryPlan)1 SQLExceptionInfo (org.apache.phoenix.exception.SQLExceptionInfo)1 PhoenixDriver (org.apache.phoenix.jdbc.PhoenixDriver)1