• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / ActiveData / 1612

pending completion
1612

push

travis-ci

Kyle Lahnakoski
fix table format

25 of 25 new or added lines in 1 file covered. (100.0%)

4441 of 7759 relevant lines covered (57.24%)

0.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.27
/vendor/jx_elasticsearch/es52/expressions/eq_op.py
1
# encoding: utf-8
2
#
3
#
4
# This Source Code Form is subject to the terms of the Mozilla Public
5
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
6
# You can obtain one at http:# mozilla.org/MPL/2.0/.
7
#
8
# Contact: Kyle Lahnakoski (kyle@lahnakoski.com)
9
#
10
from __future__ import absolute_import, division, unicode_literals
1✔
11

12
from jx_base.expressions import (
1✔
13
    EqOp as EqOp_,
14
    FALSE,
15
    TRUE,
16
    Variable as Variable_,
17
    is_literal,
18
    simplified,
19
)
20
from jx_base.language import is_op
1✔
21
from jx_elasticsearch.es52.expressions import BasicEqOp
1✔
22
from jx_elasticsearch.es52.expressions._utils import ES52
1✔
23
from jx_elasticsearch.es52.expressions.case_op import CaseOp
1✔
24
from jx_elasticsearch.es52.expressions.or_op import OrOp
1✔
25
from jx_elasticsearch.es52.expressions.when_op import WhenOp
1✔
26
from jx_elasticsearch.es52.util import pull_functions
1✔
27
from jx_python.jx import value_compare
1✔
28
from mo_dots import Data, is_container
1✔
29
from mo_future import first
1✔
30
from mo_json import BOOLEAN, python_type_to_json_type, NUMBER_TYPES
1✔
31
from mo_logs import Log
1✔
32

33

34
class EqOp(EqOp_):
1✔
35
    @simplified
1✔
36
    def partial_eval(self):
37
        lhs = ES52[self.lhs].partial_eval()
1✔
38
        rhs = ES52[self.rhs].partial_eval()
1✔
39

40
        if is_literal(lhs):
1✔
41
            if is_literal(rhs):
×
42
                return FALSE if value_compare(lhs.value, rhs.value) else TRUE
×
43
            else:
44
                return EqOp([rhs, lhs])  # FLIP SO WE CAN USE TERMS FILTER
×
45

46
        return EqOp([lhs, rhs])
1✔
47

48
    def to_esfilter(self, schema):
1✔
49
        if is_op(self.lhs, Variable_) and is_literal(self.rhs):
1✔
50
            rhs = self.rhs.value
1✔
51
            lhs = self.lhs.var
1✔
52
            cols = schema.leaves(lhs)
1✔
53
            if not cols:
1✔
54
                Log.warning(
×
55
                    "{{col}} does not exist while processing {{expr}}",
56
                    col=lhs,
57
                    expr=self.__data__(),
58
                )
59

60
            if is_container(rhs):
1✔
61
                if len(rhs) == 1:
1✔
62
                    rhs = rhs[0]
1✔
63
                else:
64
                    types = Data()  # MAP JSON TYPE TO LIST OF LITERALS
1✔
65
                    for r in rhs:
1✔
66
                        types[python_type_to_json_type[r.__class__]] += [r]
1✔
67
                    if len(types) == 1:
1✔
68
                        jx_type, values = first(types.items())
1✔
69
                        for c in cols:
1✔
70
                            if jx_type == c.jx_type or (jx_type in NUMBER_TYPES and c.jx_type in NUMBER_TYPES):
1✔
71
                                return {"terms": {c.es_column: values}}
1✔
72
                        return FALSE.to_esfilter(schema)
×
73
                    else:
74
                        return (
×
75
                            OrOp(
76
                                [
77
                                    EqOp([self.lhs, values])
78
                                    for t, values in types.items()
79
                                ]
80
                            )
81
                            .partial_eval()
82
                            .to_esfilter(schema)
83
                        )
84

85
            for c in cols:
1✔
86
                if c.jx_type == BOOLEAN:
1✔
87
                    rhs = pull_functions[c.jx_type](rhs)
1✔
88
                rhs_type = python_type_to_json_type[rhs.__class__]
1✔
89
                if rhs_type == c.jx_type or (rhs_type in NUMBER_TYPES and c.jx_type in NUMBER_TYPES):
1✔
90
                    return {"term": {c.es_column: rhs}}
1✔
91
            return FALSE.to_esfilter(schema)
×
92
        else:
93
            return (
1✔
94
                ES52[
95
                    CaseOp(
96
                        [
97
                            WhenOp(self.lhs.missing(), **{"then": self.rhs.missing()}),
98
                            WhenOp(self.rhs.missing(), **{"then": FALSE}),
99
                            BasicEqOp([self.lhs, self.rhs]),
100
                        ]
101
                    )
102
                    .partial_eval()
103
                ]
104
                .to_esfilter(schema)
105
            )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2024 Coveralls, Inc