Generate Data - Data360_Analyze - Latest

Data360 Analyze Server Help

Product type
Software
Portfolio
Verify
Product family
Data360
Product
Data360 Analyze
Version
Latest
Language
English
Product name
Data360 Analyze
Title
Data360 Analyze Server Help
Copyright
2024
First publish date
2016
Last updated
2024-11-28
Published on
2024-11-28T15:26:57.181000

Create data using scripted Python.

You can use this node to create data from a Python script when you want to perform an operation that does not require an input.

Example

This example generates random age, sex and name data.

The new fields and the number of records to output are defined in the ConfigureFields property.

The CreateRecords property defines the details:

  • The sex can be either 'Male' or 'Female'.
  • The age can be between 0 and 100.
  • The name consists of a capital letter, which can be followed by a vowel and then up to seven other random letters.

Enter the following script in the ConfigureFields property:

import random
import string
numRecords = 23
out1.sex = str
out1.age = int
out1.name = str
vowels = 'aeiou'

Enter the following script in the CreateRecords property:

for i in range(numRecords):
    myBool = random.randint(0,1)
    if myBool == 1:
        out1.sex = "Male"
    else:
        out1.sex = "Female"

    out1.age = random.randint(0,100)

    myName = ""
    nameLength = random.randint(0,9)
    for j in range(nameLength):
        if j == 0:
            letters = string.ascii_uppercase
        elif j ==1:
            letters = vowels
        else:
            letters = string.ascii_lowercase
        myName = myName + random.choice(letters)

    out1.name = myName

    node.write(0,out1)
      

Tip: When processing a high volume of records (100+ million records) with large string values, consider using StringIO objects from the Python StringIO module for improved performance. For more information, see the Python documentation at https://docs.python.org/2/library/stringio.html.

For information on importing pure Python modules to use in the Generate Data node, see importing pure Python modules.

Properties

ConfigureFields

Specify the Python script to configure the node outputs and output fields.

This script is executed once in order to configure the output metadata.

CreateRecords

Specify the Python script to write output records.

ImplicitWriteMode

Optionally specify whether or not the output records will be automatically written by the node after processing the CreateRecords script. Choose from:

  • Always - Unless an output record has been explicitly written within the Python script, or has been explicitly set to None, it will always be written.
  • Never - Output records will never be automatically written. They need to be explicitly written within the CreateRecords script.
  • When Modified - Output records will be automatically written whenever something (including None) has been set on the output record, and the output has not been set to None, and the record has not been explicitly written.

The default value is When Modified.

Consider the following CreateRecords script:

if in1.Status != 'Inactive':   
     out1 += in1     

With ImplicitWriteMode set to When Modified, this record will only be written to the output if the 'Status' field value is not 'Inactive'.

If ImplicitWriteMode is set to Always, the record would be written to the output with the script above. To prevent this, you would use the following script:

if in1.Status != 'Inactive': 
     out1 += in1
else    
     out1 += None     

If ImplicitWriteMode is set to Never, then you would need to provide additional instructions to write the record to the output upon setting the value:

if in1.Status != 'Inactive':   
     out1 += in1  
     node.write(0, out1)

Inputs and outputs

Inputs: None.

Outputs: out1.