Home > Hadrian >

Titus’s pfarandom script generates a placeholder PFA document, given an input Avro schema and an output Avro schema. The action generated by this script ignores the input and produces random output. That is, the generated PFA file is determined, but the output generated when the scoring engine runs is random.

This script is typically only used for testing a scoring engine consumer. A particular application may need data in a specified form (specified by Avro schemas), but it’s not important what that scoring engine does. The pfarandom script quickly makes such a test function.

Before you begin…

Download and install Titus. This article was tested with Titus 0.8.3; newer versions should work with no modification. Python >= 2.6 and < 3.0 is required.

Help document

A good place to start is pfarandom’s own help text, which will always show the latest options.

usage: pfarandom [-h] [--check] [--exception EXCEPTION] [--name NAME]
                 [--randseed RANDSEED] [--doc DOC] [--version VERSION]
                 [--metadata METADATA] [--options OPTIONS]
                 input output [fileName]

Given an input and an output schema, generate a PFA file that only computes
random outputs (for tests).

positional arguments:
  input                 input schema file (Avro schema in JSON format)
  output                output schema file (Avro schema in JSON format)
  fileName              output PFA file name or "-" for standard out

optional arguments:
  -h, --help            show this help message and exit
  --check               if supplied, the PFA will be tested with 100 samples,
                        written to standard error
  --exception EXCEPTION
                        probability of runtime exception (must be between 0
                        and 1, inclusive)
  --name NAME           name field for output PFA file
  --randseed RANDSEED   randseed field for output PFA file (must be an
  --doc DOC             doc field for output PFA file
  --version VERSION     version field for output PFA file (must be an integer)
  --metadata METADATA   metadata field for output PFA file (must be a JSON map
                        of strings)
  --options OPTIONS     options field for output PFA file (must be a JSON map)


Create a simple input.avsc (integers) and a complex output.avsc (records), then test-run it in Hadrian-Standalone.

% cat > input.avsc
% cat > output.avsc
{"type": "record",
 "name": "Test",
 "fields": [{"name": "one", "type": "int"},
            {"name": "two", "type": "double"},
            {"name": "three", "type": "string"},
            {"name": "four", "type": {"type": "array", "items": "boolean"}}]}
% pfarandom input.avsc output.avsc test.pfa
% java -jar hadrian-standalone-0.8.3-jar-with-dependencies.jar -i json -o json test.pfa

Give it a 30% chance of throwing an exception, rather than returning a result.

% pfarandom input.avsc output.avsc test.pfa --exception 0.3                                                            
% java -jar hadrian-standalone-TRUNK-jar-with-dependencies.jar -i json -o json test.pfa
Exception in thread "Hadrian-engine-0" com.opendatagroup.hadrian.errors.PFAUserException: thrown with probability 0.3 at JSON line:col 1:23 (PFA field "action -> 0 -> then")
        at PFA_Engine_1$2$1$1.apply(Unknown Source)
        at PFA_Engine_1$2$1.apply(Unknown Source)
        at PFA_Engine_1$2.apply(Unknown Source)
        at PFA_Engine_1.action(Unknown Source)
        at PFA_Engine_1.action(Unknown Source)
        at com.opendatagroup.hadrian.standalone.Main$$anonfun$main$1$EngineRunnable$1.action(standalone.scala:196)
        at com.opendatagroup.hadrian.standalone.Main$$anonfun$main$1$EngineRunnable$1$$anonfun$19.apply(standalone.scala:221)
        at com.opendatagroup.hadrian.standalone.Main$$anonfun$main$1$EngineRunnable$1$$anonfun$19.apply(standalone.scala:221)
        at com.opendatagroup.hadrian.standalone.Main$$anonfun$main$1$EngineRunnable$1.run(standalone.scala:232)
        at java.lang.Thread.run(Thread.java:745)