Ejemplo n.º 1
0
    def visit(self, query: main.Query) -> QVisited:
        fields = query.get_fields()
        returns = {}
        for field in fields:
            returns[field] = getattr(self, f"_visit_{field}")(getattr(query, field))

        return self._combine(query, returns)
Ejemplo n.º 2
0
    def _combine(self, query: main.Query, returns: Mapping[str, str]) -> str:
        clause_order = query.get_fields()
        # These fields are encoded outside of the SQL
        to_skip = (
            "dataset",
            "consistent",
            "turbo",
            "debug",
            "dry_run",
            "legacy",
            "parent_api",
            "team",
            "feature",
        )

        separator = "\n" if (self.pretty and not self.is_inner) else " "
        formatted = separator.join(
            [returns[c] for c in clause_order if c not in to_skip and returns[c]]
        )

        if self.pretty and not self.is_inner:
            prefix = ""
            for skip in to_skip:
                if returns.get(skip):
                    prefix += f"-- {skip.upper()}: {returns[skip]}\n"
            formatted = f"{prefix}{formatted}"

        return formatted