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));
}
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));
}
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);
}
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())));
}
}
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;
}
Aggregations