Loading Data into a JSON Table from JSON Files
If you have data stored in JSON files that you want to store in a JSON table, create a new JSON
table in MapR-DB from the mapr dbshell and then load the data into the table using the
insert
command. Or, you can use the mapr importJSON command to create the table and import data. The
insert
command is useful when inserting a small number of JSON documents into a
JSON table. The mapr importJSON command is useful when inserting many documents into a JSON
table.
- Start the
mapr dbshell
:mapr dbshell
- Issue the
create
command to create the JSON table, including a filepath if you do not want the table stored in the default directory. The default directory is the current directory on MapR-FS which is set to the user’s home directory when themapr dbshell
starts.create students
- View Create the HBase Table to see the data used to
create the “students” binary table. The binary table was created using a series of put
commands. To create a JSON table, the data needs to be in JSON format. Issue the following
commands to insert each JSON record into the JSON
table:
insert students --value '{"_id":"student1", "name":"Alice", "street":"123 Ballmer Av", "zipcode":12345, "state":"CA"}' insert students --value '{"_id":"student2", "name":"Bob", "street":"1 Infinite Loop", "zipcode":12345, "state":"CA"}' insert students --value '{"_id":"student3", "name":"Frank", "street":"435 Walker Ct", "zipcode":12345, "state":"CA"}' insert students --value '{"_id":"student4", "name":"Mary", "street":"56 Southern Pkwy", "zipcode":12345, "state":"CA"}'
Alternatively, you can create a flat text JSON file that contains the records and run the mapr
importJSON
command to import the records into the table from the file. - Issue
find <table_name>
to verify that the table was created. - Issue
exit
and press return to close themapr dbshell
.
SELECT * FROM dfs.`/user/root/students`;
SELECT * FROM dfs.`/file/path/students`;