Search in sources :

Example 1 with CronBuilder

use of com.cronutils.builder.CronBuilder in project hive by apache.

the class ScheduledQueryAnalyzer method getDefaultCronBuilder.

private CronBuilder getDefaultCronBuilder() {
    CronDefinition definition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
    CronBuilder b = CronBuilder.cron(definition).withYear(always()).withDoM(always()).withMonth(always()).withDoW(questionMark()).withHour(always()).withMinute(always()).withMinute(always()).withSecond(always());
    return b;
}
Also used : CronBuilder(com.cronutils.builder.CronBuilder) CronDefinition(com.cronutils.model.definition.CronDefinition)

Example 2 with CronBuilder

use of com.cronutils.builder.CronBuilder in project hive by apache.

the class ScheduledQueryAnalyzer method interpretEveryNode.

private String interpretEveryNode(int every, int intervalToken, Timestamp ts) throws SemanticException {
    CronBuilder b = getDefaultCronBuilder();
    switch(intervalToken) {
        case HiveParser.TOK_INTERVAL_DAY_LITERAL:
            if (every != 1) {
                throw new SemanticException("EVERY " + every + " DAY is not supported; only EVERY DAY is supported");
            }
            b.withSecond(on(ts.getSeconds()));
            b.withMinute(on(ts.getMinutes()));
            b.withHour(on(ts.getHours()));
            break;
        case HiveParser.TOK_INTERVAL_HOUR_LITERAL:
            b.withSecond(on(ts.getSeconds()));
            b.withMinute(on(ts.getMinutes()));
            b.withHour(every(on0(ts.getHours()), every));
            break;
        case HiveParser.TOK_INTERVAL_MINUTE_LITERAL:
            b.withSecond(on(ts.getSeconds()));
            b.withMinute(every(on0(ts.getMinutes()), every));
            break;
        case HiveParser.TOK_INTERVAL_SECOND_LITERAL:
            b.withSecond(every(on0(ts.getSeconds()), every));
            break;
        default:
            throw new SemanticException("not supported schedule interval(only HOUR/MINUTE/SECOND is supported)");
    }
    return b.instance().asString();
}
Also used : CronBuilder(com.cronutils.builder.CronBuilder)

Aggregations

CronBuilder (com.cronutils.builder.CronBuilder)2 CronDefinition (com.cronutils.model.definition.CronDefinition)1