io.crate.types.BooleanType Java Examples

The following examples show how to use io.crate.types.BooleanType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StmtExecutor.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static PrimitiveType getPrimitiveTypeFromESType(DataType t) {
    if (t.getName().equals(StringType.INSTANCE.getName())) {
        return PrimitiveType.STRING;
    } else if (t.getName().equals(BooleanType.INSTANCE.getName())) {
        return PrimitiveType.BOOL;
    } else if (t.getName().equals(ByteType.INSTANCE.getName())) {
        return PrimitiveType.BYTE;
    } else if (t.getName().equals(DoubleType.INSTANCE.getName())) {
        return PrimitiveType.DOUBLE;
    } else if (t.getName().equals(FloatType.INSTANCE.getName())) {
        return PrimitiveType.FLOAT;
    } else if (t.getName().equals(IntegerType.INSTANCE.getName())) {
        return PrimitiveType.INT;
    } else if (t.getName().equals(LongType.INSTANCE.getName())) {
        return PrimitiveType.LONG;
    } else if (t.getName().equals(ShortType.INSTANCE.getName())) {
        return PrimitiveType.SHORT;
    } else if (t.getName().equals(TimestampType.INSTANCE.getName())) {
        return PrimitiveType.TIMESTAMP;
    }
    return PrimitiveType.STRING;
}
 
Example #2
Source File: CrateDocumentConverterTest.java    From spring-data-crate with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldMapSimpleTypes() {
	
	String[] columns = {"string", "integer", "bool", "locale"};
	
	DataType<?>[] types = { StringType.INSTANCE, IntegerType.INSTANCE, 
						    BooleanType.INSTANCE, StringType.INSTANCE };
	
	Object[] row = new Object[]{"DOCUMENT", 1, true, CANADA};
	
	Map<String, Object> expected = new HashMap<String, Object>();
	expected.put("string", "DOCUMENT");
	expected.put("integer", 1);
	expected.put("bool", true);
	expected.put("locale", CANADA);
	
	converter = new CrateDocumentConverter(columns, types, row);
	
	CrateDocument document = converter.toDocument();
	
	assertThat(document, is(notNullValue()));
	assertThat(document.equals(expected), is(true));
}
 
Example #3
Source File: ArrayLengthQuery.java    From crate with Apache License 2.0 6 votes vote down vote up
private static IntUnaryOperator getNumTermsPerDocFunction(LeafReader reader, Reference ref) {
    DataType elementType = ArrayType.unnest(ref.valueType());
    switch (elementType.id()) {
        case BooleanType.ID:
        case ByteType.ID:
        case ShortType.ID:
        case IntegerType.ID:
        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
        case FloatType.ID:
        case DoubleType.ID:
        case GeoPointType.ID:
            return numValuesPerDocForSortedNumeric(reader, ref.column());

        case StringType.ID:
            return numValuesPerDocForString(reader, ref.column());

        case IpType.ID:
            return numValuesPerDocForIP(reader, ref.column());

        default:
            throw new UnsupportedOperationException("NYI: " + elementType);
    }
}
 
Example #4
Source File: NullSentinelValues.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * @return a sentinel value that is used to indicate a `null` value.
 *         The returned value here is **not** necessarily compatible with the value type of the given `type`.
 *         This can be used for in places where {@link org.apache.lucene.search.ScoreDoc} is used,
 *         which for example uses LONG also for columns of type INTEGER.
 */
public static Object nullSentinelForScoreDoc(DataType<?> type, boolean reverseFlag, Boolean nullFirst) {
    boolean min = reverseFlag ^ (nullFirst != null ? nullFirst : reverseFlag);
    switch (type.id()) {
        case ByteType.ID:
        case ShortType.ID:
        case IntegerType.ID:
        case BooleanType.ID:
        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return min ? Long.MIN_VALUE : Long.MAX_VALUE;

        case FloatType.ID:
            return min ? Float.NEGATIVE_INFINITY : Float.POSITIVE_INFINITY;

        case DoubleType.ID:
            return min ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;

        default:
            return null;
    }
}
 
Example #5
Source File: LiteralTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testNestedArrayLiteral() throws Exception {
    for (DataType<?> type : DataTypes.PRIMITIVE_TYPES) {
        DataType<?> nestedType = new ArrayType<>(new ArrayType<>(type));
        Object value;

        if (type.id() == BooleanType.ID) {
            value = true;
        } else if (type.id() == DataTypes.IP.id()) {
            value = type.value("123.34.243.23");
        } else if (type.id() == DataTypes.INTERVAL.id()) {
            value = type.value(new Period().withSeconds(100));
        } else {
            value = type.value("0");
        }
        var nestedValue = List.of(List.of(value));
        Literal nestedLiteral = Literal.ofUnchecked(nestedType, nestedValue);
        assertThat(nestedLiteral.valueType(), is(nestedType));
        assertThat(nestedLiteral.value(), is(nestedValue));
    }
}
 
Example #6
Source File: HyperLogLogDistinctAggregation.java    From crate with Apache License 2.0 6 votes vote down vote up
static Murmur3Hash getForType(DataType<?> dataType, boolean allOn4_1) {
    switch (dataType.id()) {
        case DoubleType.ID:
        case FloatType.ID:
            return Double.INSTANCE;
        case LongType.ID:
        case IntegerType.ID:
        case ShortType.ID:
        case ByteType.ID:
        case TimestampType.ID_WITH_TZ:
            return Long.INSTANCE;
        case StringType.ID:
        case BooleanType.ID:
        case IpType.ID:
            if (allOn4_1) {
                return Bytes64.INSTANCE;
            } else {
                return new Bytes();
            }
        default:
            throw new IllegalArgumentException("data type \"" + dataType + "\" is not supported");
    }
}
 
Example #7
Source File: AnyOperator.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public FunctionImplementation<Function> getForTypes(List<DataType> dataTypes) throws IllegalArgumentException {
    checkArgument(dataTypes.size() == 2, "ANY operator requires exactly 2 arguments");
    checkArgument(DataTypes.isCollectionType(dataTypes.get(1)), "The second argument to ANY must be an array or set");
    checkArgument(((CollectionType) dataTypes.get(1)).innerType().equals(dataTypes.get(0)),
            "The inner type of the array/set passed to ANY must match its left expression");
    return newInstance(new FunctionInfo(new FunctionIdent(name(), dataTypes), BooleanType.INSTANCE));
}
 
Example #8
Source File: LuceneReferenceResolver.java    From crate with Apache License 2.0 5 votes vote down vote up
private static LuceneCollectorExpression<?> typeSpecializedExpression(final FieldTypeLookup fieldTypeLookup, final Reference ref) {
    final String fqn = ref.column().fqn();
    final MappedFieldType fieldType = fieldTypeLookup.get(fqn);
    if (fieldType == null) {
        return NO_FIELD_TYPES_IDS.contains(unnest(ref.valueType()).id()) || isIgnoredDynamicReference(ref)
            ? DocCollectorExpression.create(toSourceLookup(ref))
            : new NullValueCollectorExpression();
    }
    if (!fieldType.hasDocValues()) {
        return DocCollectorExpression.create(toSourceLookup(ref));
    }
    switch (ref.valueType().id()) {
        case ByteType.ID:
            return new ByteColumnReference(fqn);
        case ShortType.ID:
            return new ShortColumnReference(fqn);
        case IpType.ID:
            return new IpColumnReference(fqn);
        case StringType.ID:
            return new BytesRefColumnReference(fqn);
        case DoubleType.ID:
            return new DoubleColumnReference(fqn);
        case BooleanType.ID:
            return new BooleanColumnReference(fqn);
        case FloatType.ID:
            return new FloatColumnReference(fqn);
        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return new LongColumnReference(fqn);
        case IntegerType.ID:
            return new IntegerColumnReference(fqn);
        case GeoPointType.ID:
            return new GeoPointColumnReference(fqn);
        case ArrayType.ID:
            return DocCollectorExpression.create(toSourceLookup(ref));
        default:
            throw new UnhandledServerException("Unsupported type: " + ref.valueType().getName());
    }
}
 
Example #9
Source File: SettingsAppliers.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
protected Object validate(Object value) {
    return BooleanType.INSTANCE.value(value);
}
 
Example #10
Source File: MatchPredicate.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public BooleanType valueType() {
    return DataTypes.BOOLEAN;
}
 
Example #11
Source File: DataTypeTesting.java    From crate with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> Supplier<T> getDataGenerator(DataType<T> type) {
    Random random = RandomizedContext.current().getRandom();
    switch (type.id()) {
        case ByteType.ID:
            return () -> (T) (Byte) (byte) random.nextInt(Byte.MAX_VALUE);
        case BooleanType.ID:
            return () -> (T) (Boolean) random.nextBoolean();

        case StringType.ID:
            return () -> (T) RandomizedTest.randomAsciiLettersOfLength(random.nextInt(10));

        case IpType.ID:
            return () -> {
                if (random.nextBoolean()) {
                    return (T) randomIPv4Address(random);
                } else {
                    return (T) randomIPv6Address(random);
                }
            };

        case DoubleType.ID:
            return () -> (T) (Double) random.nextDouble();

        case FloatType.ID:
            return () -> (T) (Float) random.nextFloat();

        case ShortType.ID:
            return () -> (T) (Short) (short) random.nextInt(Short.MAX_VALUE);

        case IntegerType.ID:
            return () -> (T) (Integer) random.nextInt();

        case LongType.ID:
        case TimestampType.ID_WITH_TZ:
        case TimestampType.ID_WITHOUT_TZ:
            return () -> (T) (Long) random.nextLong();

        case GeoPointType.ID:
            return () -> (T) new PointImpl(
                BiasedNumbers.randomDoubleBetween(random, -180, 180),
                BiasedNumbers.randomDoubleBetween(random, -90, 90),
                JtsSpatialContext.GEO
            );

        case GeoShapeType.ID:
            return () -> {
                // Can't use immutable Collections.singletonMap; insert-analyzer mutates the map
                Map<String, Object> geoShape = new HashMap<>(2);
                geoShape.put("coordinates", Arrays.asList(10.2d, 32.2d));
                geoShape.put("type", "Point");
                return (T) geoShape;
            };

        case ObjectType.ID:
            Supplier<?> innerValueGenerator = getDataGenerator(randomType());
            return () -> {
                // Can't use immutable Collections.singletonMap; insert-analyzer mutates the map
                HashMap<String, Object> map = new HashMap<>();
                map.put("x", innerValueGenerator.get());
                return (T) map;
            };
        case IntervalType.ID:
            return () -> {
                return (T) new Period().withSeconds(RandomNumbers.randomIntBetween(random, 0, Integer.MAX_VALUE));
            };

    }

    throw new AssertionError("No data generator for type " + type.getName());
}