Using the %onesaitplatform interpreter


This tutorial includes a use example of the group of %onesaitplatform interpreters from the Notebooks.

To learn more about the functionalities of the interpreters you can consult the references: (Notebooks) (ES) %onesaitplatform Interpreter Reference.

Contents


Before starting

Before starting, bear in mind the following points:

  • This tutorial is based on the Restaurants database, which is available by default on the platform.
  • An ontology called RestaurantTutorialDB will be created to insert.
  • A Digital Client called RestaurantTutorialClient will be created for communication with the Restaurant and RestaurantTutorialDB ontologies.
  • A REST API called RestaurantTutorialAPI will be created on the RestaurantTutorial ontology.

If the components already exist, they must be deleted in the following order: RestaurantTutorialClient, RestaurantTutorialAPI and RestaurantTutorialDB.

  • We strongly recommend to not do the tutorial done with an administrator user.
  • The user must have the ANALYTICS role to have the Notebooks module.

Creating the necessary elements

Creating the RestaurantTutorialDB ontology

The first step is creating the RestaurantTutorialDB ontology with the same scheme as the Restaurants ontology. You can copy and paste the following scheme to define the ontology scheme:

{"$schema": "http://json-schema.org/draft-04/schema#","title": "Restaurants","type": "object","required": ["Restaurant"],"properties": {"Restaurant": {"type": "string","$ref": "#/datos"}},"datos": {"description": "Info Restaurant","type": "object","required": ["address"],"properties": {"address": {"type": "object","required": ["building"],"properties": {"building": {"type": "string"},"coordinates": {"type": "object","required": ["coordinates","type"],"properties": {"coordinates": {"type": "object","properties": {"latitude": {"type": "number"},"longitude": {"type": "number"}}},"type": {"type": "string","enum": ["Point"]}}},"street": {"type": "string"},"zipcode": {"type": "string"}}},"borough": {"type": "string"},"cuisine": {"type": "string"},"grades": {"type": "array","properties": {"date": {"type": "object","properties": {"$date": {"type": "string","format": "date-time"}}},"grade": {"type": "string"},"score": {"type": "number"}}},"name": {"type": "string"},"restaurant_id": {"type": "string"}}},"description": "Ontology Restaurants for testing","additionalProperties": true}










That way, you already have a new ontology with the same scheme as Restaurants.

Creating theRestaurantTutorialClient Digital Client


Next, you will create a Digital Client with access to the Restaurants and RestaurantTutorialDB ontologies, to query and insert data. The token will be your DIGITAL_CLIENT_TOKEN in the Notebook.










Now you already have a Client offor communication with the platform's Digital-Broker.

Creating theRestaurantTutorialAPI API REST

Lastly, create a REST API to query the ontology data by REST. Establish two types of operations: all and {id}

A query REST API is now available on the data that is inserted.

Set neccessary variables

With the recently-created elements, enter the Notebook called OnesaitPlatformZeppelinInterpretes or create a copy of it.

In the first cells, the necessary variables obtained from the creation of the elements and the user are established.

Insert them in the Zeppelin context (they will be accessible from all cells, regardless of the interpreter).


Using the %onesaitplatform interpreter

Below is an example of data exchange with the platform (queries and inserts).

Show help

Help is displayed if the word help or an unrecognizable expression is entered.

Debug mode

The debug mode allows you to see the code execution trace.

Enter credentials

The debug trace can be observed when debug mode is active for initConnection() execution.

Perform a query

SQL query example:

NATIVE query example:

Query the data as a table

To perform a data query that Zeppelin can interpret:

Perform a data insert

To perform a data insert, you must first save the serialized objects in context, from where they will be retrieved in the insert function:

Perform a paged query (batch)

In cases where large queries are made to download raw data, we recommended you to use the paged queries, which download data in batches. The the data batch configuration can be changed in the interpreter manager:

An example of a query and save process in a variable:


Using the %onesaitplatform.apimanager interpreter

Below is an example of calls to the platform's API-Manager.

Show help

La ayuda se muestra si se introduce la palabra help o una expresión no reconocible.

Debug mode

The debug mode allows you to see the code execution trace.

Enter credentials

The token to be used for requests is set. In this %onesaitplatform.apimanager version, you can pass z.get() expressions for all arguments of their functions.

List all APIs of that user

The APIs of our user are listed to obtain the basic information of the API. You can also list the APIs of other users (public and shared with the user that corresponds to the used token).

In the context, Java list objects are saved, so you have to access the list to get the results using indexes.

Getting more information about an API

If you want to obtain more extensive information from an API, the following expression is used:

Making a request to the API

An API call created to list the elements that we have inserted in the previous steps is made.