use of io.crate.types.BitStringType in project crate by crate.
the class DocIndexMetadata method getColumnDataType.
/**
* extract dataType from given columnProperties
*
* @param columnProperties map of String to Object containing column properties
* @return dataType of the column with columnProperties
*/
public static DataType<?> getColumnDataType(Map<String, Object> columnProperties) {
DataType<?> type;
String typeName = (String) columnProperties.get("type");
if (typeName == null || ObjectType.NAME.equals(typeName)) {
Map<String, Object> innerProperties = (Map<String, Object>) columnProperties.get("properties");
if (innerProperties != null) {
ObjectType.Builder builder = ObjectType.builder();
for (Map.Entry<String, Object> entry : innerProperties.entrySet()) {
builder.setInnerType(entry.getKey(), getColumnDataType((Map<String, Object>) entry.getValue()));
}
type = builder.build();
} else {
type = Objects.requireNonNullElse(DataTypes.ofMappingName(typeName), DataTypes.NOT_SUPPORTED);
}
} else if (typeName.equalsIgnoreCase("array")) {
Map<String, Object> innerProperties = Maps.get(columnProperties, "inner");
DataType<?> innerType = getColumnDataType(innerProperties);
type = new ArrayType<>(innerType);
} else {
typeName = typeName.toLowerCase(Locale.ENGLISH);
switch(typeName) {
case DateFieldMapper.CONTENT_TYPE:
Boolean ignoreTimezone = (Boolean) columnProperties.get("ignore_timezone");
if (ignoreTimezone != null && ignoreTimezone) {
return DataTypes.TIMESTAMP;
} else {
return DataTypes.TIMESTAMPZ;
}
case KeywordFieldMapper.CONTENT_TYPE:
Integer lengthLimit = (Integer) columnProperties.get("length_limit");
return lengthLimit != null ? StringType.of(lengthLimit) : DataTypes.STRING;
case BitStringFieldMapper.CONTENT_TYPE:
Integer length = (Integer) columnProperties.get("length");
assert length != null : "Length is required for bit string type";
return new BitStringType(length);
default:
type = Objects.requireNonNullElse(DataTypes.ofMappingName(typeName), DataTypes.NOT_SUPPORTED);
}
}
return type;
}
use of io.crate.types.BitStringType 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.types.BitStringType 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.types.BitStringType in project crate by crate.
the class CountAggregationTest method test_count_with_bitstring_argument.
@Test
public void test_count_with_bitstring_argument() throws Exception {
BitStringType bitStringType = new BitStringType(4);
Object[][] rows = new Object[][] { { BitString.ofRawBits("0100") }, { null }, { BitString.ofRawBits("0110") } };
assertThat(executeAggregation(bitStringType, rows), is(2L));
assertHasDocValueAggregator("count", List.of(bitStringType));
}
Aggregations