Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
0.9.4.1, 0.9.5
-
None
Description
RUN THIS:
USE Personicle;
//dropping and recreating since AsterixDB requires a virgin
DROP DATASET events IF EXISTS;
CREATE DATASET events(EventType) PRIMARY KEY eventId AUTOGENERATED;
LOAD DATASET events USING localfs
(("path"=":///Users/macandcheese/Desktop/Personicle/old-personicle-parser/sample-event-dump.jsonl"),("format"="adm"));
BUT FIRST RUN THIS (ALSO ATTACHED) TO SET THINGS UP:
--To begin we’ll go ahead and delete any existing dataverse named Personicle
--this ensures we’re writing into an empty dataverse (note ALL data in the
--dataverse will be deleted, so be careful). This is included so that this
--code can be re-run without causing naming conflicts, but is not required
--to create a dataverse.
DROP DATAVERSE Personicle IF EXISTS;
--Now that we have a clean slate let’s create our dataverse and call it
--Personicle, though the name is arbitrary.
CREATE DATAVERSE Personicle;
--Sets the current working dataverse for whatever SQL++ statements follow it.
--This is akin to USE in SQL.
USE Personicle;
--The question mark represents an optional field which may or may not be present.
--I’ve also specified some uuid types which I’ll later use for some auto-generated
--primary keys. Finally, ADM supports types within types, so you can use custom
--types for the fields. I’m not going to delve too deep into this, because I think the
--documentation explains it sufficiently more or less. Here are a couple links to
--get you started:
--https://ci.apache.org/projects/asterixdb/datamodel.html
--https://ci.apache.org/projects/asterixdb/sqlpp/primer-sqlpp.html
CREATE TYPE AddressType AS OPEN
{ category: string?, address: string, city: string, state: string, postalCode: string };
CREATE TYPE PhoneDetailType AS OPEN
;
CREATE TYPE EmailDetailType AS OPEN
;
CREATE TYPE UserType AS OPEN
;
CREATE TYPE ObservationType AS OPEN
{ observationId: uuid, --primary key uuid for observation dataSource: uuid, --foreign key to the data source which generated the observation, like a smart device, API or human. about: uuid, --foreign key to the user this observation is about label: string?, --labels are human readable identifiers, for example "location observation for James" start_at: datetime, --when the observation began being observed end_at: datetime? --when the observation stopped being observed, some observations won't need this };
CREATE TYPE EventType AS OPEN
;
CREATE TYPE DataSourceType AS OPEN
;
--The code below creates collections using the ADM specified above. --Therefore this code can be run as boilerplate code to get started with using AsterixDB.
--Note that I've specified the primary key to be "AUTOGENERATED" which
--means AsterixDB will create one for us if the UUID key is omitted,
--if it is provided AsterixDB will use the UUID that was provided.
USE Personicle;
--We will have one collection for each of the ER diagram's top-level entity type instances.
--(Instances of their subtypes will conform to the collection's type but will also have additional attributes
--appropriate to their particular subtype. AsterixDB's open types make this possible.) In MongoDB, we would
--have these same collections. We just wouldn't bother to define any of their type info (and the system wouldn't
--do any checking); everything would be by convention/documentation, but the data would be exactly the same.
CREATE DATASET users(UserType) PRIMARY KEY userId AUTOGENERATED;
CREATE DATASET observations(ObservationType) PRIMARY KEY observationId AUTOGENERATED;
CREATE DATASET events(EventType) PRIMARY KEY eventId AUTOGENERATED;
CREATE DATASET datasources(DataSourceType) PRIMARY KEY dataSourceId AUTOGENERATED;