Metropolis Documentation 4.3 > Applications > Saved Map

The Saved Map application allows you to construct a Saved Map document, which contains a collection of {key, value} entries. Maps are frequently used as lookup tables because you can "look up" the associated value with its key. For example, let's say you have a Saved Map document that contains a bunch of phone numbers:

Key Value
Joe 5551111
Jane 5551234
Jim 5554321
... ...

You can get Jane's number by entering the expression, SavedMap("Phone Number").get("Jane").

You can use Saved Map to:

  • store (e.g. cache) expensive calculations for quick use in other applications;
  • perform sanity checks - save results and run them again later to see if things have changed;
  • store a set of parameter values for use in other metrics.
Saved Map is currently a BETA application.

Getting Started

The following example will show you how to create a phone number lookup table in order to give you a basic understanding of how this tool works.

  1. Open the Saved Map application.
  2. Enter Joe as the Key and "555-1111" as the Value. The Value expression bar accepts any object, so we put quotation marks around the phone number. That way, it is interpreted as a string and not 555 minus 1111 (a number). Click Add to add this key/value pair to the table. The key is the string you will use to access the associated value. In other words, it's a shortcut to the value stored in a specific row, and therefore, it must be unique - you can't have two Joes in the table because there would be no way of knowing which Joe row you are trying to access.
  3. Enter Jane as the Key and enter "555-1234" as the Value. Click Add.
  4. Enter Jim as the Key and enter "555-4321" as the Value. Click Add.
  5. Save this map as listOfPhoneNumbers. We now have a map of names to phone numbers, and can quickly access those values in other applications. This is useful because we now just have to remember a key value, instead of an actual phone number. If the map contained other types of values or objects, everything is already computed, so calling those values from a map is a lot faster than having to calculate them each time.
  6. Open Calculator.
  7. Enter SavedMap("listOfPhoneNumbers").get("Jane"). This returns Jane's phone number by looking in our Saved Map and finding the key-value pair associated with the key "Jane" and returning the value in that row.
  8. Alternatively, we can also add mappings to our Saved Map. Enter SavedMap("listOfPhoneNumbers").put("John", "555-7890").

    This will edit our Saved Map document such that there is a new key-value pair for John.

Alternatively, we can create the Saved Map using Hedgehog.

  1. Open Calculator.
  2. Enter SavedMap phoneNumbersMap = SavedMap(); to create a new Saved Map document named phoneNumbersMap.
  3. Enter phoneNumbersMap.put("Jill","555-0987") to add the key-value pair for Jill and her phone number.
  4. Enter phoneNumbersMap.put("Jack","555-2222") to add a phone number for Jack.
  5. Enter phoneNumbersMap.put("Will", "555-1357") to add a phone number for Will.
  6. You now have a Saved Map that contains 3 key-value pairs. Open phoneNumbersMap by right clicking it in the Variables table.

  7. We can also print out all the values directly in Calculator by using a for loop. Enter the following in Calculator:
    for (String key : phoneNumbersMap.keySet()) {
        print(key + "  " + phoneNumbersMap.get(key));
    }
    

  8. Finally, in order to save the Saved Map we just created, enter phoneNumbersMap.saveAs("phoneNumbersMap").

Basic Reference

Add to Map Ribbon


Key - the string value for the key.
Value - the object.

Details to note:

  • The keys must be strings.
  • The values can be objects of any type, such as a date, model, collection, time series, or document.
  • The same map can hold values of different types.
  • The keys in a map must be unique. If you add tow entries with the same key, the second entry will overwrite the first entry.

Add - click to add the key-value pair to the Map.

Note that saving the document saves the computed key-value pair as of that date (the associated data is static). In order to refresh the data (i.e. turn a static map into a dynamic one), you can add a Refresh Function (a metric that operates on None, takes no parameters, and returns a Map), which will refresh that data the next time you try to access content of your Saved Map.

Concepts and Features

Useful Metrics

The following are the metrics you need to create a Saved Map. For more, see the autocomplete window or use Explorer to find other metrics that work with Maps.

  • Map.saveAs()
  • None.createMap()
  • None.savedMap()
  • Map.get()
  • Map.put()

Related Links

Need Help? Email us at           © 2014 Palantir Technologies  ·  Terms of Use  ·  Privacy and Security Statement