Search in sources :

Example 1 with InputException

use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.

the class ImportPanicIT method shouldExitAndThrowExceptionOnPanic.

/**
     * There was this problem where some steps and in particular parallel CSV input parsing that
     * paniced would hang the import entirely.
     */
@Test
public void shouldExitAndThrowExceptionOnPanic() throws Exception {
    // GIVEN
    BatchImporter importer = new ParallelBatchImporter(directory.absolutePath(), fs, Configuration.DEFAULT, NullLogService.getInstance(), ExecutionMonitors.invisible(), AdditionalInitialIds.EMPTY, Config.empty(), StandardV3_0.RECORD_FORMATS);
    Iterable<DataFactory<InputNode>> nodeData = nodeData(data(NO_NODE_DECORATOR, fileAsCharReadable(nodeCsvFileWithBrokenEntries())));
    Input brokenCsvInput = new CsvInput(nodeData, defaultFormatNodeFileHeader(), relationshipData(), defaultFormatRelationshipFileHeader(), IdType.ACTUAL, csvConfigurationWithLowBufferSize(), new BadCollector(new NullOutputStream(), 0, 0), Runtime.getRuntime().availableProcessors());
    // WHEN
    try {
        importer.doImport(brokenCsvInput);
        fail("Should have failed properly");
    } catch (InputException e) {
        // THEN
        assertTrue(e.getCause() instanceof DataAfterQuoteException);
    // and we managed to shut down properly
    }
}
Also used : CsvInput(org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput) Input(org.neo4j.unsafe.impl.batchimport.input.Input) BadCollector(org.neo4j.unsafe.impl.batchimport.input.BadCollector) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) DataFactory(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactory) CsvInput(org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput) DataAfterQuoteException(org.neo4j.csv.reader.DataAfterQuoteException) Test(org.junit.Test)

Example 2 with InputException

use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.

the class ImportToolTest method shouldPrintUserFriendlyMessageAboutUnsupportedMultilineFields.

@Test
public void shouldPrintUserFriendlyMessageAboutUnsupportedMultilineFields() throws Exception {
    // GIVEN
    File data = data(":ID,name", "1,\"one\ntwo\nthree\"", "2,four");
    try {
        importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", data.getAbsolutePath(), "--multiline-fields", "false");
        fail("Should have failed");
    } catch (InputException e) {
        // THEN
        assertTrue(suppressOutput.getErrorVoice().containsMessage("Detected field which spanned multiple lines"));
        assertTrue(suppressOutput.getErrorVoice().containsMessage("multiline-fields"));
    }
}
Also used : InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) File(java.io.File) Test(org.junit.Test)

Example 3 with InputException

use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.

the class ImportToolTest method shouldPrintStackTraceOnInputExceptionIfToldTo.

@Test
public void shouldPrintStackTraceOnInputExceptionIfToldTo() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    // WHEN data file contains more columns than header file
    int extraColumns = 3;
    try {
        importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeHeader(config).getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).getAbsolutePath(), "--stacktrace");
        fail("Should have thrown exception");
    } catch (InputException e) {
        // THEN
        assertTrue(suppressOutput.getErrorVoice().containsMessage(e.getClass().getName()));
        assertTrue(e.getMessage().contains("Extra column not present in header on line"));
    }
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 4 with InputException

use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.

the class InputEntityDeserializer method close.

@Override
public void close() {
    try {
        decorator.close();
        data.close();
    } catch (IOException e) {
        throw new InputException("Unable to close data iterator", e);
    }
}
Also used : UnexpectedEndOfInputException(org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) IOException(java.io.IOException)

Example 5 with InputException

use of org.neo4j.unsafe.impl.batchimport.input.InputException in project neo4j by neo4j.

the class InputEntityDeserializer method fetchNextOrNull.

@Override
protected ENTITY fetchNextOrNull() {
    // Read a CSV "line" and convert the values into what they semantically mean.
    try {
        if (!deserializeNextFromSource()) {
            return null;
        }
        // When we have everything, create an input entity out of it
        ENTITY entity = deserialization.materialize();
        // less columns than the data. Prints in close() so it only happens once per file.
        while (!mark.isEndOfLine()) {
            long lineNumber = data.lineNumber();
            data.seek(mark, delimiter);
            data.tryExtract(mark, stringExtractor);
            badCollector.collectExtraColumns(data.sourceDescription(), lineNumber, stringExtractor.value());
        }
        entity = decorator.apply(entity);
        validator.validate(entity);
        return entity;
    } catch (IOException e) {
        throw new InputException("Unable to read more data from input stream", e);
    } finally {
        deserialization.clear();
    }
}
Also used : UnexpectedEndOfInputException(org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) IOException(java.io.IOException)

Aggregations

InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)13 Test (org.junit.Test)9 IOException (java.io.IOException)4 Input (org.neo4j.unsafe.impl.batchimport.input.Input)4 UnexpectedEndOfInputException (org.neo4j.unsafe.impl.batchimport.input.UnexpectedEndOfInputException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 CharSeeker (org.neo4j.csv.reader.CharSeeker)2 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)2 Configuration (org.neo4j.unsafe.impl.batchimport.input.csv.Configuration)2 DataFactories.defaultFormatNodeFileHeader (org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader)2 File (java.io.File)1 DataAfterQuoteException (org.neo4j.csv.reader.DataAfterQuoteException)1 Extractors (org.neo4j.csv.reader.Extractors)1 BadCollector (org.neo4j.unsafe.impl.batchimport.input.BadCollector)1 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)1 CsvInput (org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput)1 DataFactory (org.neo4j.unsafe.impl.batchimport.input.csv.DataFactory)1