Creating JSON Tables with the MapR-DB OJAI Java API Library
Create a JSON table
by calling an Admin
object's createTable()
method, passing as
an argument the path that you want to use for the new table.
Example
public void createJSONTable(String tablePath) throws DBException {
try (Admin admin = MapRDB.newAdmin()) {
if (!admin.tableExists(tablePath)) {
admin.createTable(tablePath).close();
}
}
}
createTable()
method used in this
example use the default values for their attributes. Tables created with another version of
the create()
method take a TableDescriptor
object as an
argument. Before passing that object to the method, you can set values for some of a table's
attributes.
/* Create a TableDescriptor for the table to create,
passing in the path of the table. */
TableDescriptor tableDescriptor = MapRDB.newTableDescriptor(tablePath)
.setBulkLoad(true);
/* Pass the TableDescriptor object and the path to the table
to the Admin.createTable() method. */
public void createJSONTable(String tablePath, TableDescriptor tableDescriptor) throws DBException {
try (Admin admin = MapRDB.newAdmin()) {
if (!admin.tableExists(tablePath)) {
admin.createTable(tableDescriptor).close();
}
}
}
For
more information, see Admin
and TableDescriptor
in the Javadoc.