Search in sources :

Example 1 with Regclass

use of io.crate.types.Regclass in project crate by crate.

the class ServerXContentExtension method getXContentWriters.

@Override
public Map<Class<?>, XContentBuilder.Writer> getXContentWriters() {
    Map<Class<?>, XContentBuilder.Writer> writers = new HashMap<>();
    // Fully-qualified here to reduce ambiguity around our (ES') Version class
    writers.put(org.apache.lucene.util.Version.class, (b, v) -> b.value(Objects.toString(v)));
    writers.put(DateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
    writers.put(CachedDateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
    writers.put(FixedDateTimeZone.class, (b, v) -> b.value(Objects.toString(v)));
    writers.put(MutableDateTime.class, XContentBuilder::timeValue);
    writers.put(DateTime.class, XContentBuilder::timeValue);
    writers.put(TimeValue.class, (b, v) -> b.value(v.toString()));
    writers.put(ZonedDateTime.class, XContentBuilder::timeValue);
    writers.put(OffsetDateTime.class, XContentBuilder::timeValue);
    writers.put(OffsetTime.class, XContentBuilder::timeValue);
    writers.put(java.time.Instant.class, XContentBuilder::timeValue);
    writers.put(LocalDateTime.class, XContentBuilder::timeValue);
    writers.put(LocalDate.class, XContentBuilder::timeValue);
    writers.put(LocalTime.class, XContentBuilder::timeValue);
    writers.put(DayOfWeek.class, (b, v) -> b.value(v.toString()));
    writers.put(Month.class, (b, v) -> b.value(v.toString()));
    writers.put(MonthDay.class, (b, v) -> b.value(v.toString()));
    writers.put(Year.class, (b, v) -> b.value(v.toString()));
    writers.put(Duration.class, (b, v) -> b.value(v.toString()));
    writers.put(Period.class, (b, v) -> b.value(v.toString()));
    writers.put(org.joda.time.Period.class, (b, v) -> {
        org.joda.time.Period period = (org.joda.time.Period) v;
        b.value(IntervalType.PERIOD_FORMATTER.print(period));
    });
    writers.put(BytesReference.class, (b, v) -> {
        if (v == null) {
            b.nullValue();
        } else {
            BytesRef bytes = ((BytesReference) v).toBytesRef();
            b.value(bytes.bytes, bytes.offset, bytes.length);
        }
    });
    writers.put(BytesRef.class, (b, v) -> {
        if (v == null) {
            b.nullValue();
        } else {
            BytesRef bytes = (BytesRef) v;
            b.value(bytes.bytes, bytes.offset, bytes.length);
        }
    });
    writers.put(Regproc.class, (b, v) -> b.value(((Regproc) v).name()));
    writers.put(Regclass.class, (b, v) -> b.value(((Regclass) v).oid()));
    writers.put(PointImpl.class, (b, v) -> {
        Point point = (Point) v;
        b.startArray();
        b.value(point.getX());
        b.value(point.getY());
        b.endArray();
    });
    writers.put(JtsPoint.class, (b, v) -> {
        Point point = (Point) v;
        b.startArray();
        b.value(point.getX());
        b.value(point.getY());
        b.endArray();
    });
    writers.put(RowN.class, (b, v) -> {
        RowN row = (RowN) v;
        b.startArray();
        for (int i = 0; i < row.numColumns(); i++) {
            b.value(row.get(i));
        }
        b.endArray();
    });
    writers.put(TimeTZ.class, (b, v) -> {
        TimeTZ timetz = (TimeTZ) v;
        b.startArray();
        b.value(timetz.getMicrosFromMidnight());
        b.value(timetz.getSecondsFromUTC());
        b.endArray();
    });
    writers.put(BitString.class, (b, v) -> {
        BitString bitString = (BitString) v;
        b.value(bitString.asBitString());
    });
    return writers;
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) TimeTZ(io.crate.types.TimeTZ) HashMap(java.util.HashMap) Period(java.time.Period) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.spatial4j.shape.Point) JtsPoint(org.locationtech.spatial4j.shape.jts.JtsPoint) Point(org.locationtech.spatial4j.shape.Point) Regproc(io.crate.types.Regproc) RowN(io.crate.data.RowN) BitString(io.crate.sql.tree.BitString) Regclass(io.crate.types.Regclass) BytesRef(org.apache.lucene.util.BytesRef)

Aggregations

RowN (io.crate.data.RowN)1 BitString (io.crate.sql.tree.BitString)1 Regclass (io.crate.types.Regclass)1 Regproc (io.crate.types.Regproc)1 TimeTZ (io.crate.types.TimeTZ)1 Period (java.time.Period)1 HashMap (java.util.HashMap)1 BytesRef (org.apache.lucene.util.BytesRef)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 Point (org.locationtech.spatial4j.shape.Point)1 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)1