add a sqlglot transformation for casting to varchar
@@ -23,3 +23,22 @@ def move_l_r_table_prefix_to_column_suffix(blocking_rule):
transformed_tree = expression_tree.transform(_add_l_or_r_to_identifier)
transformed_tree = transformed_tree.transform(_remove_table_prefix)
return transformed_tree.sql()
+
+
+def cast_as_varchar_transformer(node):
+ if isinstance(node, exp.Column):
+
+ if isinstance(node.parent, exp.Cast):
+ return node
+
+ if node.find_ancestor(exp.DPipe):
+ sql = f"cast({node.table}.{node.name} as varchar)"
+ return sqlglot.parse_one(sql)
+
+ return node
+
+
+def cast_concat_as_varchar(sql):
+ syntax_tree = sqlglot.parse_one(sql, read=None)
+ transformed_tree = syntax_tree.transform(cast_as_varchar_transformer)
+ return transformed_tree.sql()
