We need to create a table to store your bajillion phonebook contacts. Creating a table in Kiji amounts to specifying a layout and registering that layout with Kiji. Layouts can be specified using the Kiji Data Definition Language, DDL, or in a JSON form. The DDL is the easiest and most well-supported mechanism to use; we will introduce it first.

Using the DDL

We assume that you have kiji-schema-shell installed. If not, you should consult the Get Started section of the Kiji website.

We have provided the phonebook layout in the $KIJI_HOME/examples/phonebook/layout.ddl file. For more information about how to create this file, see the DDL Shell Reference.

$KIJI_HOME/schema-shell/bin/kiji-schema-shell \


Enter the KijiSchema shell using the following command:


Use the show tables and describe commands to see your newly created table.

schema> show tables;
Table       Description
=========   ==================================
phonebook   A collection of phone book entries
schema> describe phonebook;
Table: phonebook (A collection of phone book entries)
Row key:

Column family: info
    Description: basic information

    Column info:firstname (First name)
        Schema: "string"

    Column info:lastname (Last name)
        Schema: "string"

    Column info:email (Email address)
        Schema: "string"

    Column info:telephone (Telephone number)
        Schema: "string"

    Column info:address (Street address)
        Schema: "org.kiji.examples.phonebook.Address"

Column family: derived
    Description: Information derived from an individual's address.

    Column derived:addr1 (Address line one.)
        Schema: "string"

    Column derived:apt (Address Apartment number.)
        Schema: ["string","null"]

    Column derived:addr2 (Address line two.)
        Schema: "string"

    Column derived:city (Address city.)
        Schema: "string"

    Column derived:state (Address state.)
        Schema: "string"

    Column derived:zip (Address zip code.)
        Schema: "int"

Column family: stats
    Description: Statistics about a contact.

    Column stats:talktime (Time spent talking with this person)
        Schema: (counter)
schema> quit;

Using JSON

A low level way of providing the layout is by using JSON. To learn more about specifying the layout in JSON, take a look at Managing Data.

The raw JSON view of table layouts is intended for use by system administrators, or for low-level debugging purposes. Most users should use the kiji-schema-shell DDL tool to modify table layouts instead. But for completeness, we introduce the “raw” layout tool here as well.

First, we need to delete the table we just created, so that we can create it another time using JSON. Use the following command to delete the table:

$KIJI_HOME/bin/kiji delete --target=kiji://.env/default/phonebook
Are you sure you want to delete Kiji table 'kiji://localhost:2181/default/phonebook/'?
Please answer yes or no.
13/03/13 19:19:28 INFO org.apache.hadoop.hbase.client.HBaseAdmin: Started disable of kiji.default.table.phonebook
13/03/13 19:19:29 INFO org.apache.hadoop.hbase.client.HBaseAdmin: Disabled kiji.default.table.phonebook
13/03/13 19:19:29 INFO org.apache.hadoop.hbase.client.HBaseAdmin: Deleted kiji.default.table.phonebook
Kiji table 'kiji://localhost:2181/default/phonebook/' deleted.

The command below creates the same phonebook table with the layout specified in the layout.json file in your $KIJI_HOME/examples/phonebook directory.

$KIJI_HOME/bin/kiji create-table --table=kiji://.env/default/phonebook \
Parsing table layout: $KIJI_HOME/examples/phonebook/layout.json
Creating Kiji table: kiji://localhost:2181/default/phonebook/


To ensure that your table exists, use the kiji ls command to show the available tables in your Kiji instance.

$KIJI_HOME/bin/kiji ls kiji://.env/default

The above command should list phonebook as a table.