protected JsonInputMeta createSimpleMeta(String inputColumn, JsonInputField... jsonPathFields) { JsonInputMeta jsonInputMeta = new JsonInputMeta(); jsonInputMeta.setDefault(); jsonInputMeta.setInFields(true); jsonInputMeta.setFieldValue(inputColumn); jsonInputMeta.setInputFields(jsonPathFields); jsonInputMeta.setIgnoreMissingPath(false); return jsonInputMeta; }
@Test public void testRowLimit() throws Exception { final String inCol = "json"; JsonInputField jpath = new JsonInputField("isbn"); jpath.setPath("$..book[*].isbn"); jpath.setType(ValueMetaInterface.TYPE_STRING); JsonInputMeta meta = createSimpleMeta(inCol, jpath); meta.setRemoveSourceField(true); meta.setIgnoreMissingPath(true); meta.setRowLimit(2); JsonInput jsonInput = createJsonInput("json", meta, new Object[] {getBasicTestJson()}); processRows(jsonInput, 4); Assert.assertEquals("errors", 0, jsonInput.getErrors()); Assert.assertEquals("lines written", 2, jsonInput.getLinesWritten()); }
@Test public void testDefaultLeafToNull() throws Exception { JsonInputField noPath = new JsonInputField("price"); noPath.setPath("$..price"); noPath.setType(ValueMetaInterface.TYPE_STRING); ByteArrayOutputStream out = new ByteArrayOutputStream(); helper.redirectLog(out, LogLevel.ERROR); JsonInputMeta meta = createSimpleMeta("json", noPath); meta.setIgnoreMissingPath(true); meta.setRemoveSourceField(true); final String input = getBasicTestJson(); JsonInput jsonInput = createJsonInput("json", meta, new Object[] {input}, new Object[] {input}); processRows(jsonInput, 7); disposeJsonInput(jsonInput); Assert.assertEquals(5, jsonInput.getLinesWritten()); }
protected JsonInputMeta createFileListMeta(final List<FileObject> files) { JsonInputMeta meta = new JsonInputMeta() { @Override public FileInputList getFileInputList(VariableSpace space) { return new FileInputList() { @Override public List<FileObject> getFiles() { return files; } @Override public int nrOfFiles() { return files.size(); } }; } }; meta.setDefault(); meta.setInFields(false); meta.setIgnoreMissingPath(false); return meta; }