DRILL-1247: Override toString() method in Time (java.sql.Time) class to print millis
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/3da5d70b Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/3da5d70b Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/3da5d70b Branch: refs/heads/master Commit: 3da5d70bc84678416c96be95e2b3fef7e1a3a52b Parents: abaf5c4 Author: Mehant Baid <[email protected]> Authored: Thu Jul 31 19:22:06 2014 -0700 Committer: Jacques Nadeau <[email protected]> Committed: Wed Aug 6 16:44:21 2014 -0700 ---------------------------------------------------------------------- .../src/main/codegen/includes/vv_imports.ftl | 2 + .../main/codegen/templates/SqlAccessors.java | 2 +- .../vector/accessor/sql/TimePrintMillis.java | 42 ++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3da5d70b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl index 3afa20c..67c6bff 100644 --- a/exec/java-exec/src/main/codegen/includes/vv_imports.ftl +++ b/exec/java-exec/src/main/codegen/includes/vv_imports.ftl @@ -64,6 +64,8 @@ import org.joda.time.Period; import org.apache.hadoop.io.Text; +import org.apache.drill.exec.vector.accessor.sql.TimePrintMillis; + http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3da5d70b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java index a9eb3fe..701c8b8 100644 --- a/exec/java-exec/src/main/codegen/templates/SqlAccessors.java +++ b/exec/java-exec/src/main/codegen/templates/SqlAccessors.java @@ -168,7 +168,7 @@ public class ${name}Accessor extends AbstractSqlAccessor{ </#if> org.joda.time.DateTime time = new org.joda.time.DateTime(ac.get(index), org.joda.time.DateTimeZone.UTC); time = time.withZoneRetainFields(org.joda.time.DateTimeZone.getDefault()); - return new Time(time.getMillis()); + return new TimePrintMillis(time.getMillis()); } <#else> @Override http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/3da5d70b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/accessor/sql/TimePrintMillis.java ---------------------------------------------------------------------- diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/accessor/sql/TimePrintMillis.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/accessor/sql/TimePrintMillis.java new file mode 100644 index 0000000..372bd86 --- /dev/null +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/accessor/sql/TimePrintMillis.java @@ -0,0 +1,42 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.vector.accessor.sql; + +import org.apache.drill.exec.expr.fn.impl.DateUtility; + +import java.sql.Time; + + +public class TimePrintMillis extends Time { + public TimePrintMillis(long time) { + super(time); + } + + @Override + public String toString () { + int millis = (int) (getTime() % DateUtility.secondsToMillis); + String baseTime = super.toString(); + + if (millis > 0) { + baseTime = baseTime + "." + Integer.toString(millis); + } + + return baseTime; + } +} +
