Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"iPhone10,1": "iPhone 8",
"iPhone10,4": "iPhone 8",
"iPhone10,2": "iPhone 8 Plus",
"iPhone10,5": "iPhone 8 Plus",
"iPhone10,3": "iPhone X",
"iPhone10,6": "iPhone X",
},
"isOneToOne": False,
},
},
}
spec_json = json.dumps(dimension_spec)
col = DruidColumn(column_name="deviceName", dimension_spec_json=spec_json)
column_dict = {"deviceName": col}
f = DruidDatasource.get_filters(filters, [], column_dict)
assert isinstance(f.extraction_function, MapLookupExtraction)
dim_ext_fn = dimension_spec["extractionFn"]
f_ext_fn = f.extraction_function
self.assertEqual(dim_ext_fn["lookup"]["map"], f_ext_fn._mapping)
self.assertEqual(dim_ext_fn["lookup"]["isOneToOne"], f_ext_fn._injective)
self.assertEqual(
dim_ext_fn["replaceMissingValueWith"], f_ext_fn._replace_missing_values
)
self.assertEqual(
dim_ext_fn["retainMissingValue"], f_ext_fn._retain_missing_values
)
def _create_extraction_fn(dim_spec):
extraction_fn = None
if dim_spec and "extractionFn" in dim_spec:
col = dim_spec["dimension"]
fn = dim_spec["extractionFn"]
ext_type = fn.get("type")
if ext_type == "lookup" and fn["lookup"].get("type") == "map":
replace_missing_values = fn.get("replaceMissingValueWith")
retain_missing_values = fn.get("retainMissingValue", False)
injective = fn.get("isOneToOne", False)
extraction_fn = MapLookupExtraction(
fn["lookup"]["map"],
replace_missing_values=replace_missing_values,
retain_missing_values=retain_missing_values,
injective=injective,
)
elif ext_type == "regex":
extraction_fn = RegexExtraction(fn["expr"])
elif ext_type == "registeredLookup":
extraction_fn = RegisteredLookupExtraction(fn.get("lookup"))
elif ext_type == "timeFormat":
extraction_fn = TimeFormatExtraction(
fn.get("format"), fn.get("locale"), fn.get("timeZone")
)
else:
raise Exception(_("Unsupported extraction function: " + ext_type))
return (col, extraction_fn)