Search in sources :

Example 1 with DateColumn

use of com.alibaba.datax.common.element.DateColumn in project DataX by alibaba.

the class UnstructuredStorageWriterUtil method transportOneRecord.

/**
     * 异常表示脏数据
     * */
public static void transportOneRecord(Record record, String nullFormat, DateFormat dateParse, TaskPluginCollector taskPluginCollector, UnstructuredWriter unstructuredWriter) {
    // warn: default is null
    if (null == nullFormat) {
        nullFormat = "null";
    }
    try {
        List<String> splitedRows = new ArrayList<String>();
        int recordLength = record.getColumnNumber();
        if (0 != recordLength) {
            Column column;
            for (int i = 0; i < recordLength; i++) {
                column = record.getColumn(i);
                if (null != column.getRawData()) {
                    boolean isDateColumn = column instanceof DateColumn;
                    if (!isDateColumn) {
                        splitedRows.add(column.asString());
                    } else {
                        if (null != dateParse) {
                            splitedRows.add(dateParse.format(column.asDate()));
                        } else {
                            splitedRows.add(column.asString());
                        }
                    }
                } else {
                    // warn: it's all ok if nullFormat is null
                    splitedRows.add(nullFormat);
                }
            }
        }
        unstructuredWriter.writeOneRecord(splitedRows);
    } catch (Exception e) {
        // warn: dirty data
        taskPluginCollector.collectDirtyRecord(record, e);
    }
}
Also used : DateColumn(com.alibaba.datax.common.element.DateColumn) Column(com.alibaba.datax.common.element.Column) DateColumn(com.alibaba.datax.common.element.DateColumn) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DataXException(com.alibaba.datax.common.exception.DataXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Column (com.alibaba.datax.common.element.Column)1 DateColumn (com.alibaba.datax.common.element.DateColumn)1 DataXException (com.alibaba.datax.common.exception.DataXException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1