Are you more of a command line aficionado than a user interface promoter? Wish you could navigate Datameer artifacts using the command line? With this guide, you will be able to do a variety of things with Datameer artifacts without the Datameer user interface (UI).
Table of Contents
Sample data download
Find your REST call (GET)
In this example, you will start with the GET command. This command will allow you to retrieve the configurations for a particular Datameer artifact. In order to run a REST API command via command line, you will need your username and password for Datameer, as well as the URL for Datameer.
Open up whichever command line application you prefer. Here is the command you will be using:
You must make sure to fill in your actual username and password for your Datameer instance along with the Datameer URL and job configuration ID. Your job configuration ID can be found in your Datameer UI. Go to your Datameer instance and select the Airports import job and view the Information Browser to the right of the artifacts. You will find the ID here:
A completed REST call with GET will look something like this:
Understand the return for the GET command
Once you run the command, your return should look like this:
This is a return of the configurations that have been set up to import the data into Datameer. If you look closely, you will recognize some things that you see in the import wizard within the Datameer UI:
The first part gives you general information about your Datameer instance, the path of the artifact in Datameer, any description and the name of the artifact.
The next portion (below) gives you more details on the configurations of the import, such as file format, if a histogram will be generated for this job, CSV configurations, record sample size, partitioning, custom hadoop properties, email notification settings, etc. If you were in the Datameer UI, you would see the same type of configurations by right clicking on the artifact and selecting “Configure”.
The final part of the return shows the columns and column configurations for the import job:
Download the return
Now that you have an understanding of what is contained in this return, you will now download the data using a different GET command so you can make changes to it!
The command will look very similar to our first GET command, except you are adding how you would like to save the file:
When you run this command, it will save the file in whatever directory you are currently on in your command line, or you must specify the directory you would like to save to. For example, you can use the following command to navigate to your downloads folder:
Once you hit enter in terminal, you can run the GET command and the file will save to this folder. If you do not want to navigate to the folder, but would like to specify where it saves to, your GET command will look similar to this:
Edit the JSON file
Now that you have a physical file to edit, you canl make changes. You can do this two different ways:
- Through a text editor such as TextWrangler, Smultron, or Sublime.
- From command line.
If you would like to make these changes from a text editor, it is as simple as opening the downloaded file to the application.
If you would like to edit the file from command line, you will run the following command if you are already in the same directory as the file:
If you are not in the same directory, your command will look something like this:
Now you will change a few things. If you are using your command line, press the “i” to begin editing.
First, let’s change the number of preview records from 1,000 to 5,000. This will increase the sample set that the workbook will use. To do this, find the following configuration:
Change the 1000 to 5000.
Now, change some of the names of the columns. Find the “fields” section of the JSON. Make sure you are in edit mode and change some of the column names in the configuration “name”.
You can change these names to whatever you wish as along as they start with alphanumeric characters and no spaces (i.e. use “ID_Tags” instead of “ID Tags”).
In the example below, change the name of the column from "id" to "Identifier"
Make sure you save changes to the JSON.
If you are in command line, hit ESC, then type x and return.
You can use normal saving options if you are in a text editor.
Post the changes to Datameer
Now that you have made some changes, you want to input these changes into Datameer. Since you are updating a file that already exists, use the PUT command:
This command identifies the new file with the @<job-payload>.json and tells it where to go in Datameer with the http://<Datameer-serverIP>:<port-number>/rest/import-job/<job- c!onfiguration-id>’.
If you are in the same directory as the file you are going to use the PUT on, then you only have to use the direct file name:
If you are not in the directory where your file resides, make sure you put in the directory path:
Once you run this command, you will get a response that tells you whether the PUT succeeds or not. It should look like this:
This means you have successfully updated the import configuration outside of the Datameer UI!
Now, go into Datameer, right click the Airports import artifact and select “Show Details”. You should now see your configuration changes under the Configuration Details tab.
For more information on REST API and Datameer, see: Accessing Datameer Using the REST API