Search in sources :

Example 41 with DateTime

use of org.joda.time.DateTime in project presto by prestodb.

the class TestDateTimeFunctions method testFromUnixTimeWithOffset.

@Test
public void testFromUnixTimeWithOffset() {
    DateTime dateTime = new DateTime(2001, 1, 22, 3, 4, 5, 0, DATE_TIME_ZONE);
    double seconds = dateTime.getMillis() / 1000.0;
    int timeZoneHoursOffset = 1;
    int timezoneMinutesOffset = 10;
    DateTime expected = new DateTime(dateTime, getDateTimeZone(getTimeZoneKeyForOffset((timeZoneHoursOffset * 60L) + timezoneMinutesOffset)));
    assertFunction("from_unixtime(" + seconds + ", " + timeZoneHoursOffset + ", " + timezoneMinutesOffset + ")", TIMESTAMP_WITH_TIME_ZONE, toTimestampWithTimeZone(expected));
}
Also used : DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 42 with DateTime

use of org.joda.time.DateTime in project presto by prestodb.

the class TestDateTimeFunctions method testTruncateDate.

@Test
public void testTruncateDate() {
    DateTime result = DATE;
    assertFunction("date_trunc('day', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
    result = result.withDayOfMonth(20);
    assertFunction("date_trunc('week', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
    result = result.withDayOfMonth(1);
    assertFunction("date_trunc('month', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
    result = result.withMonthOfYear(7);
    assertFunction("date_trunc('quarter', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
    result = result.withMonthOfYear(1);
    assertFunction("date_trunc('year', " + DATE_LITERAL + ")", DateType.DATE, toDate(result));
}
Also used : DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 43 with DateTime

use of org.joda.time.DateTime in project presto by prestodb.

the class TestQueryStats method assertExpectedQueryStats.

public static void assertExpectedQueryStats(QueryStats actual) {
    assertEquals(actual.getCreateTime(), new DateTime(1, UTC));
    assertEquals(actual.getExecutionStartTime(), new DateTime(2, UTC));
    assertEquals(actual.getLastHeartbeat(), new DateTime(3, UTC));
    assertEquals(actual.getEndTime(), new DateTime(4, UTC));
    assertEquals(actual.getElapsedTime(), new Duration(6, NANOSECONDS));
    assertEquals(actual.getQueuedTime(), new Duration(5, NANOSECONDS));
    assertEquals(actual.getExecutionTime(), new Duration(1, NANOSECONDS));
    assertEquals(actual.getAnalysisTime(), new Duration(7, NANOSECONDS));
    assertEquals(actual.getDistributedPlanningTime(), new Duration(8, NANOSECONDS));
    assertEquals(actual.getTotalPlanningTime(), new Duration(100, NANOSECONDS));
    assertEquals(actual.getFinishingTime(), new Duration(200, NANOSECONDS));
    assertEquals(actual.getTotalTasks(), 9);
    assertEquals(actual.getRunningTasks(), 10);
    assertEquals(actual.getCompletedTasks(), 11);
    assertEquals(actual.getTotalDrivers(), 12);
    assertEquals(actual.getQueuedDrivers(), 13);
    assertEquals(actual.getRunningDrivers(), 15);
    assertEquals(actual.getCompletedDrivers(), 16);
    assertEquals(actual.getCumulativeMemory(), 17.0);
    assertEquals(actual.getTotalMemoryReservation(), new DataSize(18, BYTE));
    assertEquals(actual.getPeakMemoryReservation(), new DataSize(19, BYTE));
    assertEquals(actual.getTotalScheduledTime(), new Duration(20, NANOSECONDS));
    assertEquals(actual.getTotalCpuTime(), new Duration(21, NANOSECONDS));
    assertEquals(actual.getTotalUserTime(), new Duration(22, NANOSECONDS));
    assertEquals(actual.getTotalBlockedTime(), new Duration(23, NANOSECONDS));
    assertEquals(actual.getRawInputDataSize(), new DataSize(24, BYTE));
    assertEquals(actual.getRawInputPositions(), 25);
    assertEquals(actual.getProcessedInputDataSize(), new DataSize(26, BYTE));
    assertEquals(actual.getProcessedInputPositions(), 27);
    assertEquals(actual.getOutputDataSize(), new DataSize(28, BYTE));
    assertEquals(actual.getOutputPositions(), 29);
}
Also used : DataSize(io.airlift.units.DataSize) Duration(io.airlift.units.Duration) DateTime(org.joda.time.DateTime)

Example 44 with DateTime

use of org.joda.time.DateTime in project presto by prestodb.

the class TestQueryIdGenerator method testCreateNextQueryId.

@Test
public void testCreateNextQueryId() throws Exception {
    TestIdGenerator idGenerator = new TestIdGenerator();
    long millis = new DateTime(2001, 7, 14, 1, 2, 3, 4, DateTimeZone.UTC).getMillis();
    idGenerator.setNow(millis);
    // generate ids to 99,999
    for (int i = 0; i < 100_000; i++) {
        assertEquals(idGenerator.createNextQueryId(), new QueryId(String.format("20010714_010203_%05d_%s", i, idGenerator.getCoordinatorId())));
    }
    // next id will cause counter to roll, but we need to add a second to the time or code will block for ever
    millis += 1000;
    idGenerator.setNow(millis);
    for (int i = 0; i < 100_000; i++) {
        assertEquals(idGenerator.createNextQueryId(), new QueryId(String.format("20010714_010204_%05d_%s", i, idGenerator.getCoordinatorId())));
    }
    // more forward one more second and generate 100 ids
    millis += 1000;
    idGenerator.setNow(millis);
    for (int i = 0; i < 100; i++) {
        assertEquals(idGenerator.createNextQueryId(), new QueryId(String.format("20010714_010205_%05d_%s", i, idGenerator.getCoordinatorId())));
    }
    // now we move to the start of the next day, and the counter should reset
    millis = new DateTime(2001, 7, 15, 0, 0, 0, 0, DateTimeZone.UTC).getMillis();
    idGenerator.setNow(millis);
    for (int i = 0; i < 100_000; i++) {
        assertEquals(idGenerator.createNextQueryId(), new QueryId(String.format("20010715_000000_%05d_%s", i, idGenerator.getCoordinatorId())));
    }
}
Also used : QueryId(com.facebook.presto.spi.QueryId) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 45 with DateTime

use of org.joda.time.DateTime in project h2o-3 by h2oai.

the class Model method toJava.

protected SBPrintStream toJava(SBPrintStream sb, boolean isGeneratingPreview, boolean verboseCode) {
    // preserve file context
    CodeGeneratorPipeline fileCtx = new CodeGeneratorPipeline();
    String modelName = JCodeGen.toJavaId(_key.toString());
    // HEADER
    sb.p("/*").nl();
    sb.p("  Licensed under the Apache License, Version 2.0").nl();
    sb.p("    http://www.apache.org/licenses/LICENSE-2.0.html").nl();
    sb.nl();
    sb.p("  AUTOGENERATED BY H2O at ").p(new DateTime().toString()).nl();
    sb.p("  ").p(H2O.ABV.projectVersion()).nl();
    sb.p("  ").nl();
    sb.p("  Standalone prediction code with sample test data for ").p(this.getClass().getSimpleName()).p(" named ").p(modelName).nl();
    sb.nl();
    sb.p("  How to download, compile and execute:").nl();
    sb.p("      mkdir tmpdir").nl();
    sb.p("      cd tmpdir").nl();
    sb.p("      curl http:/").p(H2O.SELF.toString()).p("/3/h2o-genmodel.jar > h2o-genmodel.jar").nl();
    sb.p("      curl http:/").p(H2O.SELF.toString()).p("/3/Models.java/").pobj(_key).p(" > ").p(modelName).p(".java").nl();
    sb.p("      javac -cp h2o-genmodel.jar -J-Xmx2g -J-XX:MaxPermSize=128m ").p(modelName).p(".java").nl();
    // Intentionally disabled since there is no main method in generated code
    // sb.p("//     java -cp h2o-genmodel.jar:. -Xmx2g -XX:MaxPermSize=256m -XX:ReservedCodeCacheSize=256m ").p(modelName).nl();
    sb.nl();
    sb.p("     (Note:  Try java argument -XX:+PrintCompilation to show runtime JIT compiler behavior.)").nl();
    if (_parms._offset_column != null) {
        sb.nl();
        sb.nl();
        sb.nl();
        sb.p("  NOTE:  Java model export does not support offset_column.").nl();
        sb.nl();
        Log.warn("Java model export does not support offset_column.");
    }
    if (isGeneratingPreview && toJavaCheckTooBig()) {
        sb.nl();
        sb.nl();
        sb.nl();
        sb.p("  NOTE:  Java model is too large to preview, please download as shown above.").nl();
        sb.nl();
        return sb;
    }
    sb.p("*/").nl();
    sb.p("import java.util.Map;").nl();
    sb.p("import hex.genmodel.GenModel;").nl();
    sb.p("import hex.genmodel.annotations.ModelPojo;").nl();
    sb.nl();
    String algo = this.getClass().getSimpleName().toLowerCase().replace("model", "");
    sb.p("@ModelPojo(name=\"").p(modelName).p("\", algorithm=\"").p(algo).p("\")").nl();
    sb.p("public class ").p(modelName).p(" extends GenModel {").nl().ii(1);
    sb.ip("public hex.ModelCategory getModelCategory() { return hex.ModelCategory." + _output.getModelCategory() + "; }").nl();
    toJavaInit(sb, fileCtx).nl();
    toJavaNAMES(sb, fileCtx);
    toJavaNCLASSES(sb);
    toJavaDOMAINS(sb, fileCtx);
    toJavaPROB(sb);
    //
    toJavaSuper(modelName, sb);
    sb.p("  public String getUUID() { return Long.toString(" + checksum() + "L); }").nl();
    toJavaPredict(sb, fileCtx, verboseCode);
    sb.p("}").nl().di(1);
    // Append file context
    fileCtx.generate(sb);
    sb.nl();
    return sb;
}
Also used : CodeGeneratorPipeline(water.codegen.CodeGeneratorPipeline) BufferedString(water.parser.BufferedString) DateTime(org.joda.time.DateTime)

Aggregations

DateTime (org.joda.time.DateTime)3596 Test (org.junit.Test)1091 Test (org.testng.annotations.Test)499 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)349 ResponseBody (okhttp3.ResponseBody)332 ArrayList (java.util.ArrayList)322 LocalDate (org.joda.time.LocalDate)257 Date (java.util.Date)246 Interval (org.joda.time.Interval)204 Result (io.druid.query.Result)153 HashMap (java.util.HashMap)149 ServiceCall (com.microsoft.rest.ServiceCall)148 List (java.util.List)137 BigDecimal (java.math.BigDecimal)132 DateTimeZone (org.joda.time.DateTimeZone)129 UUID (java.util.UUID)104 LocalDateTime (org.joda.time.LocalDateTime)103 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)95 IOException (java.io.IOException)94 Map (java.util.Map)90