Ejemplo n.º 1
0
    def test_map_injective(self):
        ext_fn = MapLookupExtraction(self.mapping, injective=True)
        actual = ext_fn.build()
        expected = {
            "type": "lookup",
            "lookup": {"type": "map", "map": self.mapping},
            "retainMissingValue": False,
            "replaceMissingValueWith": None,
            "injective": True,
        }

        assert actual == expected
Ejemplo n.º 2
0
    def test_map_replace_missing(self):
        ext_fn = MapLookupExtraction(self.mapping, replace_missing_values="replacer")
        actual = ext_fn.build()
        expected = {
            "type": "lookup",
            "lookup": {"type": "map", "map": self.mapping},
            "retainMissingValue": False,
            "replaceMissingValueWith": "replacer",
            "injective": False,
        }

        assert actual == expected
Ejemplo n.º 3
0
    def test_map_injective(self):
        ext_fn = MapLookupExtraction(self.mapping, injective=True)
        actual = ext_fn.build()
        expected = {
            "type": "lookup",
            "lookup": {
                "type": "map",
                "map": self.mapping
            },
            "retainMissingValue": False,
            "replaceMissingValueWith": None,
            "injective": True,
        }

        assert actual == expected
Ejemplo n.º 4
0
    def test_map_injective(self):
        ext_fn = MapLookupExtraction(self.mapping, injective=True)
        actual = ext_fn.build()
        expected = {
            'type': 'lookup',
            'lookup': {
                'type': 'map',
                'map': self.mapping
            },
            'retainMissingValue': False,
            'replaceMissingValueWith': None,
            'injective': True
        }

        assert actual == expected
Ejemplo n.º 5
0
    def test_map_injective(self):
        ext_fn = MapLookupExtraction(self.mapping, injective=True)
        actual = ext_fn.build()
        expected = {
            'type': 'lookup',
            'lookup': {
                'type': 'map',
                'map': self.mapping
            },
            'retainMissingValue': False,
            'replaceMissingValueWith': None,
            'injective': True
        }

        assert actual == expected
Ejemplo n.º 6
0
    def test_map_replace_missing(self):
        ext_fn = MapLookupExtraction(self.mapping,
                                     replace_missing_values="replacer")
        actual = ext_fn.build()
        expected = {
            "type": "lookup",
            "lookup": {
                "type": "map",
                "map": self.mapping
            },
            "retainMissingValue": False,
            "replaceMissingValueWith": "replacer",
            "injective": False,
        }

        assert actual == expected
Ejemplo n.º 7
0
    def test_map_replace_missing(self):
        ext_fn = MapLookupExtraction(self.mapping,
                                     replace_missing_values='replacer')
        actual = ext_fn.build()
        expected = {
            'type': 'lookup',
            'lookup': {
                'type': 'map',
                'map': self.mapping
            },
            'retainMissingValue': False,
            'replaceMissingValueWith': 'replacer',
            'injective': False
        }

        assert actual == expected
Ejemplo n.º 8
0
    def test_map_replace_missing(self):
        ext_fn = MapLookupExtraction(self.mapping,
                                     replace_missing_values='replacer')
        actual = ext_fn.build()
        expected = {
            'type': 'lookup',
            'lookup': {
                'type': 'map',
                'map': self.mapping
            },
            'retainMissingValue': False,
            'replaceMissingValueWith': 'replacer',
            'injective': False
        }

        assert actual == expected
Ejemplo n.º 9
0
    def test_extraction_functions(self):
        js_func = 'function(x) {return x};'
        ext_fns = [
            (RegexExtraction(r'\w+'), {'type': 'regex', 'expr': '\\w+'}),
            (PartialExtraction(r'\w+'), {'type': 'partial', 'expr': '\\w+'}),
            (JavascriptExtraction(js_func), {
                'type': 'javascript',
                'function': js_func,
                'injective': False
            }),
            (MapLookupExtraction(TestMapLookupExtraction.mapping), {
                'type': 'lookup',
                'lookup': {
                    'type': 'map',
                    'map': TestMapLookupExtraction.mapping
                },
                'retainMissingValue': False,
                'replaceMissingValueWith': None,
                'injective': False
            })
        ]

        for ext_fn, expected_ext_fn in ext_fns:
            dim_spec = DimensionSpec('dim', 'out', extraction_function=ext_fn)
            actual = dim_spec.build()
            expected = {
                'type': 'extraction',
                'dimension': 'dim',
                'outputName': 'out',
                'extractionFn': expected_ext_fn
            }

            assert actual == expected
Ejemplo n.º 10
0
    def test_extraction_functions(self):
        js_func = "function(x) {return x};"
        ext_fns = [
            (RegexExtraction(r"\w+"), {
                "type": "regex",
                "expr": "\\w+"
            }),
            (PartialExtraction(r"\w+"), {
                "type": "partial",
                "expr": "\\w+"
            }),
            (
                JavascriptExtraction(js_func),
                {
                    "type": "javascript",
                    "function": js_func,
                    "injective": False
                },
            ),
            (
                MapLookupExtraction(TestMapLookupExtraction.mapping),
                {
                    "type": "lookup",
                    "lookup": {
                        "type": "map",
                        "map": TestMapLookupExtraction.mapping
                    },
                    "retainMissingValue": False,
                    "replaceMissingValueWith": None,
                    "injective": False,
                },
            ),
        ]

        for ext_fn, expected_ext_fn in ext_fns:
            dim_spec = DimensionSpec("dim", "out", extraction_function=ext_fn)
            actual = dim_spec.build()
            expected = {
                "type": "extraction",
                "dimension": "dim",
                "outputName": "out",
                "extractionFn": expected_ext_fn,
            }

            assert actual == expected