# \[BUG?\] Escaping periods in vega-lite calculate transform

**URL:** <https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424>\
**Category:** Kibana\
**Created:** [July 10, 2018, 7:42pm UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424 "2018-07-10T19:42:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tadgh](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tadgh](https://discuss.elastic.co/u/tadgh)\
**Post date:** [July 10, 2018, 7:42pm UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/1 "2018-07-10T19:42:23Z")

</div>

Using the percentile aggregate, elasticsearch returns results wherein the key contains a period. Like so:

```
 "score_outlier": {
            "values": {
              "1.0": 1,
              "5.0": 1,
              "25.0": 2,
              "50.0": 3,
              "75.0": 3,
              "95.0": 5,
              "99.0": 5
            }
          }

```

When visualizing, vega lite indicates that you should escape any fields containing periods using a double backslash: `\\`.

This works totally fine in the encodings, like here:

```
  {
      "mark": {"type": "bar", "style": "box"},
      "encoding": {
        "y": {"field": "score_outlier.values.25\\.0", "type": "quantitative"},
        "y2": {"field": "score_outlier.values.75\\.0", "type": "quantitative"},
        "x": {"field": "key", "type": "nominal"},
        "color": {"value": "steelblue"},
        "size": {"value": 11}
      }
    }

```

But if I do the same thing during a `calculate` transform, I get a Parse Error from Vega. Here is an example which fails:

```
   "transform": [
     {
       "calculate": "datum.score_outlier.values.75\\.0 - datum.score_outlier.values.25\\.0",
       "as": "iqr"
     }
   ]

```

Which returns:

`Expression parse error: "datum.score_outlier.values.75\\.0 - datum.score_outlier.values.25\\.0"`

I've tried not escaping, double-escaping, using square bracket indexing, but nothing seems to work. Am I missing something? The moment I switch this calculation to use a field that doesn't contain a period, all is well.

Thanks for any insights

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [July 10, 2018, 8:58pm UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/2 "2018-07-10T20:58:40Z")

</div>

@nyuriks - any thoughts here?

---

<div class="post-metadata">

**Author:** ![tadgh](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tadgh](https://discuss.elastic.co/u/tadgh)\
**Post date:** [July 10, 2018, 9:03pm UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/3 "2018-07-10T21:03:07Z")

</div>

To quick-fix the issue, I tried just adding a bucket script aggregation, which turns out, suffers the same issue I am seeing here I think.

I actually think the issue may be higher up, in Elasticsearch: [Bucket Script Aggregating on fields that contain a period](https://discuss.elastic.co/t/bucket-script-aggregating-on-fields-that-contain-a-period/139428) . To narrow this down, I made a small example query. This may not be VEGA-related after all, but just ES related.

---

<div class="post-metadata">

**Author:** ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)\
**Post date:** [July 10, 2018, 9:19pm UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/4 "2018-07-10T21:19:29Z")

</div>

@tadgh for the Vega part, try using index access instead, e.g. `datum.score_outlier.values['75.0']`

---

<div class="post-metadata">

**Author:** ![tadgh](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tadgh](https://discuss.elastic.co/u/tadgh)\
**Post date:** [July 10, 2018, 10:19pm UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/5 "2018-07-10T22:19:14Z")

</div>

Thanks, changing my transform to:

```
  "transform": [
    {
      "calculate": "datum.score_outlier.values['75.0'] - datum.score_outlier.values['25.0']"
      "as": "iqr"
    },

```

Did the trick. That said, seems a bit off that its fine in the encoding, but breaks in the calculation. Slightly unintuitive to have to nest quotes in one spot, but able to escape in another.

---

<div class="post-metadata">

**Author:** ![nyuriks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nyuriks/32/26171_2.png) [@nyuriks](https://discuss.elastic.co/u/nyuriks)\
**Post date:** [July 11, 2018, 12:46am UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/6 "2018-07-11T00:46:35Z")

</div>

@tadgh while not ideal, the reason it works in the `field` is because `field` is not an expression, it is a path to a value inside the current `datum`. So if `datum` is `{a: {b: [10.5]: 'something'}}`, getting to `something` would be `a.b.10\\.5`. On the other hand, `signal` and `expr` values are real expressions - they get evaluated similar to how javascript evaluates things. JS would throw an error with `datum.a.b.10\\.5`, and so does Vega.

---

<div class="post-metadata">

**Author:** ![tadgh](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@tadgh](https://discuss.elastic.co/u/tadgh)\
**Post date:** [July 11, 2018, 3:07am UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/7 "2018-07-11T03:07:11Z")

</div>

Understood, thanks for the clarification

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 8, 2018, 3:07am UTC](https://discuss.elastic.co/t/bug-escaping-periods-in-vega-lite-calculate-transform/139424/8 "2018-08-08T03:07:16Z")

</div>

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