Unstructured data in AsterixDB

Consider the following JSON snippet:

{  
"id":101,
"name":"John Doe",
"nickname":"John",
"username":"johndoe",
"email" : "[email protected]",

"createdAt":"2018-08020T10:10:00",
"friendIds":[
2,
3,
4,
10
],
"employement":[
{
"organizationName":"SAS Web Tech",
"startDate":"2017-08-06"
},
{
"organizationName":"Kirlosker Service Center",
"startDate":"2016-08-06"
}
],
"gender":"Male"
}

The JSON data holds information of an employee who has a name, nickname, and username, and the date when the record was inserted. An employee can be associated with one or more organizations. To create a schema in AsterixDB, our schema could appear as follows:

create type EmploymentType as closed {
organizationName: string,
startDate: date,
endDate: date?
};

Notice that the schema is defined as closed. Now we can define UserType as follows:

create type UserType as open {
id: int,
username: string,
name: string,
email: string,
nickname: string,
createdAt: datetime,
friendIds: {{ int }},
employment: [EmploymentType],
gender: string
};

The world of data in AsterixDB is organized into data namespaces called dataverses. To set default dataverses for a series of statements, the use dataverse statement is provided. For example, to use dataverse to be TinySocial, we need to execute the following statement:

$ use dataverse TinySocial;

Now create dataset is used to create a new dataset. To create a dataset for this example, we need to run the following statements:

$ create dataset Employee(UserType) primary key id;

After that, we can create the example UserType and EmploymentType. When you run these statements, the output screen should look something like this:

Figure 11.5: Output screen of the query execution
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.190.38