Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added docs + sample for field names with spaces. closes #2300 #2311

Merged
merged 2 commits into from
Feb 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>