Creating the Initial Containers
Flow of Data for the Data Generator
The data generating client makes use of executables created by 5 C programs. These programs are:
Many of these applications also use methods declared in this C file.
The five executables used in by the client script all make calls and references to methods
define in gridstorefunctons.c. Many of these methods are involved in making random data or
creating containers or making updates to GridDB. In gridstorefunctions.h there are five constants:
HOST, PORT, CLUSTER_NAME, USER, PASSWORD. If you wish to connect to a different GridDB cluster,
simply set them to the values you wish.
// Change to the cluster configuration you wish to connect to, this is the default #define HOST "220.127.116.11" #define PORT "31999" #define CLUSTER_NAME "defaultCluster" #define USER "admin" #define PASSWORD "admin"
This program takes a single command line argument which is the name of the of the
coffee chain container and inserts it into GridDB.
GSGridStore* gridstore = makeGridStore(HOST,PORT,CLUSTER_NAME,USER,PASSWORD);
This is just a quick method from
gridstorefunctions.h that establishes a
connection to GridDB.
GSCollection* collection = makeCoffeeStoreCollection(gridstore,argv);
This creates and inserts the coffee chain container into GridDB. For this application, containers were created more generally or dynamically with containerInfo objects rather than with structs.
GSCollection* coffeeChain; GSColumnInfo columnInfo = GS_COLUMN_INFO_INITIALIZER; …. // Create Column Schema columnInfo.name = "store_id"; // Primary key of coffee stores is a 'store_id' columnInfo.type = GS_TYPE_STRING; …. // Address Column columnInfo.name = "address"; // All stores have an 'address' location columnInfo.type = GS_TYPE_STRING; …. // Latitude Column columnInfo.name = "latitude"; // Stores also can be identified as (latitude and longitude) columnInfo.type = GS_TYPE_FLOAT; …. // Longitude Column columnInfo.name = "longitude"; columnInfo.type = GS_TYPE_FLOAT;
As you can see above the schema created is similar to the diagram of schemas above.
The latitude and longitude are cast as floats for accuracy. To create a column schema
containerInfo objects and
are needed. Each
columnInfo in the array will have the name and type the
column should. The
containerInfo will hold all the column schemas, the container name,
its row key, and its container type. Once all these objects and their properties are set the
container can be created and inserted into GridDB with the
Once this container is created, its container name can be used to insert coffee stores later.
This program takes the following command-line arguments.
- The name of the coffee chain it belongs to
- The store id of the coffee store
- The address of the coffee store
- The latitude of the coffee store
- The longitude of the coffee store
The program starts by fetching the coffee chain container the coffee store belongs to:
The program then takes and parses those arguments to insert a row representing a coffee store into the coffee chain.
gsSetRowFieldByString(storeEntry,0,store_id); // Set store's id gsSetRowFieldByString(storeEntry,1,address); // Set store's addresss gsSetRowFieldByFloat(storeEntry,2,latitude); // Set store's latitude gsSetRowFieldByFloat(storeEntry,3,longitude) gsPutRow(coffeeChain,NULL,storeEntry,NULL);
From here the row fields are set by the command line arguments passed to the function
and the row is then inserted into the coffee chain. A coffee store not only belongs
to a coffee chain but is also a container for coffee machines. This means a coffee
store container for storing machines is needed as well.
The method of creating the container is similar to the
function. This collection has a
timestamp column that will hold the machine’s installation
date. There are also
integer columns that will hold the amount of cycles the machine has
had since it has been installed. There is also a column that holds the cycles it has had
since its last clean cycle. If a clean cycle starts on a machine, the value in that column
will reset to zero.
This programs takes these command line arguments and involves creating a coffee machine container.
- The store id of the coffee store the machine belongs to
- The serial number of the coffee machine
- The model number of the coffee machine
- The installation date of the coffee machine as a timestamp string
In the case of a new coffee machine. It will first be inserted as a row to the coffee machine
it belongs with 0 being set as the values of the
values since the machine has not started generating records.
First obtain the coffee store container the coffee machine belongs to
From there the coffee machine can be inserted into the coffee store as a row in the insertCoffeeMachines function from
gsSetRowFieldByString(coffeeMachine,0,serial_number); gsSetRowFieldByString(coffeeMachine,1,model_number); gsSetRowFieldByTimestamp(coffeeMachine,2,installation_date); gsSetRowFieldByInteger(coffeeMachine,3,cycles_new); gsSetRowFieldByInteger(coffeeMachine,4,cycles_clean); gsPutRow(coffeeStore,NULL,coffeeMachine,NULL);
If the coffee machine already exists, the program will exit immediately.
You can download the application and its source code for the data generating client and data visualisation component from the link below: