MCPcopy Index your code
hub / github.com/apache/orc / TestScanData

Class TestScanData

java/tools/src/test/org/apache/orc/tools/TestScanData.java:40–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38import static org.junit.jupiter.api.Assertions.assertTrue;
39
40public class TestScanData implements TestConf {
41 private Path workDir = new Path(System.getProperty("test.tmp.dir"));
42 private FileSystem fs;
43 private Path testFilePath;
44
45 @BeforeEach
46 public void openFileSystem() throws Exception {
47 fs = FileSystem.getLocal(conf);
48 testFilePath = new Path(workDir + File.separator + "TestScanData.testScan.orc");
49 fs.delete(testFilePath, false);
50 }
51
52 @Test
53 public void testScan() throws Exception {
54 TypeDescription schema = TypeDescription.fromString("struct<x:int,y:string>");
55 Writer writer = OrcFile.createWriter(testFilePath,
56 OrcFile.writerOptions(conf)
57 .setSchema(schema));
58 VectorizedRowBatch batch = schema.createRowBatch();
59 LongColumnVector x = (LongColumnVector) batch.cols[0];
60 BytesColumnVector y = (BytesColumnVector) batch.cols[1];
61 for (int r = 0; r < 10000; ++r) {
62 int row = batch.size++;
63 x.vector[row] = r;
64 byte[] buffer = ("byte-" + r).getBytes();
65 y.setRef(row, buffer, 0, buffer.length);
66 if (batch.size == batch.getMaxSize()) {
67 writer.addRowBatch(batch);
68 batch.reset();
69 }
70 }
71 if (batch.size != 0) {
72 writer.addRowBatch(batch);
73 }
74 writer.close();
75
76 PrintStream origOut = System.out;
77 ByteArrayOutputStream myOut = new ByteArrayOutputStream();
78 // replace stdout and run command
79 System.setOut(new PrintStream(myOut, false, StandardCharsets.UTF_8));
80 ScanData.main(conf, new String[]{"--schema", testFilePath.toString()});
81 System.out.flush();
82 System.setOut(origOut);
83 String output = myOut.toString(StandardCharsets.UTF_8);
84 assertTrue(output.contains("{\"category\": \"struct\", \"id\": 0, \"max\": 2, \"fields\": [\n" +
85 "{ \"x\": {\"category\": \"int\", \"id\": 1, \"max\": 1}},\n" +
86 "{ \"y\": {\"category\": \"string\", \"id\": 2, \"max\": 2}}]}"));
87 assertTrue(output.contains("TestScanData.testScan.orc, bad batches: 0, rows: 10000/10000"));
88 }
89}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected