Skip to content

Commit

Permalink
Merge pull request #2311 from bamaer/2300
Browse files Browse the repository at this point in the history
  • Loading branch information
hansva committed Feb 11, 2023
2 parents a46db4c + 6746303 commit 73fb99d
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,17 @@ pipeline_Status = CONTINUE_PIPELINE
if (/* your condition here */) pipeline_Status = SKIP_PIPELINE
----

All rows matching the specified condition are removed from the output.
All rows matching the specified condition are removed from the output.

=== Use field names with spaces

Javascript does not allow you to create variables with spaces in the variable name. However, you _can_ work with field names that contain spaces.

For example, to replace all spaces with underscores in a field `field name with spaces`, use the syntax `this["field name with spaces"]`.

The `this` keyword is required. Without it, Javascript will use `field name with spaces` as a character array.

[source, javascript]
----
var new_field = replace(this["field name with spaces"], " ", "_");
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<pipeline>
<info>
<name>javascript-field-name-with-spaces</name>
<name_sync_with_filename>Y</name_sync_with_filename>
<description/>
<extended_description/>
<pipeline_version/>
<pipeline_type>Normal</pipeline_type>
<parameters>
</parameters>
<capture_transform_performance>N</capture_transform_performance>
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
<transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
<created_user>-</created_user>
<created_date>2023/02/11 13:18:39.802</created_date>
<modified_user>-</modified_user>
<modified_date>2023/02/11 13:18:39.802</modified_date>
</info>
<notepads>
</notepads>
<order>
<hop>
<from>sample data</from>
<to>use field name with spaces</to>
<enabled>Y</enabled>
</hop>
</order>
<transform>
<name>sample data</name>
<type>DataGrid</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<data>
<line>
<item>dummy field value</item>
</line>
</data>
<fields>
<field>
<length>-1</length>
<precision>-1</precision>
<set_empty_string>N</set_empty_string>
<name>field name with spaces</name>
<type>String</type>
</field>
</fields>
<attributes/>
<GUI>
<xloc>80</xloc>
<yloc>112</yloc>
</GUI>
</transform>
<transform>
<name>use field name with spaces</name>
<type>ScriptValueMod</type>
<description/>
<distribute>Y</distribute>
<custom_distribution/>
<copies>1</copies>
<partitioning>
<method>none</method>
<schema_name/>
</partitioning>
<optimizationLevel>9</optimizationLevel>
<jsScripts>
<jsScript>
<jsScript_type>0</jsScript_type>
<jsScript_name>Script 1</jsScript_name>
<jsScript_script>
// new variable names can't contain spaces, but variable names with spaces can be used.
// check "Naming variables" in https://www.javascript.com/learn/variables
// or "Javascript Identifiers" in https://www.w3schools.com/js/js_variables.asp

var new_field = replace(this["field name with spaces"], " ", "_");</jsScript_script>
</jsScript>
</jsScripts>
<fields>
<field>
<name>new_field</name>
<rename>new_field</rename>
<type>String</type>
<length>-1</length>
<precision>-1</precision>
<replace>N</replace>
</field>
</fields>
<attributes/>
<GUI>
<xloc>256</xloc>
<yloc>112</yloc>
</GUI>
</transform>
<transform_error_handling>
</transform_error_handling>
<attributes/>
</pipeline>

0 comments on commit 73fb99d

Please sign in to comment.