def _format_data()

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


    def _format_data(self, column, data):
        """Given a Presto column and its data, return a more human-readable
        format of its data for some data types."""
        type = column["rawType"]

        try:
            iter(data)  # check if the data is iterable
        except TypeError:
            return data  # non-iterables can simply be directly shown

        # records should have their fields associated with types
        # but keep the tuple format for backward-compatibility
        if type == "row":
            keys = column["literalArguments"]
            values = [
                self._format_data(c, d) for c, d in zip(column["typeArguments"], data)
            ]
            return tuple(zip(keys, values))

        # arrays should have their element types associated with each element
        elif type == "array":
            rep = [column["typeArguments"][0]] * len(data)
            return [self._format_data(c, d) for c, d in zip(rep, data)]

        # maps should have their value types associated with each value
        # (note that keys are always strings), but keep the tuple format
        # for backward-compatibility
        elif type == "map":
            value_type = column["typeArguments"][1]
            return [
                (k, self._format_data(value_type, v)) for k, v in data.items()
            ]

        else:
            # unknown type, don't process it
            return data