summaryrefslogtreecommitdiffstats
path: root/tests/test_optimizer.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 16:34:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-11 16:34:56 +0000
commit278f416d08028bd175e1d6433739461f2168f4e2 (patch)
tree12492ebc5907744b2a4297228324fcda9ee2e40f /tests/test_optimizer.py
parentAdding upstream version 24.1.0. (diff)
downloadsqlglot-278f416d08028bd175e1d6433739461f2168f4e2.tar.xz
sqlglot-278f416d08028bd175e1d6433739461f2168f4e2.zip
Adding upstream version 25.0.3.upstream/25.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_optimizer.py')
-rw-r--r--tests/test_optimizer.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/test_optimizer.py b/tests/test_optimizer.py
index 7ec0872..41a5015 100644
--- a/tests/test_optimizer.py
+++ b/tests/test_optimizer.py
@@ -10,6 +10,7 @@ import sqlglot
from sqlglot import exp, optimizer, parse_one
from sqlglot.errors import OptimizeError, SchemaError
from sqlglot.optimizer.annotate_types import annotate_types
+from sqlglot.optimizer.normalize import normalization_distance
from sqlglot.optimizer.scope import build_scope, traverse_scope, walk_in_scope
from sqlglot.schema import MappingSchema
from tests.helpers import (
@@ -1214,3 +1215,11 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
query = parse_one("select a.b:c from d", read="snowflake")
qualified = optimizer.qualify.qualify(query)
self.assertEqual(qualified.expressions[0].alias, "c")
+
+ def test_normalization_distance(self):
+ def gen_expr(depth: int) -> exp.Expression:
+ return parse_one(" OR ".join("a AND b" for _ in range(depth)))
+
+ self.assertEqual(4, normalization_distance(gen_expr(2), max_=100))
+ self.assertEqual(18, normalization_distance(gen_expr(3), max_=100))
+ self.assertEqual(110, normalization_distance(gen_expr(10), max_=100))