Skip to content

Commit

Permalink
fix(postgres): fix compilation of array string join and map/struct fi…
Browse files Browse the repository at this point in the history
…eld extraction
  • Loading branch information
cpcloud committed Mar 12, 2024
1 parent d2c1316 commit 306d0fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions ibis/backends/postgres/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def visit_StructField(self, op, *, arg, field):
#
# but also postgres should really support anonymous structs
return self.cast(
self.f.json_extract(self.f.to_jsonb(arg), sge.convert(f"f{idx:d}")),
self.f.jsonb_extract_path(self.f.to_jsonb(arg), sge.convert(f"f{idx:d}")),
op.dtype,
)

Expand All @@ -336,11 +336,18 @@ def visit_MapLength(self, op, *, arg):
return self.f.cardinality(self.f.akeys(arg))

def visit_MapGet(self, op, *, arg, key, default):
return self.if_(self.f.exist(arg, key), self.f.json_extract(arg, key), default)
return self.if_(
self.f.exist(arg, key),
self.f.jsonb_extract_path_text(self.f.to_jsonb(arg), key),
default,
)

def visit_MapMerge(self, op, *, left, right):
return sge.DPipe(this=left, expression=right)

def visit_ArrayStringJoin(self, op, *, arg, sep):
return self.f.anon.array_to_string(arg, sep)

def visit_TypeOf(self, op, *, arg):
typ = self.cast(self.f.pg_typeof(arg), dt.string)
return self.if_(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ WITH "t5" AS (
FROM (
SELECT
"t1"."field_of_study",
CAST(TO_JSONB("t1"."__pivoted__") -> 'f1' AS VARCHAR) AS "years",
CAST(TO_JSONB("t1"."__pivoted__") -> 'f2' AS BIGINT) AS "degrees"
CAST(JSONB_EXTRACT_PATH(TO_JSONB("t1"."__pivoted__"), 'f1') AS VARCHAR) AS "years",
CAST(JSONB_EXTRACT_PATH(TO_JSONB("t1"."__pivoted__"), 'f2') AS BIGINT) AS "degrees"
FROM (
SELECT
"t0"."field_of_study",
Expand Down

0 comments on commit 306d0fc

Please sign in to comment.