Using and Setting Namespaces

Once you have created one or more namespaces, and tables within them, you can fully qualify table names in any references. If your store has tables with the same name, the namespace differentiates them from each other.

Here is the syntax for specifying a fully qualified table, or child table name from the CLI:
namespace:tablename
namespace:tablename.child1
To reference a table in a namespace in a SELECT statement:
SELECT * FROM ns1:table1;

Set Namespace for Method Execution

You can use the ExecuteOptions.setNamespace method to set a default namespace for the duration of a KVStore.execute() method. While set, you do not need to qualify table and other object references. If you do not use setNamespace, or fully qualify table names, the store uses sysdefault as the default namespace.

ExecuteOptions.setNamespace("ns1");
SELECT * FROM table1; 

Determine Table Namespace

To find out which namespace was set on an option object, use the ExecuteOptions.getNamespace method.

Get a Table in a Specific Namespace

You can call TableAPI.getTable() with two arguments:
TableAPI.getTable(String namespace, String tableFullName); 
Here, the first argument for TableAPI.getTable method, namespace, is the namespace in which you created the table. If this argument is NULL, the method uses the default sysdefault namespace. This case is equivalent to calling the function with a single argument, described next.

The second argument, tableFullName, is the full table name. This interface retrieves only top-level tables, without parent tables. To retrieve child tables, use TableAPI.getChildTable().

Get a Fully-Qualified Table

You can call TableAPI.getTable() with one argument:

TableAPI.getTable(String fullNamespaceName); 

The fullNamespaceName argument indicates the full name or namespace-qualified name of the target table. If you supply an unqualified name, the method uses the sysdefault namespace. If you supply a namespace that contains a table name prefixed with a namespace followed with a colon (namespace:), this usage is equivalent to calling the function as getTable(String,String) with the namespace, and TableFullName described above.