As part of its support for JSON tables, MapR Database implements the OJAI API. The OJAI API provides methods for creating, reading, updating, and deleting JSON documents
in MapR Database JSON tables. It is available in Java, and starting in MEP 6.0, Node.js, and Python. MapR Database also provides a MapR Database JSON Client API for managing JSON tables and a MapR Database JSON REST API for performing basic operations using HTTP calls.

This section describes how to create, list, and delete JSON tables, alter JSON table attributes, set permissions, and
manage column families. You can perform these operations using either the MapR Database JSON Client API library or MapR Database Shell commands.

Before you start developing applications on MapR’s Converged Data Platform, consider how you will get the data onto the
platform, the format it will be stored in, the type of processing or modeling that is required, and how the data will
be accessed.

The mapr-client package must be installed on each node where you will be building and running your applications. This package installs
all of the MapR Libraries needed for application development regardless of programming language or type of MapR Database table (binary or JSON).

This topic describes the methods for passing a MapR Database table name. Binary table names can be passed by either specifying the table path in the API or by setting the table
path in the core-site.xml file. JSON table names are passed by specifying the table path in the API.

As part of its support for JSON tables, MapR Database implements the OJAI API. The OJAI API provides methods for creating, reading, updating, and deleting JSON documents
in MapR Database JSON tables. It is available in Java, and starting in MEP 6.0, Node.js, and Python. MapR Database also provides a MapR Database JSON Client API for managing JSON tables and a MapR Database JSON REST API for performing basic operations using HTTP calls.

This section describes how to create, list, and delete JSON tables, alter JSON table attributes, set permissions, and
manage column families. You can perform these operations using either the MapR Database JSON Client API library or MapR Database Shell commands.

This section describes how to query JSON documents in MapR Database JSON tables using the OJAI API library and MapR Database Shell. It includes sample programs using the OJAI API library and shows how to run the same queries in MapR Database Shell.

This section describes how to query JSON documents using either the find or findbyid command in MapR Database Shell (dbshell). It introduces the functionality the find command supports and describes the two ways to specify your queries. It also provides links to reference pages and
examples.

This section provides query examples using the OJAI API. The examples include querying by document ID, retrieving all
documents in a store, selecting individual fields, specifying query conditions, and ordering your query result. For reference,
the examples also include the equivalent MapR Database Shell (dbshell) commands.

This topic describes MapR Database functionality that is applicable to only the Java OJAI client. This includes instructions on how to compile your Java
OJAI application, enable buffered writes, use the read your own writes feature, and enable available query options.

Starting with MEP 6.0, you can use the Node.js OJAI client to write MapR Database JSON applications. The client provides you with a lightweight library that supports the OJAI API. You can connect
to MapR Database JSON from middleware components, and add, update, and query documents in a MapR Database JSON table.

Starting with MEP 6.0, you can use the Python OJAI client to write MapR Database JSON applications. The client provides you with a lightweight library that supports the OJAI API. You can connect
to MapR Database JSON, and add, update, and query documents in a MapR Database JSON table.

MapR supports public APIs for MapR Filesystem, MapR Database, and MapR Event Store For Apache Kafka. These APIs are available for application development purposes.

Setting TTL for Data

You can delete stale JSON documents in JSON tables automatically by setting a
time-to-live (TTL) value on the column family.

TTL is set only on the default column family in a JSON table. The duration that you set
applies to each entire JSON document in the JSON table.

Note: Only the default column family can exist in order to set TTL; no other column families
can exist in the JSON table. You also cannot set the TTL for a JSON table if it has
secondary indexes.

Data can become stale. If the data in an JSON document has not been updated within a
certain period of time, you might want to delete the document. In the case of a large amount
of JSON documents, applications should not have to track the time between updates and then
delete the expired documents.

Because the time-to-live that is set on a column family affects an entire JSON table, only
the default column family is allowed to have a non-default time-to-live value. In addition,
to prevent multiple column families from having non-default time-to-live values, additional
column families can not be created in a table if the default column family has a non-default
value. This is because if more than one column family had a non-default TTL value, fragments
of documents would expire at different times, leading to inconsistent views of data.

Permission Required

The writeAce permission on the volumes where the JSON tables are located.
For information about how to set
permissions on volumes, see Setting Whole Volume ACEs.

Example: Setting the default column family to a non-default time-to-live
value

If you set the time-to-live parameter for the default column family to 864,000
seconds, JSON documents in that table are considered to be stale if the document's data has
not been updated within 10 days and are automatically deleted.

The following code example
creates a JSON table, the default column family and sets the TTL to a non-default value of
10 days (864,000 seconds).

/* Create a TableDescriptor for the table to create,
passing in the path of the table. */
TableDescriptor tableDescriptor = MapRDB.newTableDescriptor(tablePath);
/* Create a FamilyDescriptor for the default column family.
When you create a table with the API, you must also create
the default column family.
Set the TTL to 10 days.
After creating the FamilyDescriptor, add it to
the TableDescriptor. */
FamilyDescriptor defaultfamilyDesc = MapRDB.newDefaultFamilyDescriptor()
.setTTL(864000);
tableDescriptor.addFamily(defaultfamilyDesc);
// Pass the TableDescriptor to the Admin.createTable() method.publicvoid createJSONTable(String tablePath, TableDescriptor tableDescriptor) throws DBException {
try (Admin admin = MapRDB.newAdmin()) {
if (!admin.tableExists(tablePath)) {
admin.createTable(tableDescriptor);
}
}
}