SQL: Move special joda time handling into DocValueExtractor (elastic/x-pack-elasticsearch#2758)
Moves joda time handling into DocValueExtractor, that's the only place where it occurs at the moment. Original commit: elastic/x-pack-elasticsearch@205e82990a
This commit is contained in:
parent
d7ab14ee54
commit
387944d176
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue