Primeur Online Docs
Data Shaper
Data Shaper
  • 🚀GETTING STARTED
    • What is Primeur Data Shaper
      • What is the Data Shaper Designer
      • What is the Data Shaper Server
      • What is the Data Shaper Cluster
    • How does the Data Shaper Designer work
      • Designer Views and Graphs
      • Data Shaper Graphs
      • Designer Projects and Sandboxes
      • Data Shaper Designer Reference
    • How do the Data Shaper Server and Cluster work
      • Data Shaper Server and Cluster
      • Data Shaper Server Reference
    • VFS Graph Components
      • DataOneFileDescriptor (DOFD) metadata
      • Passing parameters from Data One Contract to Data Shaper graph
      • Inheriting Data One context attributes in Data Shaper graph
  • DATA SHAPER DESIGNER
    • Configuration
      • Runtime configuration
        • Logging
        • Master Password
        • User Classpath
      • Data Shaper Server Integration
      • Execution monitoring
      • Java configuration
      • Engine configuration
      • Refresh Operation
    • Designer User Interface
      • Graph Editor with Palette of Components
      • Project Explorer Pane
      • Outline Pane
      • Tabs Pane
      • Execution Tab
      • Keyboard Shortcuts
    • Projects
      • Creating Data Shaper projects
      • Converting Data Shaper projects
      • Structure of Data Shaper projects
      • Versioning of server project content
      • Working with Data Shaper Server Projects
      • Project configuration
    • Graphs
      • Creating an empty graph
      • Creating a simple graph
        • Placing Components
        • Placing Components from Palette
        • Connecting Components with Edges
    • Execution
      • Successful Graph Execution
      • Run configuration
      • Connecting to a running job
      • Graph states
    • Common dialogs
      • URL file dialog
      • Edit Value dialog
      • Open Type dialog
    • Import
      • Import Data Shaper projects
      • Import from Data Shaper server sandbox
      • Import graphs
      • Import metadata
    • Export
      • Export graphs to HTML
      • Export to Data Shaper Server sandbox
      • Export image
      • Export Project as Library
    • Graph tracking
      • Changing record count font size
    • Search functionality
    • Working with Data Shaper server
      • Data Shaper server project basic principles
      • Connecting via HTTP
      • Connecting via HTTPS
      • Connecting via Proxy Server
    • Graph components
      • Adding components
      • Finding components
      • Edit component dialog box
      • Enable/disable component
      • Passing data through disabled component
      • Common properties of components
      • Specific attribute types
      • Metadata templates
    • Edges
      • Connecting Components with Edges
      • Types of Edges
      • Assigning Metadata to Edges
      • Colors of Edges
      • Debugging Edges
      • Edge Memory Allocation
    • Metadata
      • Records and Fields
        • Record Types
        • Data Types in Metadata
        • Data Formats
        • Locale and Locale Sensitivity
        • Time Zone
        • Autofilling Functions
      • Metadata Types
        • Internal Metadata
        • External (Shared) Metadata
        • SQL Query Metadata
        • Reading Metadata from Special Sources
      • Auto-propagated Metadata
        • Sources of Auto-Propagated Metadata
        • Explicitly Propagated Metadata
        • Priorities of Metadata
        • Propagation of SQL Query Metadata
      • Creating Metadata
        • Extracting Metadata from a Flat File
        • Extracting Metadata from an XLS(X) File
        • Extracting Metadata from a Database
        • Extracting Metadata from a DBase File
        • Extracting Metadata from Salesforce
        • SQL Query Metadata
        • User Defined Metadata
      • Merging Existing Metadata
      • Creating Database Table from Metadata and Database Connection
      • Metadata Editor
        • Opening Metadata Editor
        • Basics of Metadata Editor
        • Record Pane
        • Field Name vs. Label vs. Description
        • Details Pane
      • Changing and Defining Delimiters
      • Editing Metadata in the Source Code
      • Multi-value Fields
        • Lists and Maps Support in Components
        • Joining on multivalue fields (Comparison Rules)
    • Connections
      • Database Connections
        • Internal Database Connections
        • External (Shared) Database Connections
        • Database Connections Properties
        • Encryption of Access Password
        • Browsing Database and Extracting Metadata from Database Tables
        • Windows Authentication on Microsoft SQL Server
        • Snowflake Connection
        • Hive Connection
        • Troubleshooting
      • JMS Connections
      • QuickBase Connections
      • Hadoop Connections
      • Kafka Connections
      • OAuth2 Connections
      • MongoDB Connections
      • Salesforce Connections
    • Lookup Tables
      • Lookup Tables in Cluster Environment
      • Internal Lookup Tables
      • External (Shared) Lookup Tables
      • Types of Lookup Tables
    • Sequences
      • Persistent Sequences
      • Non Persistent Sequences
      • Internal Sequences
      • External (Shared) Sequences
      • Editing a Sequence
      • Sequences in Cluster Environment
    • Parameters
      • Internal Parameters
      • External (Shared) Parameters
      • Secure Graph Parameters
      • Graph Parameter Editor
      • Secure Graph Parameters
      • Parameters with CTL2 Expressions (Dynamic Parameters)
      • Environment Variables
      • Canonicalizing File Paths
      • Using Parameters
    • Internal/External Graph Elements
    • Dictionary
      • Creating a Dictionary
      • Using a Dictionary in Graphs
    • Execution Properties
    • Notes in Graphs
      • Placing Notes into Graph
      • Resizing Notes
      • Editing Notes
      • Formatted Text
      • Links from Notes
      • Folding Notes
      • Notes Properties
    • Transformations
      • Defining Transformations
      • Transform Editor
      • Common Java Interfaces
    • Data Partitioning (Parallel Running)
    • Data Partitioning in Cluster
      • High Availability
      • Scalability
      • Graph Allocation Examples
      • Example of Distributed Execution
      • Remote Edges
    • Readers
      • Common Properties of Readers
      • ComplexDataReader
      • DatabaseReader
      • DataGenerator
      • DataOneVFSReader
      • EDIFACTReader
      • FlatFileReader
      • JSONExtract
      • JSONReader
      • LDAPReader
      • MultiLevelReader
      • SpreadsheetDataReader
      • UniversalDataReader
      • X12Reader
      • XMLExtract
      • XMLReader
      • XMLXPathReader
    • Writers
      • Common Properties of Writers
      • DatabaseWriter
      • DataOneVFSWriter
      • EDIFACTWriter
      • FlatFileWriter
      • JSONWriter
      • LDAPWriter
      • SpreadsheetDataWriter
      • HIDDEN StructuredDataWriter
      • HIDDEN TableauWriter
      • Trash
      • UniversalDataWriter
      • X12Writer
      • XMLWriter
    • Transformers
      • Common Properties of Transformers
      • Aggregate
      • Concatenate
      • DataIntersection
      • DataSampler
      • Dedup
      • Denormalizer
      • ExtSort
      • FastSort
      • Filter
      • Map
      • Merge
      • MetaPivot
      • Normalizer
      • Partition
      • Pivot
      • Rollup
      • SimpleCopy
      • SimpleGather
      • SortWithinGroups
      • XSLTransformer
    • Joiners
      • Common Properties of Joiners
      • Combine
      • CrossJoin
      • DBJoin
      • ExtHashJoin
      • ExtMergeJoin
      • LookupJoin
      • RelationalJoin
    • Others
      • Common Properties of Others
      • CheckForeignKey
      • DBExecute
      • HTTPConnector
      • LookupTableReaderWriter
      • WebServiceClient
    • CTL2 - Data Shaper Transformation Language
    • Language Reference
      • Program Structure
      • Comments
      • Import
      • Data Types in CTL2
      • Literals
      • Variables
      • Dictionary in CTL2
      • Operators
      • Simple Statement and Block of Statements
      • Control Statements
      • Error Handling
      • Functions
      • Conditional Fail Expression
      • Accessing Data Records and Fields
      • Mapping
      • Parameters
      • Regular Expressions
    • CTL Debugging
      • Debug Perspective
      • Importing and Exporting Breakpoints
      • Inspecting Variables and Expressions
      • Examples
    • Functions Reference
      • Conversion Functions
      • Date Functions
      • Mathematical Functions
      • String Functions
      • Mapping Functions
      • Container Functions
      • Record Functions (Dynamic Field Access)
      • Miscellaneous Functions
      • Lookup Table Functions
      • Sequence Functions
      • Data Service HTTP Library Functions
      • Custom CTL Functions
      • CTL2 Appendix - List of National-specific Characters
      • HIDDEN Subgraph Functions
    • Tutorial
      • Creating a Transformation Graph
      • Filtering the records
      • Sorting the Records
      • Processing Speed-up with Parallelization
      • Debugging the Java Transformation
  • DATA SHAPER SERVER
    • Introduction
    • Administration
      • Monitoring
    • Using Graphs
      • Job Queue
      • Execution History
      • Job Inspector
    • Cluster
      • Sandboxes in Cluster
      • Troubleshooting
  • Install Data Shaper
    • Install Data Shaper
      • Introduction to Data Shaper installation process
      • Planning Data Shaper installation
      • Data Shaper System Requirements
      • Data Shaper Domain Master Configuration reference
      • Performing Data Shaper initial installation and master configuration
        • Creating database objects for PostgreSQL
        • Creating database objects for Oracle
        • Executing Data Shaper installer
        • Configuring additional firewall rules for Data Shaper
Powered by GitBook
On this page
  1. DATA SHAPER DESIGNER
  2. Functions Reference

Lookup Table Functions

PreviousMiscellaneous FunctionsNextSequence Functions

Last updated 1 month ago

Lookup table functions serve for lookup and manipulation with lookup tables. (See .) To use the lookup table function, you need to specify the name of the lookup table as an argument of the lookup() function.

Do not use the functions shown below in the init(), preExecute() or postExecute() functions of CTL template!

It is not possible to have multiple queries to the same lookup table at the same time as there is only one state which holds the next record.

count

lookup(<lookup name>).count(keyValue)

The count() function returns the number of records whose key value equals to keyValue. The count() function used with DB lookup tables may return -1 instead of real count of record with specified key value (if you do not set Max cached size to a non-zero value). The lookup name is simply a name of the lookup table. It is **not **specified as a string enclosed with " character. The keyValue is a value of a key of the lookup table. If the lookup table has a key of one field, keyValue is one string. If the lookup table has a key of more fields, keyValue is specified as series of the values of particular key parts. See the documentation of the particular lookup table for handling of duplicated keys.

Example 334. Usage of count A lookup table with a one-field key.

$out.0.count = lookup(names).count("smithj");

A lookup table with a key of two fields.

$out.0.count = lookup(names).count("John", "Smith");

See also: get, Allow key duplicates

get

lookup(<lookup name>).get(keyValue)[.<field name>|.*]

The function get searches the first record whose key value is equal to the value specified in the get(keyValue) function. It returns the record of the lookup table. You can map it to other records in CTL2 (with the same metadata). If you want to get the value of the field, you can add the . part to the expression or .* to get the values of all fields. If there is no record with the requested keyValue in the lookup table, the function returns null. The keyVal in the function is a sequence of values of the field names separated by comma (not semicolon!). The key has the following form: keyValuePart1,keyValuePart2,…​,keyValuePartN.

Example 335. Usage of get There is a lookup table users having fields name, surname, phone. The key is formed by fields name and surname. The phone of John Smith is acquired by the statement:

$out.0.phone = lookup(users).get("John", "Smith").phone;

You can get the whole record:

UsersMetadata u = lookup(users).get("John", "Smith");

As the get() function returns null if no record is found, getting the whole records allows you to do better error handling.

UsersMetadata u = lookup(users).get("John", "Smith");
if ( ! isnull ( u ) ) {
    $out.0.phone = u.phone;
}

See also: count, next, put

next

lookup(<lookup name>).next()[.<field name>|.*]

The next() function allows you to iterate the result of the search. It moves the pointer to the next record and returns this record. It returns the next record with the same key. If there is no such record, it returns null.

Example 336. Usage of next The basic usage:

Record tmp = lookup(users).next()

The next() function is generally used in combination with get() function:

// Process all records from a lookup
User user = lookup(users).get($in.0.userId);

while ( ! isnull ( user ) ) {
    // Do something with user

    // Grab next user
    user = lookup(users).next();
}

See also: get, isnull

put

lookup(<lookup name>).put(<record>)

The put() function stores the record passed as its argument in the selected lookup table. It returns a boolean result indicating whether the operation has succeeded or not. Note that the metadata of the passed record must match the metadata of the lookup table. The operation may not be supported by all types of lookup tables (it is not supported by Database lookup tables, for example) and its exact semantics is implementation-specific (in particular, the stored records may not be immediately available for reading in the same phase).

Example 337. Usage of put

//Users is a same record as in the lookup table
Users u;
u.name = "John";
u.surname = "Smith";
u.username = "smithj";
lookup(users).put(u);

Example 338. Usage of Lookup Table Functions A UsersLookup lookup table contains Firstname, Surname, and Username columns. Firstname and Surname fields form the key. Lookup all Usernames for each particular Firstname and Surname tuple received from an input port.

//#CTL2

function integer transform() {
    string[] usernames;

    // getting the first record
    // whose key value equals to $in.0.Surname, $in.0.Firstname tuple
    UsersMetadata usersRecord = lookup(UsersLookup).get($in.0.Surname, $in.0.Firstname);

    // iterate through all records found
    while ( ! isnull( usersRecord ) ) {
        usernames = append( usernames, usersRecord.Username);

        // searching the next record with the key specified above
        usersRecord = lookup(UsersLookup).next();
    }

    // mapping to the output
    $out.0.Surname   = $in.0.Surname;
    $out.0.Firstname = $in.0.Firstname;
    $out.0.Username  = usernames;

    return ALL;
}

Remember that DB lookup tables cannot be used in compiled mode. (code starts with the following header: //#CTL2:COMPILE). You need to switch to interpreted mode (with the header: //#CTL2) to be able to access DB lookup tables from CTL2.

See also: ,

Lookup Tables
get