Skip to content

Query with % operator results in a ClassCastException #2825

@mrigger

Description

@mrigger

Consider the following test case:

CREATE TABLE T0(c0 DOUBLE);
INSERT INTO T0(c0) VALUES (0);
SELECT * FROM T0 WHERE c0 % 0.1; -- General error: "java.lang.ClassCastException: class org.h2.value.ValueDecfloat cannot be cast to class org.h2.value.ValueNumeric (org.h2.value.ValueDecfloat and org.h2.value.ValueNumeric are in unnamed module of loader 'app')"; 

Unexpectedly, the SELECT causes a ClassCastException, which seems like an internal error to me:

Caused by: java.lang.ClassCastException: class org.h2.value.ValueDecfloat cannot be cast to class org.h2.value.ValueNumeric (org.h2.value.ValueDecfloat and org.h2.value.ValueNumeric are in unnamed module of loader 'app')
    at org.h2.value.ValueBigDecimalBase.modulus(ValueBigDecimalBase.java:81)
    at org.h2.expression.function.MathFunction.getValue(MathFunction.java:93)
    at org.h2.expression.function.Function1_2.getValue(Function1_2.java:39)
    at org.h2.expression.Expression.getBooleanValue(Expression.java:334)
    at org.h2.command.query.Select.isConditionMet(Select.java:449)
    at org.h2.command.query.Select$LazyResultQueryFlat.fetchNextRow(Select.java:1824)
    at org.h2.result.LazyResult.hasNext(LazyResult.java:104)
    at org.h2.result.LazyResult.next(LazyResult.java:63)
    at org.h2.command.query.Select.queryFlat(Select.java:722)
    at org.h2.command.query.Select.queryWithoutCache(Select.java:828)
    at org.h2.command.query.Query.queryWithoutCacheLazyCheck(Query.java:198)
    at org.h2.command.query.Query.query(Query.java:495)
    at org.h2.command.query.Query.query(Query.java:458)
    at org.h2.command.CommandContainer.query(CommandContainer.java:255)
    at org.h2.command.Command.executeQuery(Command.java:190)

I found this based on commit 30f0187.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions