Skip to content

Commit

Permalink
updated some tutorial content
Browse files Browse the repository at this point in the history
  • Loading branch information
ydahal3 committed Sep 7, 2023
1 parent a6e0ced commit f4a6309
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 0 deletions.
67 changes: 67 additions & 0 deletions learnEcl/1500-if.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,70 @@
title: If
slug: if
---

# IF Statement

The IF function allows you to make a logical comparison between value(s) and what returning a result if that condition is True or False.

## Syntax

<pre>
<EclCode code = "attr_name := IF(expression, true_result [, false_result])
">
</EclCode>
</pre>

| Value | Definition |
| :----------- | :----------------------------------------------- |
| attribName | The name by which the variable will be invoked. |
| IF | Required |
| expression | Boolean expression to be check for True or False |
| true_result | Result value or action if expression is True |
| false_result | May be omitted only if true_result is an action |

**Example**

<pre>
<EclCode
id="IfExp_1"
tryMe="IfExp_1"
code="/*
IF Example:
Example includes nested IF*/

Permission := 23;
Age := 12;

Res1 := IF(Permission >= Age, 'Application Accepted', 'Application Rejected');

Flag := FALSE;
Res2 := IF(Flag, ', Try Again', ', Move on');

Final := IF(Res1 = 'Application Accepted' AND Res2 = ', Move on',
OUTPUT(Res1 + Res2, NAMED('Passed')),
OUTPUT(Res1 + Res2, NAMED('Failed'))
);

Final;">
</EclCode>
</pre>

## Logical Operators

Logical values that can be used for comparison of two values.

| Operator | Description |
| :-------- | :----------------------------------------------------------------- |
| `=` | Equal |
| ` >` | Greater than |
| `<` | Less than |
| `>=` | Greater than or equal |
| `<=` | Less than or equal |
| `<>` | Not equal |
| `!= ` | Not equal |
| `~` | Not |
| `AND` | Logical AND |
| `OR` | Logical OR |
| `IN` | To specify multiple possible values for a field/column |
| `NOT IN` | To specify multiple possible values that are not in a field/column |
| `BETWEEN` | Between a certain range |
56 changes: 56 additions & 0 deletions learnEcl/1600-choose.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,59 @@
title: Choose
slug: choose
---

# CHOOSE

CHOOSE function eEvaluates the expression and returns the value parameter whose ordinal position in the list of parameters corresponds to the result of the expression. All values for this function must have the same type. If no match is found it will return the else-value.

**Example**

<pre >
<EclCode
id="ChooseExp_1"
tryMe="ChooseExp_1"
code="/*CHOOSE Example:*/

Eval := 4;

CHOOSE(Eval, 2, 3, 5, 6, 20); // Returns 6

CHOOSE(Eval, 6, 6, 7, 10, 9, 11); // Returns 10

CHOOSE(Eval, 3, 4, 8); // Returns 8 (the else value)">
</EclCode>
</pre>

## Syntax

<pre>
<EclCode code="CHOOSE(Expression, Value1,... , ValueN, Else);">
</EclCode>
</pre>

| _Value_ | _Definition_ |
| :-------------- | :---------------------------------------------- |
| Expression | Evaluation field |
| Value1 … ValueN | If expression matches it will return the result |
| Else | If nothing matches else-value is returned |

**Example**

<pre>
<EclCode
id="ChooseExp_2"
tryMe="ChooseExp_2"
code="java
/*
CHOOSE Example:
*/

CHOOSE(2, 3, 5, 6, 20); // Returns 5

CHOOSE(3, 'foo', 'bar', 'baz'); // Returns 'baz'

getVal := CHOOSE(5, 'foo', 'bar', 'baz'); // Returns 'baz' (the else value)

OUTPUT(getVal, NAMED('getVal'));">
</EclCode>
</pre>
111 changes: 111 additions & 0 deletions learnEcl/1700-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,114 @@
title: Map
slug: map
---

# MAP Function

MAP function evaluates the list of Boolean expressions and returns the value associated with the first true expression.

MAP Characteristics

- If no match is found than the else-value is returned
- All return values and else_value values must be of the same type
- All expressions must reference the same level of dataset scoping. Therefore, all expressions must either reference fields in the same dataset or the existence of a set of related child records
- The expressions are evaluated in the order in which they appear.

## Syntax

<pre>
<EclCode
code="attr_name := MAP(expression1 => value1,
expression2 => value2,
...
...
expressionN => valueN
[,else_value]
)">
</EclCode>
</pre>

| _Value_ | _Definition_ |
| :------------ | :------------------------------------------------------------------------------------------------------------------------------ |
| attr_name | The name by which the function will be invoked |
| MAP | ECL Keyword, required |
| Expression1…N | Boolean expression |
| `=> ` | “Result in” operator |
| Else_value | Optional if all other possible return values are actions, otherwise required. The value to return if all expressions are false. |

**Example**

<pre>
<EclCode code="
/*
MAP Example:
*/

Value := 120;

Assessment := MAP(Value BETWEEN 0 AND 50 => 'Under Estimated',
Value BETWEEN 51 AND 100 => 'About Right',
Value BETWEEN 101 AND 150 => 'Still Acceptable',
Value BETWEEN 151 AND 200 => 'Too High',
'Rejected');

OUTPUT(Assessment, NAMED('Assessment'));">
</EclCode>
</pre>

## Logical Operators

Logical values that can be used for comparison of two values.

**Demo Dataset**

| PersonID | FirstName | LastName | isEmployed | avgHouseIncome |
| :------- | :-------- | :------- | :--------- | :------------- |
| 102 | Fred | Smith | FALSE | 0 |
| 012 | Joe | Blow | TRUE | 11250 |
| 085 | Blue | Moon | TRUE | 185000 |
| 055 | Silver | Jo | FALSE | 5000 |
| 265 | Darling | Jo | TRUE | 5000 |
| 333 | Jane | Smith | FALSE | 50000 |

<pre>
<EclCode
id="MapExp_2"
code="/*
MAP Example:
Using logical operations
*/


Value := 100;
Flag := False;
Letter := 'A';

Assessment := MAP(Value BETWEEN 0 AND 50 OR Flag => 'Under Estimated',
Value BETWEEN 51 AND 100 AND ~Flag => 'About Right',
Value BETWEEN 101 AND 150 AND ~Flag AND Letter = 'A' => 'Still Acceptable',
Value BETWEEN 151 AND 200 => 'Too High',
'Rejected');

OUTPUT(Assessment, NAMED('Assessment'));">
</EclCode>
</pre>

## Logical Operators

Logical values that can be used for comparison of two values.

| Operator | Description |
| :-------- | :----------------------------------------------------------------- |
| `=` | Equal |
| `>` | Greater than |
| `<` | Less than |
| `>=` | Greater than or equal |
| `<=` | Less than or equal |
| `<>` | Not equal |
| `!=` | Not equal |
| `~` | Not |
| `AND` | Logical AND |
| `OR` | Logical OR |
| `IN` | To specify multiple possible values for a field/column |
| `NOT IN` | To specify multiple possible values that are not in a field/column |
| `BETWEEN` | Between a certain range |
79 changes: 79 additions & 0 deletions learnEcl/1800-dedup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,82 @@
title: Dedup
slug: dedup
---

# DEDUP

The DEDUP function removes duplicates from a dataset based on the defined conditions. The result is dataset with unique values for selected fields.

**Note** To use DEDUP you dataset must be **sorted**.

## Syntax

<pre>
<EclCode code="DEDUP(dataset, [, condition])">
</EclCode>
</pre>

| Value | Definition |
| :-------- | :--------------------------------------------------------------------------------------------------- |
| DEDUP | Required. |
| dataset | Input dataset to process. |
| condition | A comma-delimited list of expressions or key fields in the dataset that defines "duplicate" records. |

**Demo Dataset**

| StudentID | Name | City | State | ZipCodeDepartment | |
| :-------- | :---- | :------ | :---- | :---------------- | ------- |
| 300 | Sarah | Dallas | Te | 30000 | Art |
| 400 | Matt | | | Medical |
| 305 | Liz | Atlanta | GA | 30330 | Math |
| 305 | Liz | smyrna | GA | 30330 |
| 100 | Zoro | Atlanta | GA | 30330 |
| 100 | Zoro | smyrna | GA | 30330 |
| 800 | Sandy | | | | Science |
| 604 | Danny | Newyork | NY | 40001 |
| 409 | Dan | Newyork | NY | 40001 | Medical |
| 300 | Sarah | Dallas | TX | 30000 | Math |

**Example**

<pre>
<EclCode
id="DedupExp_1"
tryMe="DedupExp_1"
code="/*
DEDUP Example:
Deduping the input dataset based on different fields.
Keep in mind that for DEDUP your dataset must be sorted.
*/

Student_Rec := RECORD
INTEGER StudentID;
STRING Name;
STRING City;
STRING2 State;
STRING5 ZipCode;
STRING Department;
END;

Student_DS := DATASET([
{300, 'Sarah', 'Dallas', 'Te', '30000', 'Art'},
{400, 'Matt', '', '', '', 'Medical'},
{305, 'Liz', 'Atlanta', 'GA', '30330', 'Math'},
{305, 'Liz', 'smyrna', 'GA', '30330', ''},
{100, 'Zoro', 'Atlanta', 'GA', '30330', ''},
{100, 'Zoro', 'smyrna', 'GA', '30330', ''},
{800, 'Sandy', '', '', '', 'Science'},
{604, 'Danny', 'Newyork', 'NY', '40001', ''},
{409, 'Dan', 'Newyork', 'NY', '40001', 'Medical'},
{300, 'Sarah', 'Dallas', 'Te', '30000', 'Math'}],
Student_Rec);


// Above dataset is already sorted.

DupMe := DEDUP(SortDS, StudentID, Name);
OUTPUT(DupMe, NAMED('DupMe'));

DupExp := DEDUP(SortDS, Name, Department);
OUTPUT(DupExp, NAMED('DupExp'));">
</EclCode>
</pre>
Loading

0 comments on commit f4a6309

Please sign in to comment.