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);
}
}
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);
}
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));
}
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")));
}
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));
}
Aggregations