@Override public boolean isComparable() { return valueType.isComparable(); }
@Override public boolean isComparable() { return elementType.isComparable(); }
@Override public boolean isComparable() { return fields.stream().allMatch(field -> field.getType().isComparable()); }
@JsonCreator public EquatableValueSet( @JsonProperty("type") Type type, @JsonProperty("whiteList") boolean whiteList, @JsonProperty("entries") Set<ValueEntry> entries) { requireNonNull(type, "type is null"); requireNonNull(entries, "entries is null"); if (!type.isComparable()) { throw new IllegalArgumentException("Type is not comparable: " + type); } if (type.isOrderable()) { throw new IllegalArgumentException("Use SortedRangeSet instead"); } this.type = type; this.whiteList = whiteList; this.entries = Collections.unmodifiableSet(new HashSet<>(entries)); }
static ValueSet copyOf(Type type, Collection<Object> values) { if (type.isOrderable()) { return SortedRangeSet.copyOf(type, values.stream() .map(value -> Range.equal(type, value)) .collect(toList())); } if (type.isComparable()) { return EquatableValueSet.copyOf(type, values); } throw new IllegalArgumentException("Cannot create discrete ValueSet with non-comparable type: " + type); }
static ValueSet of(Type type, Object first, Object... rest) { if (type.isOrderable()) { return SortedRangeSet.of(type, first, rest); } if (type.isComparable()) { return EquatableValueSet.of(type, first, rest); } throw new IllegalArgumentException("Cannot create discrete ValueSet with non-comparable type: " + type); }
public ClassifierType(Type type) { super(new TypeSignature(ClassifierParametricType.NAME, TypeSignatureParameter.of(type.getTypeSignature()))); checkArgument(type.isComparable(), "type must be comparable"); labelType = type; }
public boolean canBind(Type type) { if (comparableRequired && !type.isComparable()) { return false; } if (orderableRequired && !type.isOrderable()) { return false; } if (variadicBound != null && !type.getTypeSignature().getBase().equals(variadicBound)) { return false; } return true; }
private boolean satisfiesConstraints(Type type) { if (comparableRequired && !type.isComparable()) { return false; } if (orderableRequired && !type.isOrderable()) { return false; } if (requiredBaseName.isPresent() && !UNKNOWN.equals(type) && !requiredBaseName.get().equals(type.getTypeSignature().getBase())) { // TODO: the case below should be properly handled: // * `type` does not have the `requiredBaseName` but can be coerced to some type that has the `requiredBaseName`. return false; } return true; } }
if (type.isComparable()) { if (!functions.canResolveOperator(HASH_CODE, BIGINT, ImmutableList.of(type))) { missingOperators.put(type, HASH_CODE);
private boolean checkAllEquatableTypes(AggregateInfo aggregateInfo) { for (Symbol symbol : aggregateInfo.getOriginalNonDistinctAggregateArgs()) { Type type = symbolAllocator.getTypes().get(symbol); if (!type.isComparable()) { return false; } } if (!symbolAllocator.getTypes().get(aggregateInfo.getMask()).isComparable()) { return false; } return true; }
public MapType( Type keyType, Type valueType, MethodHandle keyBlockNativeEquals, MethodHandle keyBlockEquals, MethodHandle keyNativeHashCode, MethodHandle keyBlockHashCode) { super(new TypeSignature(StandardTypes.MAP, TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(valueType.getTypeSignature())), Block.class); if (!keyType.isComparable()) { throw new IllegalArgumentException(format("key type must be comparable, got %s", keyType)); } this.keyType = keyType; this.valueType = valueType; requireNonNull(keyBlockNativeEquals, "keyBlockNativeEquals is null"); requireNonNull(keyNativeHashCode, "keyNativeHashCode is null"); requireNonNull(keyBlockHashCode, "keyBlockHashCode is null"); this.keyBlockNativeEquals = keyBlockNativeEquals; this.keyNativeHashCode = keyNativeHashCode; this.keyBlockHashCode = keyBlockHashCode; this.keyBlockEquals = keyBlockEquals; }
static ValueSet none(Type type) { if (type.isOrderable()) { return SortedRangeSet.none(type); } if (type.isComparable()) { return EquatableValueSet.none(type); } return AllOrNoneValueSet.none(type); }
static ValueSet all(Type type) { if (type.isOrderable()) { return SortedRangeSet.all(type); } if (type.isComparable()) { return EquatableValueSet.all(type); } return AllOrNoneValueSet.all(type); }
domain = extractOrderableDomain(comparisonOperator, type, value, complement); else if (type.isComparable()) { domain = extractEquatableDomain(comparisonOperator, type, value, complement);
private static void addTypeRow(Builder builder, Type type) { builder.addRow( type.getDisplayName(), jdbcDataType(type), columnSize(type), null, null, null, DatabaseMetaData.typeNullable, false, type.isComparable() ? DatabaseMetaData.typeSearchable : DatabaseMetaData.typePredNone, null, false, null, null, 0, 0, null, null, numPrecRadix(type)); }
@Test public void testOperatorsImplemented() { for (Type type : typeRegistry.getTypes()) { if (type.isComparable()) { functionRegistry.resolveOperator(EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(NOT_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(IS_DISTINCT_FROM, ImmutableList.of(type, type)); functionRegistry.resolveOperator(HASH_CODE, ImmutableList.of(type)); } if (type.isOrderable()) { functionRegistry.resolveOperator(LESS_THAN, ImmutableList.of(type, type)); functionRegistry.resolveOperator(LESS_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN_OR_EQUAL, ImmutableList.of(type, type)); functionRegistry.resolveOperator(GREATER_THAN, ImmutableList.of(type, type)); } } }
@Override protected Type visitQuantifiedComparisonExpression(QuantifiedComparisonExpression node, StackableAstVisitorContext<Context> context) { Expression value = node.getValue(); process(value, context); Expression subquery = node.getSubquery(); process(subquery, context); Type comparisonType = coerceToSingleType(context, node, "Value expression and result of subquery must be of the same type for quantified comparison: %s vs %s", value, subquery); switch (node.getOperator()) { case LESS_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN: case GREATER_THAN_OR_EQUAL: if (!comparisonType.isOrderable()) { throw new SemanticException(TYPE_MISMATCH, node, "Type [%s] must be orderable in order to be used in quantified comparison", comparisonType); } break; case EQUAL: case NOT_EQUAL: if (!comparisonType.isComparable()) { throw new SemanticException(TYPE_MISMATCH, node, "Type [%s] must be comparable in order to be used in quantified comparison", comparisonType); } break; default: throw new IllegalStateException(format("Unexpected comparison type: %s", node.getOperator())); } return setExpressionType(node, BOOLEAN); }
if (mapTestsEnabled && type.isComparable()) { testMapRoundTrip(type, readValues);
protected void assertPositionEquals(Block block, int position, Object expectedStackValue, Object expectedObjectValue) { long hash = 0; if (type.isComparable()) { hash = hashPosition(type, block, position); } assertPositionValue(block, position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getSingleValueBlock(position), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, 1), 0, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(0, position + 1), position, expectedStackValue, hash, expectedObjectValue); assertPositionValue(block.getRegion(position, block.getPositionCount() - position), 0, expectedStackValue, hash, expectedObjectValue); BlockBuilder blockBuilder = type.createBlockBuilder(null, 1); type.appendTo(block, position, blockBuilder); assertPositionValue(blockBuilder.build(), 0, expectedStackValue, hash, expectedObjectValue); }