{ "cells": [ { "cell_type": "markdown", "id": "1334d92e-34f4-448c-b6af-73cba89e9d6d", "metadata": {}, "source": [ "# PyKX Clear RDB\n", "This notebook simple clears entries in the example table." ] }, { "cell_type": "code", "execution_count": 1, "id": "e967b617-5a18-4440-a60b-9039d2d18a20", "metadata": {}, "outputs": [], "source": [ "# scratch location \n", "scratch_path = \"/opt/kx/app/scratch\"\n", "\n", "# clean rdb?\n", "clear_rdb = True" ] }, { "cell_type": "code", "execution_count": 2, "id": "037529a7-c783-47d6-9da0-f2e8f1cfad4f", "metadata": {}, "outputs": [], "source": [ "import warnings\n", "warnings.simplefilter(action='ignore', category=FutureWarning)\n", "\n", "import os\n", "import boto3\n", "import json\n", "import datetime\n", "\n", "import pykx as kx\n", "\n", "from managed_kx import *\n", "from env_kdb_1 import *\n", "\n", "from basictick_setup import *" ] }, { "cell_type": "code", "execution_count": 3, "id": "413b90b2-0b9f-45f5-a1ff-acb5315c6249", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Using variables ...\n" ] } ], "source": [ "# triggers credential get\n", "session=None\n", "\n", "try:\n", " # aws: use ada for credentials\n", " subprocess.call([\"which\", \"ada\"])\n", " os.system(f\"ada credentials update --account={ACCOUNT_ID} --provider=isengard --role=Admin --once\")\n", "except: \n", " None\n", "\n", "if AWS_ACCESS_KEY_ID is None:\n", " print(\"Using Defaults ...\")\n", " # create AWS session: using access variables\n", " session = boto3.Session()\n", "else:\n", " print(\"Using variables ...\")\n", " session = boto3.Session(\n", " aws_access_key_id=AWS_ACCESS_KEY_ID,\n", " aws_secret_access_key=AWS_SECRET_ACCESS_KEY,\n", " aws_session_token=AWS_SESSION_TOKEN\n", " )\n", "\n", "# create finspace client\n", "client = session.client(service_name='finspace', endpoint_url=ENDPOINT_URL)" ] }, { "cell_type": "markdown", "id": "08c3a170-3da2-483d-af7e-e66ce6d16488", "metadata": {}, "source": [ "# Connect and Clear" ] }, { "cell_type": "code", "execution_count": 4, "id": "bd1b27af-82e1-4ab9-b26e-eff89db69a37", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Clearing: RDB_basictickdb\n", "BEFORE Rows: 5,388,510\n", "AFTER Rows: 0\n", "** Done **\n" ] } ], "source": [ "print (f\"Clearing: {RDB_CLUSTER_NAME}\")\n", "\n", "# Connect to the RDB cluster\n", "rdb = get_pykx_connection(client, \n", " environmentId=ENV_ID, clusterName=RDB_CLUSTER_NAME, \n", " userName=KDB_USERNAME, boto_session=session)\n", "\n", "\n", "rdb_rows = rdb(\"count example\").py()\n", "\n", "# Number of Rows\n", "print(f\"BEFORE Rows: {rdb_rows:,}\")\n", "\n", "\n", "# remove tables\n", "ret = rdb(\"delete from `example\")\n", "\n", "rdb_rows = rdb(\"count example\").py()\n", "\n", "# Number of Rows\n", "print(f\"AFTER Rows: {rdb_rows:,}\")\n", "\n", "print(\"** Done **\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "38f790d8-81c3-4e4d-8aae-81e4dcde476a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last Run: 2023-07-26 17:20:31.961010\n" ] } ], "source": [ "print( f\"Last Run: {datetime.datetime.now()}\" )" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }