use of io.crate.sql.tree.BitString in project crate by crate.
the class BitStringQueryTest method test_eq_any_on_bits_uses_termset_query.
@Test
public void test_eq_any_on_bits_uses_termset_query() throws Exception {
var builder = builder("create table tbl (bits bit(8))");
BitString bits1 = BitString.ofRawBits("00010110");
BitString bits2 = BitString.ofRawBits("01110000");
builder.indexValues("bits", bits1, bits2);
try (var tester = builder.build()) {
Query query = tester.toQuery("bits = ANY([B'01001110', B'11111111'])");
assertThat(query, instanceOf(TermInSetQuery.class));
assertThat(query.toString(), is("bits:(r [ff])"));
List<Object> result = tester.runQuery("bits", "bits = ANY([B'01001110', B'11111111'])");
assertThat(result, Matchers.empty());
result = tester.runQuery("bits", "bits = ANY([B'00010110', B'11111111'])");
assertThat(result, Matchers.contains(bits1));
result = tester.runQuery("bits", "bits = ANY([B'00010110', B'01110000'])");
assertThat(result, Matchers.contains(bits1, bits2));
}
}
use of io.crate.sql.tree.BitString in project crate by crate.
the class BitStringQueryTest method test_eq_on_bits_uses_term_query.
@Test
public void test_eq_on_bits_uses_term_query() throws Exception {
var builder = builder("create table tbl (bits bit(8))");
BitStringType bitStringType = new BitStringType(8);
Supplier<BitString> dataGenerator = DataTypeTesting.getDataGenerator(bitStringType);
BitString bits1 = dataGenerator.get();
BitString bitsNoMatch = dataGenerator.get();
while (bits1.equals(bitsNoMatch)) {
bitsNoMatch = dataGenerator.get();
}
builder.indexValues("bits", bits1);
try (var tester = builder.build()) {
Query query = tester.toQuery("bits = ?", bits1);
assertThat(query, instanceOf(TermQuery.class));
assertThat(tester.runQuery("bits", "bits = ?", bits1), Matchers.contains(bits1));
assertThat(tester.runQuery("bits", "bits = ?", bitsNoMatch), Matchers.empty());
}
}
use of io.crate.sql.tree.BitString in project crate by crate.
the class BitStringTypeTest method test_explicit_cast_can_trim_bitstring.
@Test
public void test_explicit_cast_can_trim_bitstring() throws Exception {
BitStringType type = new BitStringType(3);
BitString result = type.explicitCast(BitString.ofRawBits("1111"));
assertThat(result, is(BitString.ofRawBits("111")));
}
use of io.crate.sql.tree.BitString 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;
}
Aggregations