Search in sources :

Example 6 with ColumnInfo

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

the class PhoenixConfigurationUtil method getSelectColumnMetadataList.

public static List<ColumnInfo> getSelectColumnMetadataList(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 = getInputTableName(configuration);
    Preconditions.checkNotNull(tableName);
    final Connection connection = ConnectionUtil.getInputConnection(configuration);
    final List<String> selectColumnList = getSelectColumnList(configuration);
    columnMetadataList = PhoenixRuntime.generateColumnInfo(connection, tableName, selectColumnList);
    // 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 7 with ColumnInfo

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

the class FormatToBytesWritableMapperTest method testBuildColumnInfoList.

@Test
public void testBuildColumnInfoList() {
    List<ColumnInfo> columnInfoList = ImmutableList.of(new ColumnInfo("idCol", PInteger.INSTANCE.getSqlType()), new ColumnInfo("unsignedIntCol", PUnsignedInt.INSTANCE.getSqlType()), new ColumnInfo("stringArrayCol", PIntegerArray.INSTANCE.getSqlType()));
    Configuration conf = new Configuration();
    FormatToBytesWritableMapper.configureColumnInfoList(conf, columnInfoList);
    List<ColumnInfo> fromConfig = FormatToBytesWritableMapper.buildColumnInfoList(conf);
    assertEquals(columnInfoList, fromConfig);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ColumnInfo(org.apache.phoenix.util.ColumnInfo) Test(org.junit.Test)

Example 8 with ColumnInfo

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

the class ColumnInfoToStringEncoderDecoderTest method testEncodeDecodeWithNulls.

@Test
public void testEncodeDecodeWithNulls() {
    final Configuration configuration = new Configuration();
    final ColumnInfo columnInfo1 = new ColumnInfo("col1", PVarchar.INSTANCE.getSqlType());
    ArrayList<ColumnInfo> expectedColInfos = Lists.newArrayList(columnInfo1);
    ColumnInfoToStringEncoderDecoder.encode(configuration, Lists.newArrayList(columnInfo1, null));
    //verify the configuration has the correct values
    assertEquals(1, configuration.getInt(ColumnInfoToStringEncoderDecoder.CONFIGURATION_COUNT, 0));
    assertEquals(columnInfo1.toString(), configuration.get(String.format("%s_%d", ColumnInfoToStringEncoderDecoder.CONFIGURATION_VALUE_PREFIX, 0)));
    List<ColumnInfo> actualColInfos = ColumnInfoToStringEncoderDecoder.decode(configuration);
    assertEquals(expectedColInfos, actualColInfos);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ColumnInfo(org.apache.phoenix.util.ColumnInfo) Test(org.junit.Test)

Example 9 with ColumnInfo

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

the class ColumnInfoToStringEncoderDecoderTest method testEncodeDecode.

@Test
public void testEncodeDecode() {
    final Configuration configuration = new Configuration();
    final ColumnInfo columnInfo1 = new ColumnInfo("col1", PVarchar.INSTANCE.getSqlType());
    final ColumnInfo columnInfo2 = new ColumnInfo("col2", PDate.INSTANCE.getSqlType());
    ArrayList<ColumnInfo> expectedColInfos = Lists.newArrayList(columnInfo1, columnInfo2);
    ColumnInfoToStringEncoderDecoder.encode(configuration, expectedColInfos);
    //verify the configuration has the correct values
    assertEquals(2, configuration.getInt(ColumnInfoToStringEncoderDecoder.CONFIGURATION_COUNT, 0));
    assertEquals(columnInfo1.toString(), configuration.get(String.format("%s_%d", ColumnInfoToStringEncoderDecoder.CONFIGURATION_VALUE_PREFIX, 0)));
    assertEquals(columnInfo2.toString(), configuration.get(String.format("%s_%d", ColumnInfoToStringEncoderDecoder.CONFIGURATION_VALUE_PREFIX, 1)));
    List<ColumnInfo> actualColInfos = ColumnInfoToStringEncoderDecoder.decode(configuration);
    assertEquals(expectedColInfos, actualColInfos);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ColumnInfo(org.apache.phoenix.util.ColumnInfo) Test(org.junit.Test)

Example 10 with ColumnInfo

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

the class PhoenixResultWritable method write.

@Override
public void write(PreparedStatement statement) throws SQLException {
    ColumnInfo columnInfo = null;
    Object value = null;
    try {
        for (int i = 0, limit = columnMetadataList.size(); i < limit; i++) {
            columnInfo = columnMetadataList.get(i);
            if (valueList.size() > i) {
                value = valueList.get(i);
            } else {
                value = null;
            }
            if (value == null) {
                statement.setNull(i + 1, columnInfo.getSqlType());
            } else {
                statement.setObject(i + 1, value, columnInfo.getSqlType());
            }
        }
    } catch (SQLException | RuntimeException e) {
        LOG.error("[column-info, value] : " + columnInfo + ", " + value);
        throw e;
    }
}
Also used : SQLException(java.sql.SQLException) 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