Querying an Enum Value

Hi There -

I was curious if there were any examples on how to query an enum value using the QueryComponent. I’m having a bit of trouble:

Query.field("aggregationType").equalsValue(MetricExtractorProto.AggregationType.NONE)
Query.field("aggregationType").equalsValue(MetricExtractorProto.AggregationType.NONE.name)
Query.field("aggregationType").equalsValue(MetricExtractorProto.AggregationType.NONE.ordinal)

Any of these seem to throw an exception

com.apple.foundationdb.record.RecordCoreException: Comparison value of incorrect type
or
com.apple.foundationdb.record.RecordCoreException: Tried to compare non-comparable object class com.google.protobuf.Descriptors$EnumValueDescriptor

For now I’m just running a post-query filter so this isn’t blocking by any means.

It looks like all our tests / examples use an index to match the enum value. We don’t have one for evaluating against a loaded record. And that doesn’t (always?) work.

I’ll create a GitHub issue for this.

Awesome, thanks for the reply!

Was this issue ever fixed? Getting a

com.apple.foundationdb.record.RecordCoreException: com.apple.foundationdb.record.RecordCoreException: Tried to compare non-comparable object class com.google.protobuf.Descriptors$EnumValueDescriptor

when attempting to use the following QueryComponent:

QueryComponent agentStatusQueryComponent = field("carColour").equalsValue(CarColour.RED);

After some debugging I can see the exception being thrown in the method toClassWithRealEquals in com/apple/foundationdb/record/query/expressions/Comparisons.java

@SuppressWarnings("rawtypes")
    private static Object toClassWithRealEquals(@Nullable Object obj) {
        if (obj == null) {
            return null;
        } else if (obj instanceof ByteString) {
            return obj;
        } else if (obj instanceof byte[]) {
            return ByteString.copyFrom((byte[])obj);
        } else if (obj instanceof Comparable) {
            return obj;
        } else if (obj instanceof List) {
            return obj;
        } else {
            throw new RecordCoreException("Tried to compare non-comparable object " + obj.getClass());
        }
    }

I can see the closed PR from the conversation above: Evaluating a query component for equality comparison with a enum constant fails · Issue #763 · FoundationDB/fdb-record-layer · GitHub

Is there a work around? Thanks!

1 Like