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:
Igor Motov 2017-10-22 15:54:00 +02:00 committed by GitHub
parent d7ab14ee54
commit 387944d176
2 changed files with 11 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.joda.time.ReadableInstant;
import java.io.IOException; import java.io.IOException;
@ -41,7 +42,16 @@ public class DocValueExtractor implements HitExtractor {
public Object get(SearchHit hit) { public Object get(SearchHit hit) {
// NOCOMMIT we should think about what to do with multi-valued fields. // NOCOMMIT we should think about what to do with multi-valued fields.
DocumentField field = hit.field(fieldName); 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 @Override

View File

@ -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.plugin.sql.action.SqlResponse;
import org.elasticsearch.xpack.sql.protocol.shared.SqlDataInput; import org.elasticsearch.xpack.sql.protocol.shared.SqlDataInput;
import org.elasticsearch.xpack.sql.protocol.shared.SqlDataOutput; import org.elasticsearch.xpack.sql.protocol.shared.SqlDataOutput;
import org.joda.time.ReadableInstant;
import java.io.IOException; import java.io.IOException;
import java.sql.JDBCType; import java.sql.JDBCType;
@ -44,11 +43,6 @@ class SqlResponsePayload implements Payload {
for (int c = 0; c < row.size(); c++) { for (int c = 0; c < row.size(); c++) {
JDBCType type = typeLookup.get(c); JDBCType type = typeLookup.get(c);
Object value = row.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); ProtoUtils.writeValue(out, value, type);
} }
} }