Skip to content

Commit d58377e

Browse files
authored
feat(optimizer)!: add SHA function annotations for Hive (#6750)
1 parent f7eebb1 commit d58377e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

sqlglot/typing/hive.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
exp.Tanh,
1515
}
1616
},
17+
**{
18+
expr_type: {"returns": exp.DataType.Type.VARCHAR}
19+
for expr_type in {
20+
exp.SHA,
21+
exp.SHA2,
22+
}
23+
},
1724
exp.Coalesce: {
1825
"annotator": lambda self, e: self._annotate_by_args(e, "this", "expressions", promote=True)
1926
},

tests/fixtures/optimizer/annotate_functions.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,18 @@ BINARY;
415415
TO_BINARY(tbl.double_col, tbl.str_col);
416416
BINARY;
417417

418+
# dialect: hive, spark2, spark, databricks
419+
SHA(tbl.str_col);
420+
VARCHAR;
421+
422+
# dialect: hive, spark2, spark, databricks
423+
SHA1(tbl.str_col);
424+
VARCHAR;
425+
426+
# dialect: hive, spark2, spark, databricks
427+
SHA2(tbl.str_col, tbl.int_col);
428+
VARCHAR;
429+
418430
--------------------------------------
419431
-- BigQuery
420432
--------------------------------------

0 commit comments

Comments
 (0)