Search in sources :

Example 1 with BitString

use of io.crate.sql.tree.BitString in project crate by crate.

the class BitStringColumnReference method value.

@Override
public BitString value() {
    try {
        if (values.advanceExact(docId)) {
            long ord = values.nextOrd();
            if (values.nextOrd() != SortedSetDocValues.NO_MORE_ORDS) {
                throw new GroupByOnArrayUnsupportedException(columnName);
            }
            var bytesRef = values.lookupOrd(ord);
            var buffer = ByteBuffer.wrap(bytesRef.bytes, bytesRef.offset, bytesRef.length);
            return new BitString(BitSet.valueOf(buffer), length);
        } else {
            return null;
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : BitString(io.crate.sql.tree.BitString) UncheckedIOException(java.io.UncheckedIOException) GroupByOnArrayUnsupportedException(io.crate.exceptions.GroupByOnArrayUnsupportedException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with BitString

use of io.crate.sql.tree.BitString in project crate by crate.

the class BitType method readBinaryValue.

@Override
public BitString readBinaryValue(ByteBuf buffer, int valueLength) {
    int bitLen = buffer.readInt();
    int byteLen = (bitLen + 7) / 8;
    byte[] bytes = new byte[byteLen];
    buffer.readBytes(bytes);
    BitSet bitSet = new BitSet();
    for (int i = 0; i < bitLen; i++) {
        int b = bytes[i / 8];
        int shift = 8 - i % 8 - 1;
        int result = (b >> shift) & 0x1;
        bitSet.set(i, result == 1);
    }
    return new BitString(bitSet, length);
}
Also used : BitString(io.crate.sql.tree.BitString) BitSet(java.util.BitSet)

Example 3 with BitString

use of io.crate.sql.tree.BitString in project crate by crate.

the class PGTypesTest method test_bit_binary_round_trip_streaming.

@Test
public void test_bit_binary_round_trip_streaming() {
    int bitLength = randomIntBetween(1, 40);
    BitStringType type = new BitStringType(bitLength);
    Supplier<BitString> dataGenerator = DataTypeTesting.getDataGenerator(type);
    PGType<?> bitType = PGTypes.get(type);
    Entry entry = new Entry(type, dataGenerator.get());
    assertThat(writeAndReadBinary(entry, bitType), is(entry.value));
}
Also used : BitString(io.crate.sql.tree.BitString) BitStringType(io.crate.types.BitStringType) Test(org.junit.Test)

Example 4 with BitString

use of io.crate.sql.tree.BitString in project crate by crate.

the class BitStringTypeTest method test_explicit_cast_can_extend_bitstring.

@Test
public void test_explicit_cast_can_extend_bitstring() throws Exception {
    BitStringType type = new BitStringType(4);
    BitString result = type.explicitCast(BitString.ofRawBits("111"));
    assertThat(result, is(BitString.ofRawBits("1110")));
}
Also used : BitString(io.crate.sql.tree.BitString) Test(org.junit.Test)

Example 5 with BitString

use of io.crate.sql.tree.BitString in project crate by crate.

the class BitStringTypeTest method test_value_streaming_roundtrip.

@Test
public void test_value_streaming_roundtrip() throws Exception {
    BitStringType type = new BitStringType(randomInt(80));
    Supplier<BitString> dataGenerator = DataTypeTesting.getDataGenerator(type);
    var value = dataGenerator.get();
    var out = new BytesStreamOutput();
    type.writeValueTo(out, value);
    StreamInput in = out.bytes().streamInput();
    assertThat(type.readValueFrom(in), is(value));
}
Also used : BitString(io.crate.sql.tree.BitString) StreamInput(org.elasticsearch.common.io.stream.StreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Aggregations

BitString (io.crate.sql.tree.BitString)9 Test (org.junit.Test)6 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)2 BitStringType (io.crate.types.BitStringType)2 Query (org.apache.lucene.search.Query)2 TermInSetQuery (org.apache.lucene.search.TermInSetQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 RowN (io.crate.data.RowN)1 GroupByOnArrayUnsupportedException (io.crate.exceptions.GroupByOnArrayUnsupportedException)1 Regclass (io.crate.types.Regclass)1 Regproc (io.crate.types.Regproc)1 TimeTZ (io.crate.types.TimeTZ)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Period (java.time.Period)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 BytesRef (org.apache.lucene.util.BytesRef)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1