Java Code Examples for io.crate.types.IntegerType#ID
The following examples show how to use
io.crate.types.IntegerType#ID .
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: GroupByMaps.java From crate with Apache License 2.0 | 6 votes |
public static <K, V> Supplier<Map<K, V>> mapForType(DataType<K> type) { switch (type.id()) { case ByteType.ID: return () -> (Map) new PrimitiveMapWithNulls<>(new ByteObjectHashMap<>()); case ShortType.ID: return () -> (Map) new PrimitiveMapWithNulls<>(new ShortObjectHashMap<>()); case IntegerType.ID: return () -> (Map) new PrimitiveMapWithNulls<>(new IntObjectHashMap<>()); case LongType.ID: case TimestampType.ID_WITH_TZ: case TimestampType.ID_WITHOUT_TZ: return () -> (Map) new PrimitiveMapWithNulls<>(new LongObjectHashMap<>()); default: return HashMap::new; } }
Example 2
Source File: SumAggregation.java From crate with Apache License 2.0 | 6 votes |
@Override public DocValueAggregator<?> getDocValueAggregator(List<DataType<?>> argumentTypes, List<MappedFieldType> fieldTypes) { switch (argumentTypes.get(0).id()) { case ShortType.ID: case IntegerType.ID: case LongType.ID: return new SumLong(fieldTypes.get(0).name()); case FloatType.ID: case DoubleType.ID: return new SumDouble(fieldTypes.get(0).name()); default: return null; } }
Example 3
Source File: AverageAggregation.java From crate with Apache License 2.0 | 6 votes |
@Override public DocValueAggregator<?> getDocValueAggregator(List<DataType<?>> argumentTypes, List<MappedFieldType> fieldTypes) { switch (argumentTypes.get(0).id()) { case ShortType.ID: case IntegerType.ID: case LongType.ID: return new AvgLong(fieldTypes.get(0).name()); case FloatType.ID: case DoubleType.ID: return new AvgDouble(fieldTypes.get(0).name()); default: return null; } }
Example 4
Source File: NegateLiterals.java From crate with Apache License 2.0 | 6 votes |
@Override public Literal visitLiteral(Literal symbol, Void context) { Object value = symbol.value(); if (value == null) { return symbol; } DataType valueType = symbol.valueType(); switch (valueType.id()) { case DoubleType.ID: return Literal.of(valueType, (Double) value * -1); case FloatType.ID: return Literal.of(valueType, (Double) value * -1); case ShortType.ID: return Literal.of(valueType, (Short) value * -1); case IntegerType.ID: return Literal.of(valueType, (Integer) value * -1); case LongType.ID: return Literal.of(valueType, (Long) value * -1); default: throw new UnsupportedOperationException(Symbols.format( "Cannot negate %s. You may need to add explicit type casts", symbol)); } }
Example 5
Source File: ArrayLengthQuery.java From crate with Apache License 2.0 | 6 votes |
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 6
Source File: NullSentinelValues.java From crate with Apache License 2.0 | 6 votes |
/** * @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 7
Source File: HyperLogLogDistinctAggregation.java From crate with Apache License 2.0 | 6 votes |
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 8
Source File: ArithmeticOperatorsFactory.java From crate with Apache License 2.0 | 5 votes |
static BiFunction getAddFunction(DataType<?> fstArgDataType, DataType<?> sndArgDataType) { switch (fstArgDataType.id()) { case LongType.ID: case TimestampType.ID_WITH_TZ: case TimestampType.ID_WITHOUT_TZ: if (IntervalType.ID == sndArgDataType.id()) { var signature = IntervalTimestampArithmeticScalar.signatureFor( fstArgDataType, ArithmeticFunctions.Names.ADD ); return new IntervalTimestampArithmeticScalar( "+", signature, signature ); } return ADD_LONG_FUNCTION; case DoubleType.ID: return ADD_DOUBLE_FUNCTION; case FloatType.ID: return ADD_FLOAT_FUNCTION; case ByteType.ID: case ShortType.ID: case IntegerType.ID: return ADD_INTEGER_FUNCTION; default: throw new UnsupportedOperationException( "Cannot create add function for data type " + fstArgDataType.getName()); } }
Example 9
Source File: ArithmeticOperatorsFactory.java From crate with Apache License 2.0 | 5 votes |
static BiFunction getSubtractFunction(DataType<?> fstArgDataType, DataType<?> sndArgDataType) { switch (fstArgDataType.id()) { case LongType.ID: case TimestampType.ID_WITH_TZ: case TimestampType.ID_WITHOUT_TZ: if (IntervalType.ID == sndArgDataType.id()) { var signature = IntervalTimestampArithmeticScalar.signatureFor( fstArgDataType, ArithmeticFunctions.Names.SUBTRACT ); return new IntervalTimestampArithmeticScalar( "-", signature, signature ); } return SUB_LONG_FUNCTION; case DoubleType.ID: return SUB_DOUBLE_FUNCTION; case FloatType.ID: return SUB_FLOAT_FUNCTION; case ByteType.ID: case ShortType.ID: case IntegerType.ID: return SUB_INTEGER_FUNCTION; default: throw new UnsupportedOperationException( "Cannot create subtract function for data type " + fstArgDataType.getName()); } }
Example 10
Source File: NullSentinelValues.java From crate with Apache License 2.0 | 5 votes |
/** * Similar to {@link #nullSentinelForScoreDoc(DataType, boolean, Boolean)} * but returns a value that is compatible with the value type of the given DataType. */ @Nullable public static Object nullSentinel(DataType<?> dataType, NullValueOrder nullValueOrder, boolean reversed) { boolean min = nullValueOrder == NullValueOrder.FIRST ^ reversed; switch (dataType.id()) { case ByteType.ID: return min ? Byte.MIN_VALUE : Byte.MAX_VALUE; case ShortType.ID: return min ? Short.MIN_VALUE : Short.MAX_VALUE; case IntegerType.ID: return min ? Integer.MIN_VALUE : Integer.MAX_VALUE; 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 11
Source File: LuceneReferenceResolver.java From crate with Apache License 2.0 | 5 votes |
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 12
Source File: DataTypeTesting.java From crate with Apache License 2.0 | 4 votes |
@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()); }