Exp.boolBin

I have stored the following records

  Bin day  = new Bin("day", Value.get("Monday"));
  Bin month = new Bin("month", Value.get(11));
  Bin active = new Bin("active", Value.get(false));
  client.put( wPolicy, keyA, day, month, active );
aql> select * from insurance
+-------------+-------+--------+
| day         | month | active |
+-------------+-------+--------+
| "Monday"    | 11    | 0      |
| "Wednesday" | 9     | 0      |
| "Tuesday"   | 10    | 1      |
+-------------+-------+--------+
3 rows in set (0.265 secs)

When selecting this data with an expression it returns null if using:

Exp.eq(Exp.boolBin("active"), Exp.val(false)

but if I use

Exp.eq(Exp.intBin("active"), Exp.val(0)

it works?

Would have expected both to work.

Here is the NOT working version:

Policy policy = new Policy();
        policy.filterExp = Exp.build(
                Exp.and(
                        Exp.eq(Exp.stringBin("day"), Exp.val("Monday")),
                        Exp.eq(Exp.intBin("month"), Exp.val(11)),
                        Exp.eq(Exp.boolBin("active"), Exp.val(false))
                )
        );

Return null

Here is the working version:

Policy policy = new Policy();
        policy.filterExp = Exp.build(
                Exp.and(
                        Exp.eq(Exp.stringBin("day"), Exp.val("Monday")),
                        Exp.eq(Exp.intBin("month"), Exp.val(11)),
                        Exp.eq(Exp.intBin("active"), Exp.val(0))
                )
        );

return (gen:1),(exp:364822605),(bins:(day:Monday),(month:11),(active:0))

BoolBin requires that the bin be a boolean type otherwise it returns unknown. Expressions do not implicitly cast between types.

Similarly expressions expecting bool will not cast any other type to a bool. For example something like or(true, 100) will return unknown down the expression tree. If the entire expressions results in unknown then it will be treated as false in a filter-expression and as an eval-error in an operation-expression.

Doesn’t this line mean the bin is of type boolean:

Bin active = new Bin("active", Value.get(false));

as per the initial text

Which client version are you using?

Server: AEROSPIKE_VERSION=5.6.0.5 Community

Client: com.aerospike aerospike-client 5.1.3

The client needs be configured to use the new boolean bin type for new Bin("active", Value.get(false)) to result in a boolean bin.

See Value.UseBoolBin in the java client documentation.

Hi,

That worked:

aql> select * from insurance.expr1
+-------------+-------+--------+--------------------------------+---------+---------+-------+
| day         | month | active | {edigest}                      | {set}   | {ttl}   | {gen} |
+-------------+-------+--------+--------------------------------+---------+---------+-------+
| "Monday"    | 11    | false  | "XIuhCB92E+NFMUvqoOQlWLUTD74=" | "expr1" | 2591984 | 1     |
| "Wednesday" | 9     | false  | "NS0pvx5lr8C0rtJVECvSZgyMKCM=" | "expr1" | 2591984 | 1     |
| "Tuesday"   | 10    | true   | "PC6RzAvP5wgSR1o46/GxdDA8nWA=" | "expr1" | 2591984 | 1     |
+-------------+-------+--------+--------------------------------+---------+---------+-------+

Understand this is to support backward compatibility.

Ideally this needs to become the fwd default state.

Yes, the goal is to eventually phase out this config. Going forward it is best to avoid using integers as Booleans. But while transitioning from integers to Boolean values an existing field could use a pattern similar to the following during the transition:

Exp.let(
    Exp.def(
        "active", Exp.cond(
            Exp.eq(Exp.binType("active"), Exp.Type.BOOL), Exp.boolBin("active"),
            Exp.ne(Exp.intBin("active"), Exp.val(0)) )),
    Exp.and(
        Exp.eq(Exp.stringBin("day"), Exp.val("Monday")),
        Exp.eq(Exp.intBin("month"), Exp.val(11)),
        Exp.not(Exp.var("active"))
    )
)

Great response.

Kind regards Naresh Maharaj

This topic was automatically closed 84 days after the last reply. New replies are no longer allowed.