def validate_mapper()

in backend/lambdas/data_mappers/handlers.py [0:0]


def validate_mapper(mapper):
    existing_s3_locations = get_existing_s3_locations(mapper["DataMapperId"])
    if mapper["QueryExecutorParameters"].get("DataCatalogProvider") == "glue":
        table_details = get_table_details_from_mapper(mapper)
        new_location = get_glue_table_location(table_details)
        serde_lib, serde_params = get_glue_table_format(table_details)
        for partition in mapper["QueryExecutorParameters"].get("PartitionKeys", []):
            if partition not in get_glue_table_partition_keys(table_details):
                raise ValueError("Partition Key {} doesn't exist".format(partition))
        if any([is_overlap(new_location, e) for e in existing_s3_locations]):
            raise ValueError(
                "A data mapper already exists which covers this S3 location"
            )
        if serde_lib not in SUPPORTED_SERDE_LIBS:
            raise ValueError(
                "The format for the specified table is not supported. The SerDe lib must be one of {}".format(
                    ", ".join(SUPPORTED_SERDE_LIBS)
                )
            )
        if serde_lib == JSON_OPENX_SERDE:
            not_allowed_json_params = {
                "ignore.malformed.json": "TRUE",
                "dots.in.keys": "TRUE",
            }
            for param, value in not_allowed_json_params.items():
                if param in serde_params and serde_params[param] == value:
                    raise ValueError(
                        "The parameter {} cannot be {} for SerDe library {}".format(
                            param, value, JSON_OPENX_SERDE
                        )
                    )
            if any([k for k, v in serde_params.items() if k.startswith("mapping.")]):
                raise ValueError(
                    "Column mappings are not supported for SerDe library {}".format(
                        JSON_OPENX_SERDE
                    )
                )