def normalize_response()

in src/redash_stmo/query_runner/activedata.py [0:0]


    def normalize_response(self, table):
        columns = {}  # MAP FROM name TO (MAP FROM type TO (full_name))
        output = []

        def get_unique_name(name, type):
            all_types = columns.get(name)
            if all_types is None:
                all_types = columns[name] = {}
            specific_type = all_types.get(type)
            if specific_type is None:
                if all_types:
                    specific_type = all_types[type] = name + "." + type
                else:
                    specific_type = all_types[type] = name
            return specific_type

        for r in table["data"]:
            new_row = {}
            for i, cname in enumerate(table["header"]):
                val = r[i]
                if val is None:
                    continue
                if isinstance(val, (dict, list)):
                    val = json.dumps(val, cls=JSONEncoder)
                col = get_unique_name(cname, TYPES_MAP.get(type(val), TYPE_STRING))
                new_row[col] = val
            output.append(new_row)

        output_columns = [
            {"name": full_name, "type": ctype, "friendly_name": full_name}
            for cname, types in columns.items()
            for ctype, full_name in types.items()
        ]

        return {"columns": output_columns, "rows": output}