Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version next

...

Excerpt

Returns the index value in the input string where a specified matching string is located in provided column, string literal, or function returning a string. Search is conducted left-to-right.

Input can be specified as a column reference or a string literal, although string literal usage is rare.

  • A column reference can refer to a column of String, Object, or Array type, which makes the FIND function useful for filtering data before it has been completely un-nested into tabular data.
  • Returned value is from the beginning of the string, regardless of the string index value.
  • If no match is found, the function returns a null value.
  • If you need to determine if a value is in an array or not, you can use the MATCHES function, which returns a true/false response. See MATCHES Function.

...

Column reference example:

FIND
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
find(MyName,'find this',true,0)

find(MyName,'find this',true,0)


Output
: Searches the MyName column value for the string find this from the beginning of the value, ignoring case. If a match is found, the index value where the string is located is written to the new columnreturned

String literal example:

FIND
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
find('Hello, World','lo',false,2)

find('Hello, World','lo',false,2)

Output: Searches the string Hello, World for the string lo, in a case-sensitive search, beginning at the third character in the string. Since the match is found at the fourth character, the value 3 is

...

returned.

If example:

IFFIND
d-codelang-syntax
RawWrangletrue
Typeref
showNotetrue
WrangleTextderive type:single value:
if(
find(SearchPool,'FindIt') >= 0, 'found it', '') as: 'Finds'

if(find(SearchPool,'FindIt') >= 0, 'found it', '')


Output
: Searches the SearchPool column value for the string FindIt from the beginning of the value (default). Default behavior is to not ignore case. If the string is found, the new column Finds contains the value found it is returned. Otherwise, the column is empty.

D s
snippetSyntax

FINDcolumn
d-codelang-syntax
RawWrangletrue
Typesyntax
showNotetrue
WrangleTextderive type:single value:
find(
input_string,string_pattern,[ignore_case], [start_index])

find(input_string,string_pattern,[ignore_case], [start_index])


ArgumentRequired?Data TypeDescription
columninput_stringYstringName of the column, function returning a string, or string literal to be applied to the function
string_patternYstringString Name of column, function returning a string, or string literal or pattern to find
ignore_caseNbooleanIf true, a case-insensitive match is performed. Default is false.
start_indexNinteger (non-negative)

If specified, this value identifies the start index value of the source data to search for a match.

If not specified, the entire string is searched.

D s lang notes

...

input_string

Name of the item to be searched. Valid values can be:

  • String literals must be quoted ( 'Hello, World' ).
  • column reference to any type that can be inferred as a string, which encompasses all values.
  • Function returning a string value.

Missing values generate the start-index parameter value.

...

Required?Data TypeExample Value
YesString literal, function returning a string, or column reference (String, Array, or Object)myColumn

string_pattern

String Column of strings, , function returning a string, string literal or pattern to find. This An input value can be a string literal,  

D s item
itempattern
rtrue
, or a regular expression.

...

The transaction stream includes test transactions, which are identified by the value TEST for TransType in the detail column. You want to remove these transactions early in the process, which should simplify your dataset and speed up its processing.

TransformTransformation:

First, you must identify the records that contain the test transaction value. The following transform generates a new column containing true/false values for whether the value "TEST" appears in the OrderDetail transform.

Tip

Tip: You should include the double-quotes around the value, in case the other fields in the array could contain some version of the value TEST. Note that the double quotes need to be escaped, as in the value below.

d-

...

trans
RawWrangletrue
Typestep
WrangleTextderive type:single value:

...

find(OrderDetail, '\"TEST\"', false, 0)
p01NameFormula type
p01ValueSingle row formula
p02NameFormula
p02Valuefind(OrderDetail, '\"TEST\"', false, 0)
SearchTermNew formula

When the step is added to the recipe, the find_OrderDetail column is generated, containing the index value returned by the FIND function. In this case, there is only one row that contains a value: 42 for the third transaction.

You can then add the following step to keep the rows where the FIND function returned a null value in the find_OrderDetail column:

d-

...

trans
RawWrangletrue
p03Valueisnull(find_OrderDetail)
Typestep
WrangleTextkeep row:

...

isnull(find_OrderDetail)
p01NameCondition
p01ValueCustom formula
p02NameType of formula
p02ValueCustom single
p03NameCondition
p04ValueKeep matching rows
p04NameAction
SearchTermFilter rows

Results:

TransactionIdCustomerIdOrderDetailfind_OrderDetail
12312312100023[{"ProdId":"54321","Qty":"5","TransType":"PURCHASE"}] 
12312313100045[{"ProdId":"94105","Qty":"12","TransType":"PURCHASE"}] 
12312315100068[{"ProdId":"85858","Qty":"9","TransType":"PURCHASE"}] 

...