# Exp.boolBin

**URL:** <https://discuss.aerospike.com/t/exp-boolbin/8572>\
**Category:** Java Client\
**Tags:** expressions\
**Created:** [June 24, 2021, 11:37am UTC](https://discuss.aerospike.com/t/exp-boolbin/8572 "2021-06-24T11:37:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![naresh.maharaj](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/naresh.maharaj/32/1669_2.png) [@naresh.maharaj](https://discuss.aerospike.com/u/naresh.maharaj)\
**Post date:** [June 24, 2021, 11:37am UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/1 "2021-06-24T11:37:39Z")

</div>

I have stored the following records

```auto
  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 );

```

```auto
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:

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

```

but if I use

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

```

it works?

Would have expected both to work.

Here is the NOT working version:

```auto
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:

```auto
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))

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [June 24, 2021, 2:29pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/2 "2021-06-24T14:29:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![naresh.maharaj](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/naresh.maharaj/32/1669_2.png) [@naresh.maharaj](https://discuss.aerospike.com/u/naresh.maharaj)\
**Post date:** [June 24, 2021, 2:45pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/3 "2021-06-24T14:45:07Z")

</div>

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

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

```

as per the initial text

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [June 24, 2021, 3:06pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/4 "2021-06-24T15:06:47Z")

</div>

Which client version are you using?

---

<div class="post-metadata">

**Author:** ![naresh.maharaj](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/naresh.maharaj/32/1669_2.png) [@naresh.maharaj](https://discuss.aerospike.com/u/naresh.maharaj)\
**Post date:** [June 24, 2021, 3:40pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/5 "2021-06-24T15:40:10Z")

</div>

Server: AEROSPIKE\_VERSION=5.6.0.5 Community

Client: com.aerospike aerospike-client 5.1.3

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [June 24, 2021, 5:11pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/6 "2021-06-24T17:11:51Z")

</div>

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`](https://docs.aerospike.com/apidocs/java/com/aerospike/client/Value.html#UseBoolBin) in the java client documentation.

---

<div class="post-metadata">

**Author:** ![naresh.maharaj](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/naresh.maharaj/32/1669_2.png) [@naresh.maharaj](https://discuss.aerospike.com/u/naresh.maharaj)\
**Post date:** [June 24, 2021, 9:26pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/7 "2021-06-24T21:26:29Z")

</div>

Hi,

That worked:

```auto
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.

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [June 24, 2021, 10:01pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/8 "2021-06-24T22:01:52Z")

</div>

> [@naresh.maharaj](#):
>
> 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:

```java
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"))
    )
)

```

---

<div class="post-metadata">

**Author:** ![naresh.maharaj](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/naresh.maharaj/32/1669_2.png) [@naresh.maharaj](https://discuss.aerospike.com/u/naresh.maharaj)\
**Post date:** [June 24, 2021, 10:05pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/9 "2021-06-24T22:05:10Z")

</div>

Great response.

Kind regards Naresh Maharaj

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [September 16, 2021, 10:05pm UTC](https://discuss.aerospike.com/t/exp-boolbin/8572/10 "2021-09-16T22:05:51Z")

</div>

Closed on September 16, 2021, 10:05pm UTC

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