View the original community article here
Last tested: Dec 15, 2020
TL;DR: LookML constants cannot be "passed" between projects. We can only change the values of the constants defined in the imported project.
Intro
Constants can be created in a LookML project for defining a value to be reused throughout that project. But sometimes, that LookML project is imported into another LookML project, either as a local or a remote dependency. The behavior of constants–when they are from an imported project–can be confusing. This is because constants themselves cannot be imported, whereas LookML files can be imported/included from another project. This behavior is explained in more detail below.
The export and override_constant parameters
For the explanation moving forward, we'll use Project A to refer to the project being imported into another LookML project, Project B.
export
When defining a LookML constant in a project's manifest file, you can add an export parameter to a constant. The export parameter is added to the original definition of the constant, in Project A. This parameter determines what Project B is allowed to do with the constant when it imports Project A.
override_constant
When importing Project A using the local_dependency or remote_dependency parameters in Project B, as long as Project A has allowed it in its export
parameter, we can specify a new value for the constant.
Here's the trickiest, but most important part:
- The constant from Project A can only be used in Project A's files.
- So when we import Project A into Project B, the override_constant parameter only changes the value of the constant for Project A files included in Project B.
- This allows Project B to see the files included from Project A as having a different value than the one defined in Project A's manifest file.
- This does not allow Project B to use the constant in its own files.
Examples in Practice:
These examples show what happens with different combinations of the export
parameter and override_constant
parameter. (local_dependency is used as an example, but the behavior is the same with a remote_dependency)
export: none

export: override_optional

export: override_required

This content is subject to limited support.