use of org.neo4j.internal.batchimport.input.InputException in project neo4j by neo4j.
the class CsvInputTest method shouldPropagateExceptionFromFailingDecorator.
@Test
public void shouldPropagateExceptionFromFailingDecorator() throws Exception {
// GIVEN
RuntimeException failure = new RuntimeException("FAILURE");
Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,name\n1,Mattias", new FailingNodeDecorator(failure)));
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatNodeFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
readNext(nodes);
} catch (InputException e) {
// THEN
assertSame(e.getCause(), failure);
}
}
use of org.neo4j.internal.batchimport.input.InputException in project neo4j by neo4j.
the class CsvInputParser method next.
boolean next(InputEntityVisitor visitor) throws IOException {
lineNumber++;
int i = 0;
Header.Entry entry = null;
Header.Entry[] entries = header.entries();
try {
boolean doContinue = true;
for (i = 0; i < entries.length && doContinue; i++) {
entry = entries[i];
if (!seeker.seek(mark, delimiter)) {
if (i > 0) {
throw new UnexpectedEndOfInputException("Near " + mark);
}
// We're just at the end
return false;
}
switch(entry.type()) {
case ID:
if (seeker.tryExtract(mark, entry.extractor())) {
switch(idType) {
case STRING:
case INTEGER:
Object idValue = entry.extractor().value();
doContinue = visitor.id(idValue, entry.group());
if (entry.name() != null) {
doContinue = visitor.property(entry.name(), idValue);
}
break;
case ACTUAL:
doContinue = visitor.id(((LongExtractor) entry.extractor()).longValue());
break;
default:
throw new IllegalArgumentException(idType.name());
}
}
break;
case START_ID:
if (seeker.tryExtract(mark, entry.extractor())) {
switch(idType) {
case STRING:
doContinue = visitor.startId(entry.extractor().value(), entry.group());
break;
case INTEGER:
doContinue = visitor.startId(entry.extractor().value(), entry.group());
break;
case ACTUAL:
doContinue = visitor.startId(((LongExtractor) entry.extractor()).longValue());
break;
default:
throw new IllegalArgumentException(idType.name());
}
}
break;
case END_ID:
if (seeker.tryExtract(mark, entry.extractor())) {
switch(idType) {
case STRING:
doContinue = visitor.endId(entry.extractor().value(), entry.group());
break;
case INTEGER:
doContinue = visitor.endId(entry.extractor().value(), entry.group());
break;
case ACTUAL:
doContinue = visitor.endId(((LongExtractor) entry.extractor()).longValue());
break;
default:
throw new IllegalArgumentException(idType.name());
}
}
break;
case TYPE:
if (seeker.tryExtract(mark, entry.extractor())) {
doContinue = visitor.type((String) entry.extractor().value());
}
break;
case PROPERTY:
if (seeker.tryExtract(mark, entry.extractor(), entry.optionalParameter())) {
// TODO since PropertyStore#encodeValue takes Object there's no point splitting up
// into different primitive types
Object value = entry.extractor().value();
if (!isEmptyArray(value)) {
doContinue = visitor.property(entry.name(), value);
}
}
break;
case LABEL:
if (seeker.tryExtract(mark, entry.extractor())) {
Object labelsValue = entry.extractor().value();
if (labelsValue.getClass().isArray()) {
doContinue = visitor.labels((String[]) labelsValue);
} else {
doContinue = visitor.labels(new String[] { (String) labelsValue });
}
}
break;
case IGNORE:
break;
default:
throw new IllegalArgumentException(entry.type().toString());
}
if (mark.isEndOfLine()) {
// We're at the end of the line, break and return an entity with what we have.
break;
}
}
while (!mark.isEndOfLine()) {
seeker.seek(mark, delimiter);
if (doContinue) {
seeker.tryExtract(mark, stringExtractor, entry.optionalParameter());
badCollector.collectExtraColumns(seeker.sourceDescription(), lineNumber, stringExtractor.value());
}
}
visitor.endOfEntity();
return true;
} catch (final RuntimeException e) {
String stringValue = null;
try {
Extractors extractors = new Extractors('?');
if (seeker.tryExtract(mark, extractors.string(), entry.optionalParameter())) {
stringValue = extractors.string().value();
}
} catch (Exception e1) {
// OK
}
String message = format("ERROR in input" + "%n data source: %s" + "%n in field: %s" + "%n for header: %s" + "%n raw field value: %s" + "%n original error: %s", seeker, entry + ":" + (i + 1), header, stringValue != null ? stringValue : "??", e.getMessage());
if (e instanceof InputException) {
throw Exceptions.withMessage(e, message);
}
throw new InputException(message, e);
}
}
use of org.neo4j.internal.batchimport.input.InputException in project neo4j by neo4j.
the class CsvInputTest method shouldNotParsePointPropertyValuesWithDuplicateKeys.
@Test
public void shouldNotParsePointPropertyValuesWithDuplicateKeys() throws Exception {
// GIVEN
DataFactory data = data(":ID,name,point:Point\n" + "1,Johan,\" { height :0.01 ,longitude:5, latitude : -4.2, latitude : 4.2 } \"\n");
Iterable<DataFactory> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
// WHEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
// THEN
readNext(nodes);
fail("Should have failed when key assigned multiple times, but didn't.");
} catch (InputException ignore) {
// this is fine
}
}
Aggregations