Когда я пытаюсь написать одно и то же значение для каждой строки для строки в файле ORC, только первая строка возвращает письменное значение, при чтении оставшихся строк сталкивается с нулевым вопросом указателя. В некоторых случаях мы могли бы столкнуться с этой проблемой, поэтому ищут решение этой проблемы < /p>
Logic Writer: < /p>
TypeDescription schema = TypeDescription.createStruct()
.addField("value", TypeDescription.createString())
.addField("quality", TypeDescription.createLong());
// Create a configuration object
Configuration conf = new Configuration();
// Create a WriterImpl instance
WriterImpl writer = (WriterImpl) OrcFile.createWriter(new Path("testString.orc"),
OrcFile.writerOptions(conf).setSchema(schema).stripeSize(1024).compress(CompressionKind.SNAPPY));
// Create a batch to hold the data
VectorizedRowBatch batch = schema.createRowBatch();
BytesColumnVector value = (BytesColumnVector)batch.cols[0];
LongColumnVector quality = (LongColumnVector)batch.cols[1];
int start = 0;
int end = 100;
while (start < end) {
int row = batch.size++;
value.setVal(row, ("value").getBytes(StandardCharsets.UTF_8));
quality.vector[row] = start;
start += 1;
if (batch.size == batch.getMaxSize()) {
writer.addRowBatch(batch);
batch.reset();
for (int i = 0; i < value.isNull.length; i++) {
value.isNull = true; // Mark all rows as null
}
}
}
if (batch.size != 0) {
writer.addRowBatch(batch);
batch.reset();
for (int i = 0; i < value.isNull.length; i++) {
value.isNull = true; // Mark all rows as null
}
}
writer.close();
< /code>
orc reader logic: < /p>
Reader reader = OrcFile.createReader(new Path("testString.orc"),
OrcFile.readerOptions(conf));
// Get the schema of the ORC file
TypeDescription schema = reader.getSchema();
// Create a batch to hold the data
VectorizedRowBatch batch = schema.createRowBatch();
// Create a RecordReader to read the data
RecordReader rows = reader.rows();
int rowcount = 1;
long startTime = System.currentTimeMillis();
// Read the data
while (rows.nextBatch(batch)) {
BytesColumnVector value = (BytesColumnVector) batch.cols[0];
for (int r = 0; r < batch.size; ++r) {
String valueStr = new String(value.vector[r], value.start[r], value.length[r]);
System.out.println("Row " + rowcount + " value: " + valueStr);
rowcount++;
}
}
System.out.println("Total time :: "+(System.currentTimeMillis() - startTime));
// Close the RecordReader
rows.close();
Подробнее здесь: https://stackoverflow.com/questions/795 ... using-java
Я пишу повторяющиеся строковые значения в строковый столбец в файле ORC с использованием Java и при чтении файла ORC обр ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение