From e7317861ebf5a5a535926879c0fe55e2f6af82b0 Mon Sep 17 00:00:00 2001 From: tkaunlaky-e6 Date: Mon, 27 Jul 2026 14:30:43 +0530 Subject: [PATCH] fix(e6): default single-argument LOG to natural-log base e DBR treats a single-argument LOG(x) as the natural logarithm (base e), but e6 requires an explicit base. Supply e = 2.718281828459045 so that single-arg LOG becomes LOG(2.718281828459045, x). DBR parses single-arg LOG(x) into an Ln node tagged with the original name, so handle that case too while leaving a genuine LN(x) untouched. Two-argument LOG(base, value) is unchanged. --- sqlglot/dialects/e6.py | 12 +++++++++++- tests/dialects/test_e6.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sqlglot/dialects/e6.py b/sqlglot/dialects/e6.py index d37d30030f..9e5ba190a6 100644 --- a/sqlglot/dialects/e6.py +++ b/sqlglot/dialects/e6.py @@ -3381,7 +3381,17 @@ def create_lpad_component(func_name: str): exp.LastValue: rename_func("LAST_VALUE"), exp.NextDay: _next_day_sql, exp.Length: length_sql, - exp.Log: lambda self, e: self.func("LOG", e.this, e.expression), + exp.Log: lambda self, e: self.func("LOG", e.this, e.expression) + if e.expression + else self.func("LOG", exp.Literal.number("2.718281828459045"), e.this), + # DBR parses single-argument LOG(x) into an Ln node (it treats log as + # natural log) that keeps the original name in meta; give it the base + # e explicitly. A genuine LN(x) is left as-is. + exp.Ln: lambda self, e: self.func( + "LOG", exp.Literal.number("2.718281828459045"), e.this + ) + if (e.meta.get("name") or "").lower() == "log" + else self.func("LN", e.this), exp.Lower: rename_func("LOWER"), exp.LogicalOr: rename_func("BOOL_OR"), exp.MakeInterval: lambda self, e: make_interval_sql(self, e) diff --git a/tests/dialects/test_e6.py b/tests/dialects/test_e6.py index afc4ed4d9a..5d42331710 100644 --- a/tests/dialects/test_e6.py +++ b/tests/dialects/test_e6.py @@ -1798,6 +1798,16 @@ def test_math(self): self.validate_all("SELECT LN(1)", read={"databricks": "SELECT ln(1)"}) + # DBR treats single-argument LOG(x) as natural log (base e); e6 needs an + # explicit base, so supply e = 2.718281828459045. + self.validate_all("SELECT LOG(2.718281828459045, a)", read={"databricks": "SELECT log(a)"}) + + # Two-argument LOG(base, value) is passed through unchanged. + self.validate_all("SELECT LOG(2, 8)", read={"databricks": "SELECT log(2, 8)"}) + + # A single-argument LOG parsed as an e6 Log node also gets the base. + self.validate_identity("SELECT LOG(a)", "SELECT LOG(2.718281828459045, a)") + def test_string(self): self.validate_all( "SELECT '%SystemDrive%/Users/John' LIKE '/%SystemDrive/%//Users%' ESCAPE '/'",