Example usage for org.joda.time DateTimeZone setDefault

List of usage examples for org.joda.time DateTimeZone setDefault

Introduction

In this page you can find the example usage for org.joda.time DateTimeZone setDefault.

Prototype

public static void setDefault(DateTimeZone zone) throws SecurityException 

Source Link

Document

Sets the default time zone.

Usage

From source file:org.apache.gobblin.source.DatePartitionedNestedRetriever.java

License:Apache License

@Override
public void init(SourceState state) {
    DateTimeZone.setDefault(DateTimeZone.forID(
            state.getProp(ConfigurationKeys.SOURCE_TIMEZONE, ConfigurationKeys.DEFAULT_SOURCE_TIMEZONE)));

    initDatePartition(state);/*from   w  ww  . j  av a  2  s . c o m*/
    this.sourcePartitionPrefix = state
            .getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_PREFIX, StringUtils.EMPTY);

    this.sourcePartitionSuffix = state
            .getProp(PartitionedFileSourceBase.DATE_PARTITIONED_SOURCE_PARTITION_SUFFIX, StringUtils.EMPTY);
    this.sourceDir = new Path(state.getProp(ConfigurationKeys.SOURCE_FILEBASED_DATA_DIRECTORY));
    this.leadTimeDuration = PartitionAwareFileRetrieverUtils.getLeadTimeDurationFromConfig(state);
    this.helper = new HadoopFsHelper(state);
    this.schemaInSourceDir = state.getPropAsBoolean(ConfigurationKeys.SCHEMA_IN_SOURCE_DIR,
            ConfigurationKeys.DEFAULT_SCHEMA_IN_SOURCE_DIR);
    this.schemaFile = this.schemaInSourceDir
            ? state.getProp(ConfigurationKeys.SCHEMA_FILENAME, ConfigurationKeys.DEFAULT_SCHEMA_FILENAME)
            : "";
}

From source file:org.apache.pig.backend.hadoop.executionengine.fetch.FetchLauncher.java

License:Apache License

private void init(PhysicalPlan pp, POStore poStore) throws IOException {
    poStore.setStoreImpl(new FetchPOStoreImpl(pigContext));
    poStore.setUp();/*from w ww  .  j a v  a 2 s  .  c o  m*/

    TaskAttemptID taskAttemptID = HadoopShims.getNewTaskAttemptID();
    HadoopShims.setTaskAttemptId(conf, taskAttemptID);

    if (!PlanHelper.getPhysicalOperators(pp, POStream.class).isEmpty()) {
        MapRedUtil.setupStreamingDirsConfSingle(poStore, pigContext, conf);
    }

    String currentTime = Long.toString(System.currentTimeMillis());
    conf.set("pig.script.submitted.timestamp", currentTime);
    conf.set("pig.job.submitted.timestamp", currentTime);

    PhysicalOperator.setReporter(new FetchProgressableReporter());
    SchemaTupleBackend.initialize(conf, pigContext);

    UDFContext udfContext = UDFContext.getUDFContext();
    udfContext.addJobConf(conf);
    udfContext.setClientSystemProps(pigContext.getProperties());
    udfContext.serialize(conf);

    PigMapReduce.sJobConfInternal.set(conf);
    String dtzStr = conf.get("pig.datetime.default.tz");
    if (dtzStr != null && dtzStr.length() > 0) {
        // ensure that the internal timezone is uniformly in UTC offset style
        DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(DateTimeZone.forID(dtzStr).getOffset(null)));
    }

    boolean aggregateWarning = "true".equalsIgnoreCase(conf.get("aggregate.warning"));
    PigStatusReporter pigStatusReporter = PigStatusReporter.getInstance();
    pigStatusReporter.setContext(new FetchTaskContext(new FetchContext()));
    PigHadoopLogger pigHadoopLogger = PigHadoopLogger.getInstance();
    pigHadoopLogger.setReporter(pigStatusReporter);
    pigHadoopLogger.setAggregate(aggregateWarning);
    PhysicalOperator.setPigLogger(pigHadoopLogger);
}

From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBase.java

License:Apache License

/**
 * Configures the mapper with the map plan and the
 * reproter thread/*from  w  w w  .  ja  v  a  2 s  .  co m*/
 */
@SuppressWarnings("unchecked")
@Override
public void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);

    Configuration job = context.getConfiguration();
    SpillableMemoryManager.configure(ConfigurationUtil.toProperties(job));
    PigMapReduce.sJobContext = context;
    PigMapReduce.sJobConfInternal.set(context.getConfiguration());
    PigMapReduce.sJobConf = context.getConfiguration();
    inIllustrator = inIllustrator(context);

    PigContext
            .setPackageImportList((ArrayList<String>) ObjectSerializer.deserialize(job.get("udf.import.list")));
    pigContext = (PigContext) ObjectSerializer.deserialize(job.get("pig.pigContext"));

    // This attempts to fetch all of the generated code from the distributed cache, and resolve it
    SchemaTupleBackend.initialize(job, pigContext);

    if (pigContext.getLog4jProperties() != null)
        PropertyConfigurator.configure(pigContext.getLog4jProperties());

    if (mp == null)
        mp = (PhysicalPlan) ObjectSerializer.deserialize(job.get("pig.mapPlan"));
    stores = PlanHelper.getPhysicalOperators(mp, POStore.class);

    // To be removed
    if (mp.isEmpty())
        log.debug("Map Plan empty!");
    else {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        mp.explain(baos);
        log.debug(baos.toString());
    }
    keyType = ((byte[]) ObjectSerializer.deserialize(job.get("pig.map.keytype")))[0];
    // till here

    pigReporter = new ProgressableReporter();
    // Get the UDF specific context
    MapRedUtil.setupUDFContext(job);

    if (!(mp.isEmpty())) {

        PigSplit split = (PigSplit) context.getInputSplit();
        List<OperatorKey> targetOpKeys = split.getTargetOps();

        ArrayList<PhysicalOperator> targetOpsAsList = new ArrayList<PhysicalOperator>();
        for (OperatorKey targetKey : targetOpKeys) {
            targetOpsAsList.add(mp.getOperator(targetKey));
        }
        roots = targetOpsAsList.toArray(new PhysicalOperator[1]);
        leaf = mp.getLeaves().get(0);
    }

    PigStatusReporter pigStatusReporter = PigStatusReporter.getInstance();
    pigStatusReporter.setContext(new MRTaskContext(context));

    log.info(
            "Aliases being processed per job phase (AliasName[line,offset]): " + job.get("pig.alias.location"));

    String dtzStr = PigMapReduce.sJobConfInternal.get().get("pig.datetime.default.tz");
    if (dtzStr != null && dtzStr.length() > 0) {
        // ensure that the internal timezone is uniformly in UTC offset style
        DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(DateTimeZone.forID(dtzStr).getOffset(null)));
    }
}

From source file:org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigGenericMapBaseRollupSample.java

License:Apache License

/**
 * Configures the mapper with the map plan and the
 * reproter thread//from w w w . j  a  v  a2  s .c  o  m
 */
@SuppressWarnings("unchecked")
@Override
public void setup(Context context) throws IOException, InterruptedException {
    super.setup(context);
    Configuration job = context.getConfiguration();
    SpillableMemoryManager.configure(ConfigurationUtil.toProperties(job));
    PigMapReduce.sJobContext = context;
    PigMapReduce.sJobConfInternal.set(context.getConfiguration());
    PigMapReduce.sJobConf = context.getConfiguration();
    inIllustrator = inIllustrator(context);

    PigContext
            .setPackageImportList((ArrayList<String>) ObjectSerializer.deserialize(job.get("udf.import.list")));
    pigContext = (PigContext) ObjectSerializer.deserialize(job.get("pig.pigContext"));

    // This attempts to fetch all of the generated code from the distributed cache, and resolve it
    SchemaTupleBackend.initialize(job, pigContext);

    if (pigContext.getLog4jProperties() != null)
        PropertyConfigurator.configure(pigContext.getLog4jProperties());

    if (mp == null)
        mp = (PhysicalPlan) ObjectSerializer.deserialize(job.get("pig.mapPlan"));
    stores = PlanHelper.getPhysicalOperators(mp, POStore.class);

    // To be removed
    if (mp.isEmpty())
        log.debug("Map Plan empty!");
    else {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        mp.explain(baos);
        log.debug(baos.toString());
    }
    keyType = ((byte[]) ObjectSerializer.deserialize(job.get("pig.map.keytype")))[0];
    // till here

    pigReporter = new ProgressableReporter();
    // Get the UDF specific context
    MapRedUtil.setupUDFContext(job);

    if (!(mp.isEmpty())) {

        PigSplit split = (PigSplit) context.getInputSplit();
        List<OperatorKey> targetOpKeys = split.getTargetOps();

        ArrayList<PhysicalOperator> targetOpsAsList = new ArrayList<PhysicalOperator>();
        for (OperatorKey targetKey : targetOpKeys) {
            targetOpsAsList.add(mp.getOperator(targetKey));
        }
        roots = targetOpsAsList.toArray(new PhysicalOperator[1]);
        leaf = mp.getLeaves().get(0);
    }

    PigStatusReporter.setContext(context);

    log.info(
            "Aliases being processed per job phase (AliasName[line,offset]): " + job.get("pig.alias.location"));

    String dtzStr = PigMapReduce.sJobConfInternal.get().get("pig.datetime.default.tz");
    if (dtzStr != null && dtzStr.length() > 0) {
        // ensure that the internal timezone is uniformly in UTC offset style
        DateTimeZone.setDefault(DateTimeZone.forOffsetMillis(DateTimeZone.forID(dtzStr).getOffset(null)));
    }
}

From source file:org.apache.pig.impl.util.Utils.java

License:Apache License

public static void setDefaultTimeZone(Configuration conf) {
    String dtzStr = conf.get(PigConfiguration.PIG_DATETIME_DEFAULT_TIMEZONE);
    if (dtzStr != null && dtzStr.length() > 0) {
        // don't use offsets because it breaks across DST/Standard Time
        DateTimeZone.setDefault(DateTimeZone.forID(dtzStr));
    }//from  w  w  w  .jav  a2s .c o  m
}

From source file:org.apache.pig.piggybank.evaluation.datetime.convert.CustomFormatToISO.java

License:Apache License

@Override
public String exec(Tuple input) throws IOException {
    if (input == null || input.size() < 2) {
        return null;
    }//from  ww w .jav a 2  s. c  om

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    String date = input.get(0).toString();
    String format = input.get(1).toString();

    // See http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
    DateTimeFormatter parser = DateTimeFormat.forPattern(format);
    DateTime result;
    try {
        result = parser.parseDateTime(date);
    } catch (Exception e) {
        return null;
    }

    return result.toString();
}

From source file:org.apache.pig.piggybank.evaluation.datetime.convert.ISOToUnix.java

License:Apache License

@Override
public Long exec(Tuple input) throws IOException {
    if (input == null || input.size() < 1) {
        return null;
    }/*from ww  w . j a va 2  s.co m*/

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    DateTime result = new DateTime(input.get(0).toString());

    return result.getMillis();
}

From source file:org.apache.pig.piggybank.evaluation.datetime.convert.UnixToISO.java

License:Apache License

@Override
public String exec(Tuple input) throws IOException {
    if (input == null || input.size() < 1) {
        return null;
    }//from www  .  j  a va2s  . co  m

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    DateTime result = new DateTime(DataType.toLong(input.get(0)));

    return result.toString();
}

From source file:org.apache.pig.piggybank.evaluation.datetime.CustomFormatDiffDate.java

License:Apache License

@Override
public Long exec(Tuple input) throws IOException {
    if (input == null || input.size() != 3 || input.get(0) == null || input.get(1) == null
            || input.get(2) == null) {//from  w w  w . j av  a  2 s . co  m
        String msg = "CustomFormatDiffDate : 3 Parameters are expected (Date 1, Date 2, Date format).";
        throw new IOException(msg);
    }

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    String strDate1 = input.get(0).toString();
    String strDate2 = input.get(1).toString();
    String format = input.get(2).toString();

    DateFormat df = new SimpleDateFormat(format);

    Date date1 = null;
    Date date2 = null;
    try {
        date1 = df.parse(strDate1);
        date2 = df.parse(strDate2);
    } catch (ParseException e) {
        String msg = "DiffDate : Parameters have to be string in " + format;
        warn(msg, PigWarning.UDF_WARNING_1);
        return null;
    }
    return (long) ((date1.getTime() - date2.getTime()));
}

From source file:org.apache.pig.piggybank.evaluation.datetime.diff.ISODaysBetween.java

License:Apache License

@Override
public Long exec(Tuple input) throws IOException {
    if (input == null || input.size() < 2) {
        return null;
    }/*w  w w .ja v  a 2s  .  c om*/

    // Set the time to default or the output is in UTC
    DateTimeZone.setDefault(DateTimeZone.UTC);

    DateTime startDate = new DateTime(input.get(0).toString());
    DateTime endDate = new DateTime(input.get(1).toString());

    // Larger date first
    Days d = Days.daysBetween(endDate, startDate);
    long days = d.getDays();

    return days;

}