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;
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations