Skip to content

Commit 02d9442

Browse files
committed
Correct some issues in jupyter notebook
1 parent 408b886 commit 02d9442

File tree

1 file changed

+23
-47
lines changed

1 file changed

+23
-47
lines changed

languages/python/jupyter_notebook/CipherStash-Getting-Started.ipynb

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@
170170
"cell_type": "code",
171171
"execution_count": null,
172172
"id": "b082598f-acc8-47bc-b561-c0f07d059f4b",
173-
"metadata": {
174-
"scrolled": true
175-
},
173+
"metadata": {},
176174
"outputs": [],
177175
"source": [
178176
"%env CS_WORKSPACE_ID=<workspace_id>"
@@ -182,9 +180,7 @@
182180
"cell_type": "code",
183181
"execution_count": null,
184182
"id": "e01757fa-0d70-4d53-b33d-88bf02449d3c",
185-
"metadata": {
186-
"scrolled": true
187-
},
183+
"metadata": {},
188184
"outputs": [],
189185
"source": [
190186
"%env CS_CLIENT_ACCESS_KEY=<client_access_key>"
@@ -194,9 +190,7 @@
194190
"cell_type": "code",
195191
"execution_count": null,
196192
"id": "348e6430-dae7-4183-8eab-46315b622f1c",
197-
"metadata": {
198-
"scrolled": true
199-
},
193+
"metadata": {},
200194
"outputs": [],
201195
"source": [
202196
"%env CS_ENCRYPTION__CLIENT_ID=<client_id>"
@@ -206,9 +200,7 @@
206200
"cell_type": "code",
207201
"execution_count": null,
208202
"id": "e8ac364e-98a1-4687-b11e-4b935b6d8b70",
209-
"metadata": {
210-
"scrolled": true
211-
},
203+
"metadata": {},
212204
"outputs": [],
213205
"source": [
214206
"%env CS_ENCRYPTION__CLIENT_KEY=<client_key>"
@@ -814,9 +806,9 @@
814806
"# JSONB containment 1\n",
815807
"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",
816808
"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\")"
820812
]
821813
},
822814
{
@@ -835,11 +827,12 @@
835827
"metadata": {},
836828
"outputs": [],
837829
"source": [
838-
"# JSONB containment 1\n",
830+
"# JSONB containment 2\n",
839831
"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",
840832
"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}\")"
843836
]
844837
},
845838
{
@@ -866,28 +859,10 @@
866859
"\n",
867860
"results = cur.execute(query, (CsText(\"$.top.nested\", \"examples\", \"encrypted_jsonb\").to_db_format(\"ejson_path\"),))\n",
868861
"\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",
887862
"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')}\")"
891866
]
892867
},
893868
{
@@ -916,9 +891,8 @@
916891
"\n",
917892
"found = cur.fetchall()\n",
918893
"\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\")"
922896
]
923897
},
924898
{
@@ -946,8 +920,9 @@
946920
" (CsText(\"$.num\", \"examples\", \"encrypted_jsonb\").to_db_format(\"ejson_path\"),)\n",
947921
")\n",
948922
"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')}\")"
951926
]
952927
},
953928
{
@@ -978,9 +953,10 @@
978953
"\n",
979954
"found = cur.fetchall()\n",
980955
"\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"
984960
]
985961
},
986962
{

0 commit comments

Comments
 (0)