Skip to content

Commit

Permalink
fix json test
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwpark authored and aljazerzen committed Oct 17, 2024
1 parent 90f4a91 commit d97bdf3
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions edb/edgeql/compiler/casts.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,34 @@ def _cast_json_to_tuple(
"error_message_context": error_message_context
})
))
json_objects = qlast.FunctionCall(
func=('__std__', '__tuple_validate_json'),
args=json_object_args

# Don't validate NULLs. They are filtered out with the json nulls.
json_objects = qlast.IfElse(
condition=qlast.UnaryOp(
op='EXISTS',
operand=source_path,
),
if_expr=qlast.FunctionCall(
func=('__std__', '__tuple_validate_json'),
args=json_object_args,
),
else_expr=qlast.TypeCast(
expr=qlast.Set(elements=[]),
type=typegen.type_to_ql_typeref(orig_stype, ctx=ctx),
),
)

# Filter out json nulls.
json_objects_ir = dispatch.compile(json_objects, ctx=subctx)

with ctx.new() as subctx:
pathctx.register_set_in_scope(json_objects_ir, ctx=subctx)
subctx.anchors = subctx.anchors.copy()
source_path = subctx.create_anchor(json_objects_ir, 'a')

# Filter out json nulls and postgress NULLs.
# Nulls at the top level cast can be ignored.
filtered = qlast.SelectQuery(
result=json_objects,
result=source_path,
where=qlast.BinOp(
left=qlast.FunctionCall(
func=('__std__', 'json_typeof'), args=[source_path]
Expand Down

0 comments on commit d97bdf3

Please sign in to comment.