Section
Globals QuickStart
InterSystems IRIS® data platform contains an extremely efficient data model known as globals. Individually, a global is a persistent multidimensional array. Data added to globals is immediately stored and available to multiple processes, not just the process that stored it.
The benefits of using globals are vast — some are listed below. Globals are:
- Efficient: They grow based on need, without upfront declaration of size or structure.
- Multimodel: They store objects, tables and indexes, JSON and XML documents, even documentation.
- Typeless: They can contain integer, named, or any other subscript type, even at the same subscript level.
- Automatically sorted: They sort subscripts automatically at each dimension.
- Flexible: They allow flexibility in node structure and data storage to contain any number of subscripts and any type of data.
- Safe: You can lock any node to keep other processes from changing value, while keeping other nodes at same level accessible.
Note that globals are not just another storage model. In fact, they are so powerful and flexible that they are actually at the core of all InterSystems models, giving you freedom from database remodels.
Interested in seeing it for yourself? Watch the video, then try the exercise below.
In the following exercise, you will store and retrieve globals, holding data stock inventory data, to see for yourself how powerful and beneficial they can be.
Start the exercise in one of three ways:
- Use an InterSystems Learning Lab by clicking the launcher button below.
- Use AWS, Azure, or GCP, first following the steps to change the password for InterSystems IRIS.
- Try the exercise locally with an instance of InterSystems IRIS.
You must be logged in to launch an InterSystems IRIS instance.
- Log in with your existing account.
- Don't have an InterSystems account? Create a new account.
Typeless nodes of globals provide great flexibility
- Open the InterSystems Terminal. On AWS, Azure and GCP, you can do this using
sudo docker exec -it try-iris iris session iris
- Create the following globals (Hint: you can copy all lines at once and paste!):
set ^Stock("dress", 4, "blue", "floral") = 52
set ^Stock("dress", 8, "green", "solid") = 10
set ^Stock("dress", 4, "blue", "striped") = 7
set ^Stock("dress", 4, "blue", "solid") = 117
set ^Stock("dress", "location") = "aisle A"
Here, you are storing this data directly to InterSystems IRIS in your own custom structure. This example contains one node for each pattern and an additional node for the location of the dresses in the store. Notice the subscripts within a global ("dress"
and4
) can have different types. Furthermore, subscripts even within the same position (4
and"location"
) can also have different types, supporting your ability to dynamically and efficiently store sparse and varied data.
Globals are automatically sorted and easy to retrieve
- To easily see if there are any size 4 blue dresses with a floral pattern, you can access the correct data node by executing:
write ^Stock("dress", 4, "blue", "floral")
- This data is automatically sorted and easy to filter. View globals of only size 4 dresses, automatically sorted, by entering into Terminal:
zwrite ^Stock("dress",4)
Globals are easy and performant
- Display the amount in stock of all size 4 blue dresses simply by iterating through all of the data nodes below the
^Stock("dress", 4, "blue")
node. Copy and paste the following line and execute it in Terminal:
set key = "" for { set key = $order(^Stock("dress",4,"blue",key)) quit:key="" write ! ,key_":"_$get(^Stock("dress",4,"blue",key)) }
Unrelated nodes, such as the location of dresses, are not touched, optimizing the performance of the retrieval.
Note that while you can run this in one line, a slightly more formatted version of this breaks down the key aspects of this code:
Formatted version of the code above with explanation:
set key = "" for { set key = $order(^Stock("dress",4,"blue",key)) quit:key="" write ! ,key_":"_$get(^Stock("dress",4,"blue",key)) }
On the first line, the variable of key is set to a blank string. On the second line, a for loop begins. The for loop iterates using the $order iterator on the third line. The $order iterator loops through the ^Stock global, selecting only the nodes that have a base node pattern matching ("dress", 4, "blue"). The final value of each matching node becomes the value of the variable key. In the fourth line, the loop breaks if key is empty because there are no more matching nodes. In the fifth line, a string is written. The string contains a new line, then a string concatenation of the key, a literal colon, and the value of each node.
To exit the InterSystems Terminal, type:halt
- Open the InterSystems Terminal. On AWS, Azure and GCP, you can do this using
Watch the video below to learn more about globals and how they work.
Experience the power of data model flexibility in InterSystems IRIS with this hands-on exercise.
Follow this learning path to build a server-side application with InterSystems IRIS using InterSystems ObjectScript.