Search in sources :

Example 1 with OExtractedItem

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);
    }
}
Also used : SQLException(java.sql.SQLException) OExtractedItem(com.orientechnologies.orient.etl.OExtractedItem) NoSuchElementException(java.util.NoSuchElementException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OExtractedItem

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);
    }
}
Also used : OExtractedItem(com.orientechnologies.orient.etl.OExtractedItem) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) ParseException(java.text.ParseException) NoSuchElementException(java.util.NoSuchElementException)

Example 3 with OExtractedItem

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);
    }
}
Also used : OExtractedItem(com.orientechnologies.orient.etl.OExtractedItem) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException)

Example 4 with OExtractedItem

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);
}
Also used : OType(com.orientechnologies.orient.core.metadata.schema.OType) OExtractedItem(com.orientechnologies.orient.etl.OExtractedItem) IOException(java.io.IOException) ParseException(java.text.ParseException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OExtractedItem (com.orientechnologies.orient.etl.OExtractedItem)4 IOException (java.io.IOException)3 NoSuchElementException (java.util.NoSuchElementException)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 ParseException (java.text.ParseException)2 OType (com.orientechnologies.orient.core.metadata.schema.OType)1 SQLException (java.sql.SQLException)1