Skip to content

Commit bc403af

Browse files
committed
Fix bpchar tag hashing in DNF queries
1 parent f8a0af5 commit bc403af

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎packages/sync-service/lib/electric/shapes/querying.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ defmodule Electric.Shapes.Querying do
548548
end
549549

550550
defp tag_slot_sql(%{is_subquery: true, tag_columns: [col]}, stack_id, shape_handle) do
551-
col_sql = ~s["#{col}"::text]
551+
col_sql = pg_cast_column_to_text(col)
552552
namespaced = pg_namespace_value_sql(col_sql)
553553
~s[md5('#{stack_id}#{shape_handle}' || #{namespaced})]
554554
end
@@ -560,7 +560,7 @@ defmodule Electric.Shapes.Querying do
560560
) do
561561
column_parts =
562562
Enum.map(cols, fn col_name ->
563-
col = ~s["#{col_name}"::text]
563+
col = pg_cast_column_to_text(col_name)
564564
~s['#{col_name}:' || #{pg_namespace_value_sql(col)}]
565565
end)
566566

‎packages/sync-service/test/electric/shapes/querying_test.exs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Electric.Shapes.QueryingTest do
66
alias Electric.Postgres.Inspector.DirectInspector
77
alias Electric.Shapes.Querying
88
alias Electric.Shapes.Shape
9+
alias Electric.Shapes.SubqueryTags
910

1011
@refs %{
1112
["id"] => :int4,
@@ -607,6 +608,18 @@ defmodule Electric.Shapes.QueryingTest do
607608
)
608609
|> fill_handles()
609610

611+
tag1 = SubqueryTags.make_value_hash("dummy-stack-id", "dummy-shape-handle", "ab ")
612+
tag2 = SubqueryTags.make_value_hash("dummy-stack-id", "dummy-shape-handle", "cd ")
613+
614+
assert [
615+
%{value: %{parent_id: "ab "}, headers: %{tags: [^tag1]}},
616+
%{value: %{parent_id: "cd "}, headers: %{tags: [^tag2]}},
617+
%{value: %{parent_id: "ef "}, headers: %{tags: [_]}}
618+
] =
619+
decode_stream(
620+
Querying.stream_initial_data(conn, "dummy-stack-id", "dummy-shape-handle", shape)
621+
)
622+
610623
{:ok, dnf_plan} = DnfPlan.compile(shape)
611624
move_in_values = ["ab ", "cd "]
612625
views_before_move = %{["$sublink", "0"] => MapSet.new()}
@@ -622,8 +635,8 @@ defmodule Electric.Shapes.QueryingTest do
622635
)
623636

624637
assert [
625-
%{value: %{parent_id: "ab "}},
626-
%{value: %{parent_id: "cd "}}
638+
%{value: %{parent_id: "ab "}, headers: %{tags: [^tag1]}},
639+
%{value: %{parent_id: "cd "}, headers: %{tags: [^tag2]}}
627640
] =
628641
Querying.query_move_in(
629642
conn,

0 commit comments

Comments
 (0)