diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/extractor/DocValueExtractor.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/extractor/DocValueExtractor.java index 11ec2266bfe..7e1c90bd748 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/extractor/DocValueExtractor.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/extractor/DocValueExtractor.java @@ -9,6 +9,7 @@ import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.search.SearchHit; +import org.joda.time.ReadableInstant; import java.io.IOException; @@ -41,7 +42,16 @@ public class DocValueExtractor implements HitExtractor { public Object get(SearchHit hit) { // NOCOMMIT we should think about what to do with multi-valued fields. DocumentField field = hit.field(fieldName); - return field != null ? field.getValue() : null; + if (field != null) { + Object value = field.getValue(); + if (value != null && value instanceof ReadableInstant) { + return ((ReadableInstant) value).getMillis(); + } else { + return value; + } + } else { + return null; + } } @Override diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlResponsePayload.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlResponsePayload.java index 4ae68da490e..3dfdeab4eb3 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlResponsePayload.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlResponsePayload.java @@ -10,7 +10,6 @@ import org.elasticsearch.xpack.sql.jdbc.net.protocol.ProtoUtils; import org.elasticsearch.xpack.sql.plugin.sql.action.SqlResponse; import org.elasticsearch.xpack.sql.protocol.shared.SqlDataInput; import org.elasticsearch.xpack.sql.protocol.shared.SqlDataOutput; -import org.joda.time.ReadableInstant; import java.io.IOException; import java.sql.JDBCType; @@ -44,11 +43,6 @@ class SqlResponsePayload implements Payload { for (int c = 0; c < row.size(); c++) { JDBCType type = typeLookup.get(c); Object value = row.get(c); - // unpack Joda classes on the server-side to not 'pollute' the common project and thus the client - if (type == JDBCType.TIMESTAMP && value instanceof ReadableInstant) { - // NOCOMMIT feels like a hack that'd be better cleaned up another way. - value = ((ReadableInstant) value).getMillis(); - } ProtoUtils.writeValue(out, value, type); } }