|
170 | 170 | "cell_type": "code",
|
171 | 171 | "execution_count": null,
|
172 | 172 | "id": "b082598f-acc8-47bc-b561-c0f07d059f4b",
|
173 |
| - "metadata": { |
174 |
| - "scrolled": true |
175 |
| - }, |
| 173 | + "metadata": {}, |
176 | 174 | "outputs": [],
|
177 | 175 | "source": [
|
178 | 176 | "%env CS_WORKSPACE_ID=<workspace_id>"
|
|
182 | 180 | "cell_type": "code",
|
183 | 181 | "execution_count": null,
|
184 | 182 | "id": "e01757fa-0d70-4d53-b33d-88bf02449d3c",
|
185 |
| - "metadata": { |
186 |
| - "scrolled": true |
187 |
| - }, |
| 183 | + "metadata": {}, |
188 | 184 | "outputs": [],
|
189 | 185 | "source": [
|
190 | 186 | "%env CS_CLIENT_ACCESS_KEY=<client_access_key>"
|
|
194 | 190 | "cell_type": "code",
|
195 | 191 | "execution_count": null,
|
196 | 192 | "id": "348e6430-dae7-4183-8eab-46315b622f1c",
|
197 |
| - "metadata": { |
198 |
| - "scrolled": true |
199 |
| - }, |
| 193 | + "metadata": {}, |
200 | 194 | "outputs": [],
|
201 | 195 | "source": [
|
202 | 196 | "%env CS_ENCRYPTION__CLIENT_ID=<client_id>"
|
|
206 | 200 | "cell_type": "code",
|
207 | 201 | "execution_count": null,
|
208 | 202 | "id": "e8ac364e-98a1-4687-b11e-4b935b6d8b70",
|
209 |
| - "metadata": { |
210 |
| - "scrolled": true |
211 |
| - }, |
| 203 | + "metadata": {}, |
212 | 204 | "outputs": [],
|
213 | 205 | "source": [
|
214 | 206 | "%env CS_ENCRYPTION__CLIENT_KEY=<client_key>"
|
|
814 | 806 | "# JSONB containment 1\n",
|
815 | 807 | "cur.execute(\"SELECT * from examples WHERE cs_ste_vec_v1(encrypted_jsonb) @> cs_ste_vec_v1(%s)\", (CsJsonb({'top': { 'nested': ['a', 'b'] } }, \"examples\", \"encrypted_jsonb\").to_db_format(\"ste_vec\"),))\n",
|
816 | 808 | "found = cur.fetchall()\n",
|
817 |
| - "for row in found:\n", |
818 |
| - " print(f\"Record Found with JSONB query: {CsRow(row).row}\\n\")\n", |
819 |
| - " print(f\"JSONB inside the found record: {CsJsonb.from_parsed_json(row['encrypted_jsonb'])}\\n\")" |
| 809 | + "for f in found:\n", |
| 810 | + " print(f\"Record Found with JSONB query: {CsRow(f).row}\\n\")\n", |
| 811 | + " print(f\"JSONB inside the found record: {CsJsonb.from_parsed_json(f['encrypted_jsonb'])}\\n\")" |
820 | 812 | ]
|
821 | 813 | },
|
822 | 814 | {
|
|
835 | 827 | "metadata": {},
|
836 | 828 | "outputs": [],
|
837 | 829 | "source": [
|
838 |
| - "# JSONB containment 1\n", |
| 830 | + "# JSONB containment 2\n", |
839 | 831 | "cur.execute(\"SELECT * from examples WHERE cs_ste_vec_v1(encrypted_jsonb) <@ cs_ste_vec_v1(%s)\", (CsJsonb({\"num\": 2, \"category\": \"b\", 'top': {'nested': ['a'] } }, \"examples\", \"encrypted_jsonb\").to_db_format(\"ste_vec\"),))\n",
|
840 | 832 | "found = cur.fetchall()\n",
|
841 |
| - "for row in found:\n", |
842 |
| - " print(f\"Record Found with JSONB query: {CsRow(row).row}\\n\")\n" |
| 833 | + "print(\"Record Found with JSONB query:\")\n", |
| 834 | + "for f in found:\n", |
| 835 | + " print(f\" {CsRow(f).row}\")" |
843 | 836 | ]
|
844 | 837 | },
|
845 | 838 | {
|
|
866 | 859 | "\n",
|
867 | 860 | "results = cur.execute(query, (CsText(\"$.top.nested\", \"examples\", \"encrypted_jsonb\").to_db_format(\"ejson_path\"),))\n",
|
868 | 861 | "\n",
|
869 |
| - "# TODO add extracting 'p'\n", |
870 |
| - "found = cur.fetchall()\n", |
871 |
| - "for row in found:\n", |
872 |
| - " print(f\"Record Found with JSONB query: {row}\\n\")\n" |
873 |
| - ] |
874 |
| - }, |
875 |
| - { |
876 |
| - "cell_type": "code", |
877 |
| - "execution_count": null, |
878 |
| - "id": "f753ce40-139a-4e0d-ba5f-3a284bc70b83", |
879 |
| - "metadata": {}, |
880 |
| - "outputs": [], |
881 |
| - "source": [ |
882 |
| - "# JSONB containment 1\n", |
883 |
| - "conn.rollback()\n", |
884 |
| - "cur.execute(\"SELECT cs_ste_vec_value_v1(encrypted_jsonb, %s) AS val FROM examples\",\n", |
885 |
| - " (CsText(\"$.top.nested\", \"examples\", \"encrypted_jsonb\").to_db_format(\"ejson_path\"),)\n", |
886 |
| - ")\n", |
887 | 862 | "found = cur.fetchall()\n",
|
888 |
| - "# TODO add extracting 'p'\n", |
889 |
| - "for row in found:\n", |
890 |
| - " print(f\"Record Found with JSONB query: {CsRow(row).row}\\n\")" |
| 863 | + "print(\"values from '$.top.nested':\")\n", |
| 864 | + "for f in found:\n", |
| 865 | + " print(f\" {CsRow(f).row.get('val', {}).get('p')}\")" |
891 | 866 | ]
|
892 | 867 | },
|
893 | 868 | {
|
|
916 | 891 | "\n",
|
917 | 892 | "found = cur.fetchall()\n",
|
918 | 893 | "\n",
|
919 |
| - "# TODO: extract 'p'\n", |
920 |
| - "for e in found:\n", |
921 |
| - " print(f\"Record Found with JSONB query: {CsRow(row).row}\\n\")" |
| 894 | + "for f in found:\n", |
| 895 | + " print(f\"Record Found with JSONB query: {CsRow(f).row}\\n\")" |
922 | 896 | ]
|
923 | 897 | },
|
924 | 898 | {
|
|
946 | 920 | " (CsText(\"$.num\", \"examples\", \"encrypted_jsonb\").to_db_format(\"ejson_path\"),)\n",
|
947 | 921 | ")\n",
|
948 | 922 | "found = cur.fetchall();\n",
|
949 |
| - "for e in found:\n", |
950 |
| - " print(f\"JSONB results: {e}\")" |
| 923 | + "print(\"JSONB contents, ordered by 'num' desc:\")\n", |
| 924 | + "for f in found:\n", |
| 925 | + " print(f\" {CsRow(f).row.get('encrypted_jsonb')}\")" |
951 | 926 | ]
|
952 | 927 | },
|
953 | 928 | {
|
|
978 | 953 | "\n",
|
979 | 954 | "found = cur.fetchall()\n",
|
980 | 955 | "\n",
|
981 |
| - "# TODO: exctract records\n", |
982 |
| - "for e in found:\n", |
983 |
| - " print(f\"JSONB results: {e}\")\n" |
| 956 | + "print(\"count, grouped by category:\")\n", |
| 957 | + "for f in found:\n", |
| 958 | + " row = CsRow(f).row\n", |
| 959 | + " print(f\" category: {row.get('category', {}).get('p')}, count: {row.get('count')}\")\n" |
984 | 960 | ]
|
985 | 961 | },
|
986 | 962 | {
|
|
0 commit comments