use of com.orientechnologies.orient.etl.OExtractedItem in project orientdb by orientechnologies.
the class OJDBCExtractor method next.
@Override
public OExtractedItem next() {
try {
if (!didNext) {
if (!rs.next())
throw new NoSuchElementException("[JDBC extractor] previous position was " + current);
}
didNext = false;
final ODocument doc = new ODocument();
for (int i = 0; i < rsColumns; i++) {
// final OType fieldType = columnTypes != null ? columnTypes.get(i) : null;
Object fieldValue = rs.getObject(i + 1);
doc.field(columnNames.get(i), fieldValue);
}
return new OExtractedItem(current++, doc);
} catch (SQLException e) {
throw new OExtractorException("[JDBC extractor] error on moving forward in resultset of query '" + query + "'. Previous position was " + current, e);
}
}
use of com.orientechnologies.orient.etl.OExtractedItem in project orientdb by orientechnologies.
the class OJsonExtractor method next.
@Override
public OExtractedItem next() {
if (next != null) {
final OExtractedItem ret = next;
next = null;
return ret;
}
if (!hasNext())
throw new NoSuchElementException("EOF");
try {
return fetchNext();
} catch (Exception e) {
throw new OExtractorException("[JSON extractor] error on extract json", e);
}
}
use of com.orientechnologies.orient.etl.OExtractedItem in project orientdb by orientechnologies.
the class ORowExtractor method next.
@Override
public OExtractedItem next() {
if (next != null) {
final OExtractedItem ret = next;
next = null;
return ret;
}
if (!hasNext())
throw new NoSuchElementException("EOF");
try {
return fetchNext();
} catch (IOException e) {
throw new OExtractorException(e);
}
}
use of com.orientechnologies.orient.etl.OExtractedItem in project orientdb by orientechnologies.
the class OCSVExtractor method fetchNext.
private OExtractedItem fetchNext(CSVRecord csvRecord) {
ODocument doc = new ODocument();
final Map<String, String> recordAsMap = csvRecord.toMap();
if (columnTypes.isEmpty()) {
for (Map.Entry<String, String> en : recordAsMap.entrySet()) {
final String value = en.getValue();
if (!csvFormat.getAllowMissingColumnNames() || !en.getKey().isEmpty()) {
if (value == null || nullValue.equals(value) || value.isEmpty())
doc.field(en.getKey(), null, OType.ANY);
else
doc.field(en.getKey(), determineTheType(value));
}
}
} else {
for (Map.Entry<String, OType> typeEntry : columnTypes.entrySet()) {
final String fieldName = typeEntry.getKey();
final OType fieldType = typeEntry.getValue();
String fieldValueAsString = recordAsMap.get(fieldName);
try {
if (fieldType != null && fieldType.getDefaultJavaType() != null && fieldType.getDefaultJavaType().equals(Date.class)) {
if (fieldType.equals(OType.DATE))
doc.field(fieldName, transformToDate(fieldValueAsString));
else
doc.field(fieldName, transformToDateTime(fieldValueAsString));
} else {
Object fieldValue = OType.convert(fieldValueAsString, fieldType.getDefaultJavaType());
doc.field(fieldName, fieldValue);
}
} catch (Exception e) {
processor.getStats().incrementErrors();
log(OETLProcessor.LOG_LEVELS.ERROR, "Error on converting row %d field '%s' value '%s' (class:%s) to type: %s", csvRecord.getRecordNumber(), fieldName, fieldValueAsString, fieldValueAsString.getClass().getName(), fieldType);
}
}
}
log(DEBUG, "document=%s", doc);
current++;
return new OExtractedItem(current, doc);
}
Aggregations