Hi,
Is there a way to extend the byte size of an existing string datatype? For example, I have a string column where the byte size is 3, but I extend the dataset in order to add more values, and now want to write a value that is 5 bytes. I've looked through the documentation to see if this is possible but haven't had any luck. I do know that I could instead use the variable length string data type to handle this. However, I am working with very large datasets, and there seems to be a very significant read/write performance penalty using variable length string data type.
I have an example test case below illustrating what I am trying to do, any pointers would be greatly appreciated.
Thanks,
Chris
@Test
public void testHdfStringWriter() throws Exception {
// create and open a temp file
File file = new File("c:\\temp.h5");
int fileId = H5.H5Fcreate(file.getAbsolutePath(),
HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
// define dimensions and create dataspace
int rowCount = 3;
long[] dataset_dims = { rowCount };
long[] max_dims = { HDF5Constants.H5S_UNLIMITED };
long[] chunk_dims = { rowCount };
int dataspaceId = H5.H5Screate_simple(1, dataset_dims, max_dims);
int dcplId = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
H5.H5Pset_deflate(dcplId, 9);
H5.H5Pset_chunk(dcplId, 1, chunk_dims);
// create 3 byte string datatype, then create the dataset
int strtypeId = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
H5.H5Tset_size(strtypeId, 3);
int datasetId = H5.H5Dcreate(fileId, "/dataset1", strtypeId,
dataspaceId, dcplId);
// write the data
String[] strings = { "111", "222","333" };
byte[][] stringData = new byte[rowCount][3];
for(int i=0; i<strings.length; i++){
stringData[i] = strings[i].getBytes();
}
H5.H5Dwrite(datasetId, strtypeId, HDF5Constants.H5S_ALL,
HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, stringData);
//try to increase byte size to 5
H5.H5Tset_size(strtypeId, 5);
//write longer strings
String[] newStrings = { "11111", "22222","33333" };
stringData = new byte[rowCount][5];
for(int i=0; i<strings.length; i++){
stringData[i] = newStrings[i].getBytes();
}
H5.H5Dwrite(datasetId, strtypeId, HDF5Constants.H5S_ALL,
HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, stringData);
H5.H5Tclose(strtypeId);
H5.H5Sclose(dataspaceId);
H5.H5Dclose(datasetId);
H5.H5Fclose(fileId);
}