mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-10-18 20:30:48 +00:00
* add teradata functions * fix teradata schema * reformat code * change random approach for teradata --------- Co-authored-by: Teddy <teddy.crepineau@gmail.com>
This commit is contained in:
parent
7cf9fb3820
commit
342eaee092
@ -52,6 +52,7 @@ def _(element, compiler, **kw):
|
||||
@compiles(LenFn, Dialects.Hana)
|
||||
@compiles(LenFn, Dialects.Druid)
|
||||
@compiles(LenFn, Dialects.Doris)
|
||||
@compiles(LenFn, Dialects.Teradata)
|
||||
def _(element, compiler, **kw):
|
||||
return "LENGTH(%s)" % compiler.process(element.clauses, **kw)
|
||||
|
||||
|
@ -40,3 +40,12 @@ def _(element, compiler, **kw):
|
||||
@compiles(MD5, PythonDialects.BigQuery.value)
|
||||
def _(element, compiler, **kw):
|
||||
return f"TO_HEX(MD5(CAST({compiler.process(element.clauses, **kw)} AS STRING)))"
|
||||
|
||||
|
||||
@compiles(MD5, PythonDialects.Teradata.value)
|
||||
def _(element, compiler, **kw):
|
||||
# There is no MD5 in Teradata or any other hashes
|
||||
# But we can use UDF function hash_md5 published by Teradata Community
|
||||
return (
|
||||
f"HASH_MD5(CAST({compiler.process(element.clauses, **kw)} AS VARCHAR(32000)))"
|
||||
)
|
||||
|
@ -61,6 +61,7 @@ def _(element, compiler, **kw):
|
||||
@compiles(ModuloFn, Dialects.Vertica)
|
||||
@compiles(ModuloFn, Dialects.Hana)
|
||||
@compiles(ModuloFn, Dialects.Cockroach)
|
||||
@compiles(ModuloFn, Dialects.Teradata)
|
||||
def _(element, compiler, **kw):
|
||||
"""Modulo function for specific dialect"""
|
||||
value, base = validate_and_compile(element, compiler, **kw)
|
||||
|
@ -98,10 +98,14 @@ def _(*_, **__):
|
||||
|
||||
|
||||
@compiles(RandomNumFn, Dialects.Snowflake)
|
||||
@compiles(RandomNumFn, Dialects.Teradata)
|
||||
def _(*_, **__):
|
||||
"""We use FROM <table> SAMPLE BERNOULLI (n) for sampling
|
||||
in snowflake. We'll return 0 to make sure we get all the rows
|
||||
from the already sampled results when executing row::MOD(0, 100) < profile_sample.
|
||||
|
||||
Teradata RANDOM(0,100) function can't be used inside ORDER BY clause. That's why
|
||||
use the same trick.
|
||||
"""
|
||||
return "0"
|
||||
|
||||
|
@ -86,6 +86,7 @@ class PythonDialects(Enum):
|
||||
SingleStore = "singlestore"
|
||||
SQLite = "sqlite"
|
||||
Snowflake = "snowflake"
|
||||
Teradata = "teradatasql"
|
||||
Trino = "trino"
|
||||
Vertica = "vertica"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user