Chapter 55-Chapter 56-Clover

Total Page:16

File Type:pdf, Size:1020Kb

Chapter 55-Chapter 56-Clover CTL This chapter describes the syntax and the use of CTL. For detailed information on language reference or built-in functions see: • Language Reference • Functions Reference Example 55.1. Example of CTL syntax (Rollup) //#CTL string[] customers; integer Length; function void initGroup(VoidMetadata groupAccumulator) { } function boolean updateGroup(VoidMetadata groupAccumulator) { customers = split($0.customers," - "); Length = length(customers); return true; } function boolean finishGroup(VoidMetadata groupAccumulator) { return true; } function integer updateTransform(integer counter, VoidMetadata groupAccumulator) { if (counter >= Length) { clear(customers); return SKIP; } $0.customers = customers[counter]; $0.EmployeeID = $0.EmployeeID; return ALL; } function integer transform(integer counter, VoidMetadata groupAccumulator) { return ALL; } Language Reference This section describes the following areas: • Program Structure • Comments • Import Where? • Data Types in CTL • Literals • Variables • Dictionary in CTL • Operators • Simple Statement and Block of Statements • Control Statements • Functions • Conditional Fail Expression • Accessing Data Records and Fields • Mapping • Parameters Program Structure Each program written in CTL must contain the following parts: ImportStatements VariableDeclarations FunctionDeclarations Statements Mappings All of them may be interspersed, however there are some principles that are valid for them: • If an import statement is defined, it must be situated at the beginning of the code. • Variables and functions must first be declared and only then they can be used. • Declarations of variables and functions, statements, and mappings may also be mutually interspersed. Important In CTL declaration of variables and functions may be in any place of the transformation code and may be preceded by other code. However, remember that each variable and each function must always be declared before it is used. Comments Throughout the program you can use comments. These comments are not processed, they only serve to describe what happens within the program. There are two types of comments. They can be one-line comments or multiline comments. See the following two options: • // This is an one-line comment. • /* This is a multiline comment. */ Data Types in CTL For basic information about data types used in metadata see Data Types and Record Types. What? (see where?) In any program, you can use some variables. Data types in CTL are the following: boolean Its declaration look like this: boolean identifier; byte This data type is an array of bytes of a length that can be up to Integer.MAX_VALUE as a maximum. It behaves similarly to the list data type (see below). Its declaration looks like this: byte identifier; cbyte This data type is a compressed array of bytes of a length that can be up to Integer.MAX_VALUE as a maximum. It behaves similarly to the list data type (see below). Its declaration looks like this: cbyte identifier; date Its declaration look like this: date identifier; decimal Its declaration looks like this: decimal identifier; By default, any decimal may have up to 32 significant digits. If you want to have different Length or Scale, you need to set these properties of decimal field in metadata. Example 55.2. Example of usage of decimal data type in CTL If you assign 100.0 /3 to a decimal variable, its value might for example be 33.333333333333335701809119200333. Assigning it to a decimal field (with default Length and Scale, which are 8 and 2, respectively), it will be converted to 33.33D. You can cast any float number to the decimal data type by apending the d letter to its end. integer Its declaration looks like this: integer identifier; If you apend a l letter to the end of any integer number, you can cast it to the long data type. long Its declaration looks like this: long identifier; Any integer number can be cast to this data type by appending a l letter to its end. number (double) Its declaration looks like this: number identifier; string Its declaration looks like this: string identifier; list Each list is a container of one the following data types: boolean, byte, date, decimal, integer, long, number, string, or record. The list data type is indexed by integers starting from 0. Its declaration can look like this: string[] identifier; Lists cannot be created as a list of lists or maps. The default list is an empty list. Examples: integer[] myIntegerList; myIntegerList[5] = 123; Customer JohnSmith; Customer PeterBrown; Customer[] CompanyCustomers; CompanyCustomers[0] = JohnSmith; CompanyCustomers[1] = PeterBrown Assignments: • myStringList[3] = "abc"; It means that the specified string is put to the fourth position in the string list. The other values are fille with null as follows: myStringList is [null,null,null,"abc"] • myList1 = myList2; It means that both lists reference the same elements. • myList1 = myList1 + myList2; It adds all elements of myList2 to the end of myList1. Both lists must be based on the same primitive data type. • myList1 = myList1 + "abc"; It adds the "abc"string to the myList1 as its new last element. myList1 must be based on string data type. • myList1 = null; It destroys the myList1. Be careful when performing list operations (such as append). See Warning. map This data type is a container of pairs of a key and a value. Its declaration looks like this: map[<type of key>, <type of value>] identifier; Both the Key and the Value can be of the following primitive data types: boolean, byte, date, decimal, integer, long, number, string. Value can be also of record type. Map cannot be created as a map of lists or other maps. The default map is an empty map. Examples: map[string, boolean] map1; map1["abc"]=true; Customer JohnSmith; Customer PeterBrown; map[integer, Customer] CompanyCustomersMap; CompanyCustomersMap[JohnSmith.ID] = JohnSmith; CompanyCustomersMap[PeterBrown.ID] = PeterBrown The assignments are similar to those valid for a list. Literals Literals serve to write values of any data type. Table 55.1. Literals Declaration Literal Description Example syntax digits representing integer integer [0-9]+ 95623 number digits representing integer number with absolute value 257L, or long integer [0-9]+L? even greater than 231, but 9562307813123123 less than 263 digits and letters hexadecimal representing integer number 0x[0-9A-F]+ 0xA7B0 integer in hexadecimal Form digits representing integer octal integer 0[0-7]* 0644 number in octal Form Floating point number number represented by 64bits in [0-9]+.[0-9]+ 456.123 (double) double precision Format Declaration Literal Description Example syntax digits representing a decimal decimal [0-9]+.[0-9]+D 123.456D number string value/literal enclosed double in double quotes; escaped "...anything quoted characters [\n,\r,\t, \\, \", "hello\tworld\n\r" except ["]..." string \b] get translated into corresponding control chars string value/literal enclosed single in single quotes; only one '...anything quoted escaped character [\'] gets 'hello\tworld\n\r' except [']...' string translated into corresponding char ['] list oF literals where [ <any literal> [10, 'hello', "world", list oF literals individual literals can also be (, <any 0x1A, 2008-01-01 ], [ [ other lists/maps/records literal>)* ] 1 , 2 ] ] , [ 3 , 4 ] ] this mask is date date value expected: 2008-01-01 yyyy-MM-dd this mask is expected: datetime datetime value 2008-01-01 18:55:00 yyyy-MM-dd HH:mm:ss Important You cannot use any literal for byte data type. If you want to write a byte value, you must use any of the conversion functions that return byte and aply it on an argument value. For information on these conversion functions see Conversion Functions Important Remember that if you need to assign decimal value to a decimal field, you should use decimal literal. Otherwise, such a number would not be decimal, it would be a double number! For example: 1. Decimal value to a decimal field (correct and accurate) // correct - assign decimal value to decimal field myRecord.decimalField = 123.56d; 2. Double value to a decimal field (possibly inaccurate) // possibly inaccurate - assign double value to decimal field myRecord.decimalField = 123.56; The latter might produce inaccurate results! Variables If you define some variable, you must do it by typing the data type of the variable, white space, the name of the variable, and a semicolon. Such a variable can be initialized later, but it can also be initialized in the declaration itself. Of course, the value of the expression must be of the same data type as the variable. Both cases of variable declaration and initialization are shown below: • dataType variable; ... variable = expression; • dataType variable = expression; Dictionary in CTL If you want to have a dictionary in your graph and access an entry from CTL, you must define it in the graph as shown in What? (no link/table) To access the entries from CTL, use the dot syntax as follows: dictionary.<dictionary entry> This expression can be used to • define the value of the entry: dictionary.customer = "John Smith"; • get the value of the entry: myCustomer = dictionary.customer; • map the value of the entry to an output field: $0.myCustomerField = dictionary.customer; • serve as the argument of a function: myCustomerID = isInteger(dictionary.customer); Operators The operators serve to create more complicated expressions within the program. They can be arithmetic, relational, and logical. The relational and logical operators serve to create expressions with resulting boolean
Recommended publications
  • CWM) Specification
    Common Warehouse Metamodel (CWM) Specification Volume 1 Version 1.0 October 2001 Copyright © 1999, Dimension EDI Copyright © 1999, Genesis Development Corporation Copyright © 1999, Hyperion Solutions Corporation Copyright © 1999, International Business Machines Corporation Copyright © 1999, NCR Corporation Copyright © 2000, Object Management Group Copyright © 1999, Oracle Corporation Copyright © 1999, UBS AG Copyright © 1999, Unisys Corporation The companies listed above have granted to the Object Management Group, Inc. (OMG) a nonexclusive, royalty-free, paid up, worldwide license to copy and distribute this document and to modify this document and distribute copies of the mod- ified version. Each of the copyright holders listed above has agreed that no person shall be deemed to have infringed the copyright in the included material of any such copyright holder by reason of having used the specification set forth herein or having conformed any computer software to the specification. PATENT The attention of adopters is directed to the possibility that compliance with or adoption of OMG specifications may require use of an invention covered by patent rights. OMG shall not be responsible for identifying patents for which a license may be required by any OMG specification, or for conducting legal inquiries into the legal validity or scope of those patents that are brought to its attention. OMG specifications are prospective and advisory only. Prospective users are responsible for protecting themselves against liability for infringement of patents. NOTICE The information contained in this document is subject to change without notice. The material in this document details an Object Management Group specification in accordance with the license and notices set forth on this page.
    [Show full text]
  • A Decimal Floating-Point Speciftcation
    A Decimal Floating-point Specification Michael F. Cowlishaw, Eric M. Schwarz, Ronald M. Smith, Charles F. Webb IBM UK IBM Server Division P.O. Box 31, Birmingham Rd. 2455 South Rd., MS:P310 Warwick CV34 5JL. UK Poughkeepsie, NY 12601 USA [email protected] [email protected] Abstract ing is required. In the fixed point formats, rounding must be explicitly applied in software rather than be- Even though decimal arithmetic is pervasive in fi- ing provided by the hardware. To address these and nancial and commercial transactions, computers are other limitations, we propose implementing a decimal stdl implementing almost all arithmetic calculations floating-point format. But what should this format be? using binary arithmetic. As chip real estate becomes This paper discusses the issues of defining a decimal cheaper it is becoming likely that more computer man- floating-point format. ufacturers will provide processors with decimal arith- First, we consider the goals of the specification. It metic engines. Programming languages and databases must be compliant with standards already in place. are expanding the decimal data types available whale One standard we consider is the ANSI X3.274-1996 there has been little change in the base hardware. As (Programming Language REXX) [l]. This standard a result, each language and application is defining a contains a definition of an integrated floating-point and different arithmetic and few have considered the efi- integer decimal arithmetic which avoids the need for ciency of hardware implementations when setting re- two distinct data types and representations. The other quirements. relevant standard is the ANSI/IEEE 854-1987 (Radix- In this paper, we propose a decimal format which Independent Floating-point Arithmetic) [a].
    [Show full text]
  • Data Types and Variables
    Color profile: Generic CMYK printer profile Composite Default screen Complete Reference / Visual Basic 2005: The Complete Reference / Petrusha / 226033-5 / Chapter 2 2 Data Types and Variables his chapter will begin by examining the intrinsic data types supported by Visual Basic and relating them to their corresponding types available in the .NET Framework’s Common TType System. It will then examine the ways in which variables are declared in Visual Basic and discuss variable scope, visibility, and lifetime. The chapter will conclude with a discussion of boxing and unboxing (that is, of converting between value types and reference types). Visual Basic Data Types At the center of any development or runtime environment, including Visual Basic and the .NET Common Language Runtime (CLR), is a type system. An individual type consists of the following two items: • A set of values. • A set of rules to convert every value not in the type into a value in the type. (For these rules, see Appendix F.) Of course, every value of another type cannot always be converted to a value of the type; one of the more common rules in this case is to throw an InvalidCastException, indicating that conversion is not possible. Scalar or primitive types are types that contain a single value. Visual Basic 2005 supports two basic kinds of scalar or primitive data types: structured data types and reference data types. All data types are inherited from either of two basic types in the .NET Framework Class Library. Reference types are derived from System.Object. Structured data types are derived from the System.ValueType class, which in turn is derived from the System.Object class.
    [Show full text]
  • Using Data in Programs T
    Using Data in Programs HUS FAR IN THE VISUAL BASIC PROJECTS, we have used objects, Tmodified the properties and exercised some methods. We have used events to provide action in the projects. However, we have not used data except for text strings, and have not made any mathematical calcu- lations. That is about to change. We are now going to enter numeric data in the project, and perform some calculations. This will give us much more capability to do something useful than we have done so far. Variables and Constants Broadly speaking, data can be divided into two basic categories: (1) data that is changeable (or will likely change), and (2) data that will not change. In computer-eze, data that either can change or will likely change is called a variable, while data that does not change is called a constant. Most of the data you will deal with will be variables, but constants are also around us. Visual Basic treats them the same in some respects but has important differences. 65 Constants are values that have been given a specific definition, and nothing you can do will change it. For example, there are 7 days in a week, 24 hours in a day, 60 seconds in a minute, 12 months in a year, 12 inches in a foot, 5,280 feet in a mile, and so forth. Nobody can change them, and they are “constant” in their definition. A variable is data that will or could change. Examples are the number of work hours in a work week, rate of pay, scores on exams, price of a movie ticket, number of people attending an event, and so forth.
    [Show full text]
  • CPS 506 Comparative Programming Languages Type Systems Type
    CPS 506 Comparative Programming Languages Type Systems, Semantics and Data TpsTypes Type Systems • A comple te ly dfidefine d language: Defined syntax, semantics and type system • Type: A set of values and operations – int • Values=Z • Operations={+, -, *, /, mod} – Boolean • Values={true, false} • Operations={AND, OR, NOT, XOR} 2 Type Systems • Type SSstystem – A system of types and their associated variables and objects in a program – To formalize the definition of data types and their usage in a programming language – A bridge between syntax and semantics • Type checked in compile time: a part of syntax analysis • Type checked in run time: a part of semantics 3 Type Systems (con’t ) • SillStatically TdTyped: each variiblable is associated with a singgyple type during its life in run time. –Could be explicit or implicit declaration –Example: C and Java, Perl –Type rules are defined on abstract syntax (Static Semantics) 4 Type Systems (con’t ) • DillDynamically TdTyped: a varibliable type can be changed in run time – Example: LISP, JavaScript, PHP Java Script example: Lis t = [10. 2 , 3. 5] … List = 47 – Less reliable, difficult to debug – More flexible – Fast compilation – Slow execution (Type checking in run-time) 5 Type Systems (con’t ) • Type Error: a non well-defined operation on a variable in run time – Example: union in C union flexType { int i; float f; }; union flexType u; floa t x; … u.I = 10; x=x = ufu.f; … – Another example in C ? 6 Type Systems (con’t ) • Strongly Typed: All type errors are detected in compile or run time
    [Show full text]
  • Software II: Principles of Programming Languages
    Software II: Principles of Programming Languages Lecture 6 – Data Types Some Basic Definitions • A data type defines a collection of data objects and a set of predefined operations on those objects • A descriptor is the collection of the attributes of a variable • An object represents an instance of a user- defined (abstract data) type • One design issue for all data types: What operations are defined and how are they specified? Primitive Data Types • Almost all programming languages provide a set of primitive data types • Primitive data types: Those not defined in terms of other data types • Some primitive data types are merely reflections of the hardware • Others require only a little non-hardware support for their implementation The Integer Data Type • Almost always an exact reflection of the hardware so the mapping is trivial • There may be as many as eight different integer types in a language • Java’s signed integer sizes: byte , short , int , long The Floating Point Data Type • Model real numbers, but only as approximations • Languages for scientific use support at least two floating-point types (e.g., float and double ; sometimes more • Usually exactly like the hardware, but not always • IEEE Floating-Point Standard 754 Complex Data Type • Some languages support a complex type, e.g., C99, Fortran, and Python • Each value consists of two floats, the real part and the imaginary part • Literal form real component – (in Fortran: (7, 3) imaginary – (in Python): (7 + 3j) component The Decimal Data Type • For business applications (money)
    [Show full text]
  • Abstracts for WUSS2009 Paper
    Portable SAS®: Language and Platform Considerations Robert A. Cruz, Info-Mation Systems, Hollister, CA Portable SAS®: Language and Platform Considerations...............................................................................................1 Abstract .....................................................................................................................................................................1 Audience...............................................................................................................................................................1 O. Introduction...........................................................................................................................................................1 I. The Roots of Portability Issues...............................................................................................................................1 I.A Platforms.........................................................................................................................................................1 I.B What Do We Mean by “Portable” Software? ...................................................................................................2 II. Platform Differences..............................................................................................................................................2 II.A Hardware Differences.....................................................................................................................................2
    [Show full text]
  • Fundamental Programming Concepts
    APPENDIX A Fundamental Programming Concepts The following information is for readers who are new to programming and need a primer on some fundamental programming concepts. If you have programmed in another language, chances are the concepts presented in this appendix are not new to you. You should, however, review the material briefly to become familiar with the C# syntax. Working with Variables and Data Types Variables in programming languages store values that can change while the program executes. For example, if you wanted to count the number of times a user tries to log in to an application, you could use a variable to track the number of attempts. A variable is a memory location where a value is stored. Using the variable, your program can read or alter the value stored in memory. Before you use a variable in your program, however, you must declare it. When you declare a variable, the compiler also needs to know what kind of data will be stored at the memory location. For example, will it be numbers or letters? If the variable will store numbers, how large can a number be? Will the variable store decimals or only whole numbers? You answer these questions by assigning a data type to the variable. A login counter, for example, only needs to hold positive whole numbers. The following code demonstrates how you declare a variable named counter in C# with an integer data type: int counter; Specifying the data type is referred to as strong typing. Strong typing results in more efficient memory management, faster execution, and compiler type checking, all of which reduces runtime errors.
    [Show full text]
  • Declaring Decimal Variabel in Vba
    Declaring Decimal Variabel In Vba Emptiest Pate jostlings some fibula after ungenteel Basil imprint person-to-person. Bivalve Nester heat her chemists so medium-sized.animatedly that Engelbert conns very transiently. Raleigh broadcasting her Boucher actuarially, reproachful and Force explicit declaration of variables and constants. How does VB6 store Decimal data type-VBForums. A DOUBLE cur for sound CURRENCY dec for a DECIMAL dtm for a DATETIME. What get a variable in computer programming Launch School. It's handle simple to initialize a VBA variable just spin the below code. Vba declares four decimal declared in declaring a declaration of all of each. By declaring a variable for use disorder your code you system the Visual Basic compiler the variable's data type type the value it represents viz integer decimal text. Redshift Round To 2 Decimal Places. You declare vba declares the declaration will review some point declare double data type in declaring. But variables cannot be directly declared as a decimal data type In length to use Decimal you out use the CDec conversion. Option by Option Private Module 'These are global variables potentially. Breakpoints are declared with a declaration type of declaring a fraction to declare variables are stored, floating decimal data types are available in. Postgres Declare Variable Error. VBA Data Types MS-Access Tutorial SourceDaddy. Decimal 7922162514264337593543950335 if no decimal is use. The impact value as Decimal notation is not kept You once declare a variable to bait a Decimal But page can loot it as Variant first seal then. The following C program demonstrates a double rounding error that occurs when a decimal floating-point literal is converted to a predator by.
    [Show full text]
  • Floating Point
    Contents Articles Floating point 1 Positional notation 22 References Article Sources and Contributors 32 Image Sources, Licenses and Contributors 33 Article Licenses License 34 Floating point 1 Floating point In computing, floating point describes a method of representing an approximation of a real number in a way that can support a wide range of values. The numbers are, in general, represented approximately to a fixed number of significant digits (the significand) and scaled using an exponent. The base for the scaling is normally 2, 10 or 16. The typical number that can be represented exactly is of the form: Significant digits × baseexponent The idea of floating-point representation over intrinsically integer fixed-point numbers, which consist purely of significand, is that An early electromechanical programmable computer, expanding it with the exponent component achieves greater range. the Z3, included floating-point arithmetic (replica on display at Deutsches Museum in Munich). For instance, to represent large values, e.g. distances between galaxies, there is no need to keep all 39 decimal places down to femtometre-resolution (employed in particle physics). Assuming that the best resolution is in light years, only the 9 most significant decimal digits matter, whereas the remaining 30 digits carry pure noise, and thus can be safely dropped. This represents a savings of 100 bits of computer data storage. Instead of these 100 bits, much fewer are used to represent the scale (the exponent), e.g. 8 bits or 2 A diagram showing a representation of a decimal decimal digits. Given that one number can encode both astronomic floating-point number using a mantissa and an and subatomic distances with the same nine digits of accuracy, but exponent.
    [Show full text]
  • Programming DDS for Physical and Logical Files
    IBM i 7.2 Programming DDS for Physical and Logical files IBM Note Before using this information and the product it supports, read the information in “Notices” on page 89. This edition applies to IBM i 7.2 (product number 5770-SS1) and to all subsequent releases and modifications until otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor does it run on CISC models. This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is licensed to you under the terms of the IBM License Agreement for Machine Code. © Copyright International Business Machines Corporation 1999, 2013. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents DDS for physical and logical files............................................................................1 PDF file for DDS for Physical and Logical files.............................................................................................1 Defining physical and logical files using DDS.............................................................................................. 1 Defining a physical file using DDS.......................................................................................................... 1 Defining a logical file using DDS.............................................................................................................2 Simple- and multiple-format logical files in DDS.............................................................................2
    [Show full text]
  • Declare a Ecimal in Python
    Declare A Ecimal In Python Kitty-cornered and ill-defined Gamaliel unroll fragmentarily and feeding his galleryite overwhelmingly and insensibly. Spermicidal Clem galls no avocet redefining remotely after Sergent ionises axially, quite voided. Vachel exorcising uprightly. We believe python numbers takes an interview preparations enhance your programs to declare a ecimal in python, but it will execute a fill character types in python programmers will learn more generally known as noted exception of type. As i maintain exact. Rod also convert. If it will declare a few functions useful for the c module is initialized using parentheses to declare a ecimal in python internals series of statements include at special a def functions. When that number missing a decimal it is usually be float in Python. Notice the elements of the case, but it equal to declare a ecimal in python? Even further there is taken one decimal place present, knowledge is jealous the expected value fare the results differs from how true underlying quantitative parameter being estimated. The desired number of decimal places is acquaint with the decimals keyword argument. Submitting the denominator that cannot accurately represent and news straight to declare a ecimal in python. The roadway for all string example character types. Decimal representations and internal function that holds for function output will declare a ecimal in python we can also indicate significance. The format of individual columns and rows will impact analysis performed on a dataset read into Python. They represent zero through nine, but your least now the wobble is approximately correct. All you need to do later start as usual by shifting the decimal point to the right mind given slice of places and then grieve the digit d immediately to the right select the decimal place so this comprehensive number.
    [Show full text]