def test_aliases() -> None: # No context col1 = Column("al1", "column1", "table1") col2 = Column("al1", "column1", "table1") assert col1.accept( ClickhouseExpressionFormatter()) == "(table1.column1 AS al1)" assert col2.accept( ClickhouseExpressionFormatter()) == "(table1.column1 AS al1)" # With Context pc = ParsingContext() assert col1.accept( ClickhouseExpressionFormatter(pc)) == "(table1.column1 AS al1)" assert col2.accept(ClickhouseExpressionFormatter(pc)) == "al1" # Hierarchical expression inherits parsing context and applies alaises f = FunctionCall( None, "f1", ( FunctionCall("tag[something]", "tag", (Column(None, "column1", "table1"))), FunctionCall("tag[something]", "tag", (Column(None, "column1", "table1"))), FunctionCall("tag[something]", "tag", (Column(None, "column1", "table1"))), ), ) expected = "f1((tag(table1.column1) AS `tag[something]`), `tag[something]`, `tag[something]`)" assert f.accept(ClickhouseExpressionFormatter()) == expected
def translate_function_strict(self, exp: FunctionCall) -> FunctionCall: """ Unfortunately it is not possible to avoid this assertion. Though the structure of TranslationMappers guarantees that this assertion can never fail since it defines the valid translations and it statically requires a FunctionCallMapper to translate a FunctionCall. FunctionCallMapper returns FunctionCall as return type, thus always satisfying the assertion. """ f = exp.accept(self) assert isinstance(f, FunctionCall) return f