All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mongodb.spark.pickle.CalendarTransformer Maven / Gradle / Ivy

Go to download

The MongoDB Connector for Hadoop is a plugin for Hadoop that provides the ability to use MongoDB as an input source and/or an output destination.

There is a newer version: 2.0.2
Show newest version
package com.mongodb.spark.pickle;

import org.bson.Transformer;

import java.util.Calendar;
import java.util.TimeZone;

/**
 * Transformer that turns java.util.Calendar objects into java.util.Date
 * objects.
 *
 * This class is needed because Spark constructs pickled Python
 * datetime.datetime objects into java.util.GregorianCalendar instances instead
 * of java.util.Date objects.
 */
public class CalendarTransformer implements Transformer {
    @Override
    public Object transform(final Object objectToTransform) {
        Calendar calendar = (Calendar) objectToTransform;
        calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
        return calendar.getTime();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy