<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;[Tutorial Title]¶1.1&nbsp;&nbsp;Introduction1.2&nbsp;&nbsp;Prerequisites1.3&nbsp;&nbsp;Initialization1.3.1&nbsp;&nbsp;Ensure database is running1.3.2&nbsp;&nbsp;Download and install additional components.1.3.3&nbsp;&nbsp;Connect to database.1.3.4&nbsp;&nbsp;Populate database with test data.1.3.5&nbsp;&nbsp;Create secondary indexes if necessary2&nbsp;&nbsp;[Tutorial Section]2.1&nbsp;&nbsp;[Subsection 1]2.2&nbsp;&nbsp;[Subsection 2]3&nbsp;&nbsp;[Next Section]3.1&nbsp;&nbsp;[Subsection 1]3.2&nbsp;&nbsp;[Subsection 2]4&nbsp;&nbsp;Takeaways and Conclusion5&nbsp;&nbsp;Clean up6&nbsp;&nbsp;Further Exploration and Resources6.1&nbsp;&nbsp;Next steps **How To Create Aerospike Tutorial in Jupyter Notebook:**- Use the template below and customize the square-bracketed text in the template for your needs. Omit them if appropriate.- Code cells in this notebook are not meant to run; they are provided for illustrative purpose only. When both Python and Java code cells are presented, use the appropriate one and delete the other. - Leverage Jupyter Notebook style to build the tutorial through specific incremental goals. Avoid large markdown and code cells; instead break them down into multiple bite-sized cells.- Create a TOC level map of goals and points. Decribe the code examples without code. Get the flow and examples reviewed before finalizing the details of content and code. Check for spelling, typos, and other errors. Get the final version reviewed before publishing the notebook.- Provide local notebook links when possible as local links run on click, but remote notebooks must be downloaded first.- Use a unique set name in "test" namespace to populate each tutorial's data. Only modify data within this set without affecting the rest of the database. It is a good practice to clean up this set at the end.- Explore the extensions TOC (accessible from the header icon), collapsible headers, and scratchpad (arrow icon at right bottom). Cofigure and save as you would like the user to experience when they open the notebook first. For example, TOC at top, all headers collapsed, etc. Consider configuring TOC extension to have a TOC cell at the top.- Name the notebook appropriately and check it into appropriate repo, such as under [this notebooks directory](https://github.com/aerospike/aerospike-dev-notebooks.docker/tree/main/notebooks). Execute all cells before checking into the repo so that the notebook may be read completely as a blog post with its output visible in the non-interactive github viewer.   [Tutorial Title][A brief description of the topic and goals of the tutorial.]This notebook requires Aerospike datbase running on localhost and that python and the Aerospike python client have been installed (`pip install aerospike`). Visit [Aerospike notebooks repo](https://github.com/aerospike-examples/interactive-notebooks) for additional details and the docker container.  Introduction[Describe what the developer will learn and how.][Why is this topic relevant and important.][The structure and flow. Tips for skipping basic sections or for returning users.]  PrerequisitesThis tutorial assumes familiarity with the following topics:[Provide topics and links. For example:]- [Hello World](hello_world.ipynb)- [Aerospike Basic Operations](basic_operations.ipynb)- [Another area]  Initialization  Ensure database is runningThis notebook requires that Aerospike datbase is running. [Include the right code cell for Java or Python from the two cells below.]<jupyter_code>import io.github.spencerpark.ijava.IJava;
import io.github.spencerpark.jupyter.kernel.magic.common.Shell;
IJava.getKernelInstance().getMagics().registerMagics(Shell.class);
%sh asd
!asd >& /dev/null
!pgrep -x asd >/dev/null && echo "Aerospike database is running!" || echo "**Aerospike database is not running!**"<jupyter_output><empty_output><jupyter_text>Download and install additional components.[For Java notebooks, the latest Java client should be loaded here by including the following code cell. Specify the correct version. This section can be omitted for Python notebooks as a Python client is already installed.]<jupyter_code>%%loadFromPOM
<dependencies>
  <dependency>
    <groupId>com.aerospike</groupId>
    <artifactId>aerospike-client</artifactId>
    <version>[specify the Java client version here, e.g., 5.0.0]</version>
  </dependency>
</dependencies><jupyter_output><empty_output><jupyter_text>Connect to database.[Most developer tutorials need a client to be connected to the database. Use the right cell and change the parameters as needed.]<jupyter_code>import com.aerospike.client.AerospikeClient;
AerospikeClient client = new AerospikeClient("localhost", 3000);
System.out.println("Initialized the client and connected to the cluster.");
# import the module
from __future__ import print_function
import aerospike

# Configure the client
config = {
  'hosts': [ ('127.0.0.1', 3000) ],
  'policy' : {'key': aerospike.POLICY_KEY_SEND}
}

# Create a client and connect it to the cluster
try:
  client = aerospike.client(config).connect()
except:
  import sys
  print("failed to connect to the cluster with", config['hosts'])
  sys.exit(1)
print('Client successfully connected to the database.')<jupyter_output><empty_output><jupyter_text>Populate database with test data.[Remove this section if the tutorial does not need the database to be populated with test data.][This can be done with code or using the cvsloader utility.][Describe the test data and intent. The cells below are only examples - replace with your own data.]<jupyter_code>import com.aerospike.client.policy.ClientPolicy;

String Namespace = "test";
String Set = "my-unique-set";
String BinInt = "binint";
String BinStr = "binstr";
int NumRecords = 10;

String Names[] = {"<NAME>", "2. Keenan", "<NAME>", "<NAME>", "5. Clark", 
                "6. Jones", "7. Iyer", "8. Smith", "9. Hernandez", "10. Smith"};

ClientPolicy policy = new ClientPolicy();
for (int i = 1; i <= NumRecords; i++) {
    Key key = new Key(Namespace, Set, i);
    Bin bin1 = new Bin(BinInt, i);
    Bin bin2 = new Bin(BinStr, Names[i-1]);
    client.put(policy.writePolicyDefault, key, bin1, bin2);
}

System.out.format("Written %d records in ns=%s set=%s with userkeys 1-%d.",
                  NumRecords, Namespace, Set, NumRecords);
namespace = 'test'
tutorial_set = 'my-unique-set'
# Records are addressable via a tuple of (namespace, set, key)
people = [ {'id':1, 'name':'<NAME>', 'age': 53},
           {'id':2, 'name':'<NAME>', 'age': 21},
           {'id':3, 'name':'<NAME>', 'age': 34},
           {'id':4, 'name':'<NAME>', 'age': 48},
           {'id':5, 'name':'<NAME>', 'age': 29},
           {'id':6, 'name':'<NAME>', 'age': 56},
           {'id':7, 'name':'<NAME>', 'age': 30},
           {'id':8, 'name':'<NAME>', 'age': 32},
           {'id':9, 'name':'<NAME>', 'age': 44},
           {'id':10, 'name':'<NAME>', 'age': 22} ]
try:
    for i in range(10):
      # Write the records
      client.put((namespace, tutorial_set, 'id'+str(people[i]['id'])), people[i])
except Exception as e:
  import sys
  print("error: {0}".format(e), file=sys.stderr)

print('Test data populated.')<jupyter_output><empty_output><jupyter_text>Create secondary indexes if necessary[To use the query API, a secondary index must exist on the query field.][Replace or remove the code cell as appropriate.]<jupyter_code>import com.aerospike.client.policy.Policy;
import com.aerospike.client.query.IndexType;
import com.aerospike.client.task.IndexTask;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.ResultCode;

String IndexName = "idx_numeric_test_demo_binint";

Policy policy = new Policy();
policy.socketTimeout = 0; // Do not timeout on index create.

try {
    IndexTask task = client.createIndex(policy, Namespace, Set, IndexName, 
                                        BinInt, IndexType.NUMERIC);
    task.waitTillComplete();
}
catch (AerospikeException ae) {
    if (ae.getResultCode() != ResultCode.INDEX_ALREADY_EXISTS) {
        throw ae;
    }
}

System.out.format("Created index %s on ns=%s set=%s bin=%s.", 
                                    IndexName, Namespace, Set, BinInt);
# Must create an index to query on a bin
index_name = "test_demo_number_idx"
from aerospike import exception as ex
try:
    client.index_integer_create(Namespace, Set, "age", index_name)
except ex.IndexFoundError:
    pass

print('Secondary index created.')<jupyter_output><empty_output><jupyter_text>[Tutorial Section][Section of the core of the tutorial.]  [Subsection 1][Subsection 1]  [Subsection 2][Subsection 2]  [Next Section][Next section.]  [Subsection 1][Subsection 1]  [Subsection 2][Subsection 2]  Takeaways and Conclusion[Summarize the takeaways and conclusion of the tutorial.]  Clean up[Perform any cleanup - remove data, close connection, etc.]<jupyter_code>client.dropIndex(policy, Namespace, Set, IndexName);
client.truncate(null, Namespace, Set)
client.close();
System.out.println("Removed tutorial data and server connection closed.");
client.index_remove(namespace, index_name)¶
client.truncate(namespace, tutorial_set, 0)
# Close the connection to the Aerospike cluster
client.close()
print('Removed tutorial data. Connection closed.')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11188586140313238, 'fraction_numerical': 0.012872774082814847, 'mean_word_length': 4.856155778894473, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 50, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '510820', 'license': 'Apache-2.0', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2646, 'n_words': 985, 'path': 'notebooks/nb-template.ipynb', 'repo_name': 'artanderson/experiments', 'size': '9358'}