Splunk® Cloud Services

SPL2 Search Manual

Naming conflicts when importing items

When you import items into a module, naming conflicts can arise. The module you are importing into might already contain an item with the same name. If you import items from multiple modules, the items in different modules might have the same name.

How naming conflicts are processed

Naming conflict are identified and processed based on whether you use explicit or bulk import statements.

Explicit import statements

An explicit import statement specifies the name of the item you are importing. For example:

import top10threats from incidents_team

When you use explicit import statements, naming conflicts are identified immediately and an error is returned.

For more details, see Import statements that result in items with the same name.

Bulk import statements

Bulk import statements use a wildcard character ( * ) to import all of the items that are exported from a module. For example:

import * from incidents_team

When you use multiple bulk import statements, naming conflicts are identified when you attempt to use the imported items in the module.

  • For views, the conflict is resolved by using the view from the last import statement.
  • For custom functions and custom data types, the following table describes how the naming conflicts are resolved:
Scenario Example Conflict resolution
The items are exactly equivalent. Two identical custom functions with the same name from different modules. The item from the last import statement is used.
The items are not equivalent. Two custom functions with the same name, but some of the parameters are different. The custom function from the last import statement is reviewed first to determine if the function parameters match what is specified in the search. If there is a match, that custom function is used. If there is not a match, the next to last import statement is reviewed to look for a match. This continues until an imported item matches the parameters specified.

For more details, see Naming conflicts when importing items from multiple modules.

Import statements that result in items with the same name

When the import statements result in items with the same name, an error is returned because of an ambiguous reference to that name.

This occurs whether there is already an item in the module with the name or there are multiple import statements that result in items with the same name.

The following examples show multiple import statements to illustrate different import scenarios:

Scenaro Import example
Items from different modules that have the same name.
import top10threats from incidents_team
import top10threats from response_team
Renaming an item that results in multiple items with the same name.
import top10threats from incidents_team
import hot_threats as top10threats from response_team
Importing all items using an alias that results in items with the same name.
import top10threats from incidents_team
import * as top10threats from response_team

Naming conflicts when importing items from multiple modules

The result of a naming conflict depends on how you import the items. The following table describes the result of the naming conflict:

Type of import Examples Result
Explicitly named imports to import individual items Two views with the same name:
import view1 from module1
import view1 from module2


A view and a custom function with the same name:

import threats1 from module1
import threats1 from module2
Importing items with the same name, regardless of the kind of item, returns an error.
Bulk imports to import all items Import all items from multiple modules:
import * from biz_set_1
import * from biz_set_2


An explicitly named custom function and a bulk import from a module which has an item with the same name:

import isError from biz_set_1
import * from biz_set_2 
Importing all of the exported items from a module results in the item from the last import statement, which is viewed as the most recent import statement, is used. The other import statements with the same item name are ignored.

Detailed example of bulk import naming conflicts

Consider the following export statements from the biz_set_1 and biz_set_2 modules:

biz_set_1 module

export $top10threats  // A search exported as a view
export $metrics  // A search exported as a view
export isError  // A custom function
export roundif  // A custom function

biz_set_2 module

export count_sigfig_threats  // A custom function
export isError  // A custom function

Both modules have a custom function called isError.

When you import all of the items exported from these modules, the module specified in the last import statement takes precedence.

a-team module

import * from biz_set_1
import * from biz_set_2

The result of these import statements is:

  • The import statements are checked for naming conflicts when an item from an import statement is used in a search.
  • For the isError custom function, when the function is used in a search the function from the biz_set_2 module is checked first, since that module was the last import statement.
    • If the function in biz_set_2 module matches the parameters specified in the search, the function in biz_set_2 module is used.
    • If there is not a match, the function in biz_set_1 module matches the parameters specified in the search, the function in biz_set_1 module is used.

Resolving naming conflicts

You can resolve a naming conflict error by changing the import statement. Because the import statement is a pointer, you can either:

  • Rename the item
  • Specify an alias

Rename when you import items

You can rename an item when you import it to avoid duplicate item names in your module. Use an as clause in the import statement to rename the item.

The import syntax is:

syntax

import <item_name> as <rename> from <source_name> 

For example, to rename the transactions view from the qtr1_data module as qtr1_transactions, use this import statement:

example

import transactions as qtr1_transactions from qtr1_data

Import items using an alias

In addition to renaming items, another way to avoid duplicate item names is to import items using an alias. Technically referred to as a subnamespace alias, you can import one or more items using an alias.

The import statement syntax is:

syntax

import {<item_name>, <item_name>, ...} as <alias-name> from <source_name>

The curly brackets { } are required around the list of items, even if only one item is specified. Using the curly brackets with the as clause identifies this statement as an import using an alias instead of a rename.

Importing a single item using an alias

Here's an example of the import statement when importing one item using an alias:

example

import {qtr1_purchases} as qtr_2025 from 'quarterlypurchases'

The item you've imported is now identified as qtr_2025.qtr1_purchases.

Importing multiple items using an alias

To import multiple items using an alias, you can:

  • Import some of the items by specifying the names of individual items.
  • Import all of the items by using import *.

Import specific items using an alias

If you only want to import a few items from a module, you can specify those items individually.

Here's an example of an import statement that imports multiple items using an alias:

example

import {qtr1_purchases, qtr2_purchases, qtr3_purchases, qtr4_purchases} 
as qtr_2024 from 'quarterly purchases'

These items are now identified as:

  • qtr_2024.qtr1_purchases
  • qtr_2024.qtr2_purchases
  • qtr_2024.qtr3_purchases
  • qtr_2024.qtr4_purchases

Importing all items using an alias

All of the items that are exported from one module can be imported into another module. Suppose there is a module called biz_set_2 that contains multiple items which are designed to be shared with various teams. These items have been exported:

biz_set_2 module

export count_sigfig_threats  // A custom function
export roundif // A custom function
export person  // A custom data type

You want to import these items into the a-team module. However there is already a function called roundif in the a-team module that was imported from the biz_set_1 module.

To resolve duplicate names, you can import the items from the biz_set_2 module using an alias in the a-team module.

The syntax to import all items using an alias is:

syntax

import * as <alias-name> from <source-module>

The following example shows using an alias called biz2 to import the items from the biz_set_2 module into the a-team module:

a-team module

import * as biz2 from biz_set_2

The three items from the biz_set_2 module are imported with these names:

results

biz2.count_sigfig_threats
biz2.roundif
biz2.person 

Search using an item imported with an alias

To use an item that has been imported using an alias, you must qualify the item name with the alias name.

For example, you use biz2.roundif to specify the roundif function that was imported with the biz2 alias. In the following example, $search2 shows how to specify this function in a search:

a-team module

import * as biz2 from biz_set_2

$search2 = FROM top10threats SELECT score, biz2.roundif(score, 2) as newscore

See also

Related information
Importing module items and datasets using SPL2
Specifying import paths
Scope and precedence importing items
Exporting module items using SPL2
Understanding SPL2 namespaces
Last modified on 11 February, 2025
Importing module items and datasets using SPL2   Specifying import paths

This documentation applies to the following versions of Splunk® Cloud Services: current


Was this topic useful?







You must be logged into splunk.com in order to post comments. Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic. If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk, consider posting a question to Splunkbase Answers.

0 out of 1000 Characters