Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/sqlbuild/compiler/compile/_helpers/analysis/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
from sqlbuild.compiler.sql_analysis.constants import (
POLYGLOT_ANALYSIS_UPSTREAM as _POLYGLOT_ANALYSIS_UPSTREAM,
)
from sqlbuild.compiler.sql_analysis.constants import (
POLYGLOT_BOOLEAN_RESULT_KINDS as _POLYGLOT_BOOLEAN_RESULT_KINDS,
)
from sqlbuild.compiler.sql_analysis.constants import (
POLYGLOT_CAST_KINDS as _POLYGLOT_CAST_KINDS,
)
Expand Down Expand Up @@ -165,6 +168,9 @@
from sqlbuild.compiler.sql_analysis.constants import (
POLYGLOT_KIND_COUNT as _POLYGLOT_KIND_COUNT,
)
from sqlbuild.compiler.sql_analysis.constants import (
POLYGLOT_KIND_IS_NULL as _POLYGLOT_KIND_IS_NULL,
)
from sqlbuild.compiler.sql_analysis.constants import (
POLYGLOT_KIND_LITERAL as _POLYGLOT_KIND_LITERAL,
)
Expand Down Expand Up @@ -1280,6 +1286,8 @@ def _polyglot_expression_type(
)
if function_type is not None:
return function_type
if kind in _POLYGLOT_BOOLEAN_RESULT_KINDS:
return "BOOLEAN"
if kind not in _POLYGLOT_CAST_KINDS:
return None
payload: object = expression.to_dict().get(kind, {})
Expand Down Expand Up @@ -1364,6 +1372,8 @@ def _infer_polyglot_nullability(
return InferredNullability.UNKNOWN
if kind == _POLYGLOT_KIND_COUNT:
return InferredNullability.NON_NULL
if kind == _POLYGLOT_KIND_IS_NULL:
return InferredNullability.NON_NULL
if kind == _POLYGLOT_KIND_COALESCE:
child_nullabilities: list[InferredNullability] = [
_infer_polyglot_nullability(
Expand Down Expand Up @@ -1408,6 +1418,8 @@ def _infer_polyglot_shallow_nullability(
return InferredNullability.NON_NULL
if kind == _POLYGLOT_KIND_COUNT:
return InferredNullability.NON_NULL
if kind == _POLYGLOT_KIND_IS_NULL:
return InferredNullability.NON_NULL
if kind == _POLYGLOT_KIND_COLUMN:
return InferredNullability.UNKNOWN
if kind == _POLYGLOT_KIND_CAST:
Expand Down
1 change: 1 addition & 0 deletions src/sqlbuild/compiler/sql_analysis/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"ilike",
"in",
"is",
POLYGLOT_KIND_IS_NULL,
"like",
"lt",
"lte",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,18 @@
),
),
),
InferColumnsTestCase(
description="infers null predicates as non-null booleans",
query_sql=('SELECT status IS NOT NULL AS has_status FROM __ref("orders")'),
column_nullability_by_table={"orders": {"status": InferredNullability.NULLABLE}},
expected_columns=(
InferredColumn(
name="has_status",
type="BOOLEAN",
nullability=InferredNullability.NON_NULL,
),
),
),
InferColumnsTestCase(
description="refines filtered CTE output nullability",
query_sql=(
Expand Down
Loading