Implementing Contract Negotiation - Aster Execution Engine

Teradata Aster® Developer Guide

Product
Aster Execution Engine
Release Number
7.00.02
Published
July 2017
Language
English (United States)
Last Update
2018-04-13
dita:mapPath
xnl1494366523182.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval
dita:id
ffu1489104705746
lifecycle
previous
Product Category
Software

A graph function must implement a constructor that completes an instance of GraphRuntimeContract.

The GraphSearch constructor performs the following tasks:

  • Defines the vertex message schema and adds it to the contract.
  • Receives the source and destination vertex key values from the SOURCE and DESTINATION arguments and casts each into an instance of VertexKey class.
  • Defines the output schema of the function and adds it to the contract.
  • Completes the contract.

The example below shows the definition GraphSearch constructor.

The vertex message schema is constructed and added to the contract. The message schema is a single SqlType.Integer. The values used for messages are not important as they are simply used to trace a path through the graph.

The values of the SOURCE and DESTINATION argument clauses are extracted from the input and cast to VertexKey instances. The literal values supplied by each argument are used to construct corresponding RowHolder instances. Each RowHolder instance is in turn used to construct a corresponding VertexKey instance. These two vertex key instances are cached in class variables for later use in the search process.

The output schema of the function is defined and added to the contract. The function output is a single SqlType.Boolean column with the name "found."

Finally, the contract is completed.

/**
* Complete the runtime contract. This involves the usual
* processing of arguments, inputs, and specification of
* output schema. For graph functions, we also need to
* provide the planner with the vertex message schema.
* @param contract - runtime contract structure
*/
public GraphSearch(GraphRuntimeContract contract) {

   if (!contract.isCompleted()){

      /**
      * Get the vertex key schema. The vertex key schema is the same
      * as the partition definition schema.
      */
      InputInfo inputInfo = contract.getInputInfo();
      this.vertexKeySchema = inputInfo.getRowPartitioningExpressionTypes();

      /**
      * Set the vertex message schema. Messages sent to
      * incident vertices will consist of a single integer.
      */
      this.vertexMessageSchema.add(0, SqlType.integer());
      contract.setVertexMessageSchema    (ImmutableList.elementsOf(this.vertexMessageSchema));

      /**
      * Build up the source and destination vertex key values from
      * the input arguments. This is done by building a row (RowHolder)
      * for each of the SOURCE and DESTINATION arguments and using the
      * rows as input to the VertexKey class constructor.
      */
      ArgumentClause sourceVertex = contract.useArgumentClause("SOURCE");
      ImmutableList<String> sourceVertexArgValues = sourceVertex.getValues();
      ArgumentClause destinationVertex = contract.useArgumentClause("DESTINATION");
      ImmutableList<String> destinationVertexArgValues = destinationVertex.getValues();
      assert(sourceVertexArgValues.size() == this.vertexKeySchema.size());
      assert(destinationVertexArgValues.size() == this.vertexKeySchema.size());

      int attx = 0;

      Iterator<String> sourceVertexArgValuesIterator = sourceVertexArgValues.iterator();
      Iterator<String> destinationVertexArgValuesIterator = destinationVertexArgValues.iterator();
      RowHolder sourceVertexKeyValues, destinationVertexKeyValues;
      sourceVertexKeyValues = new RowHolder();
      destinationVertexKeyValues = new RowHolder();
      while (sourceVertexArgValuesIterator.hasNext() &&
destinationVertexArgValuesIterator.hasNext()){
         /**
         * Next integer value for source and destination vertex key.
         * Note that RowHolder will convert the Java Integer to SqlType.Integer
         */
         sourceVertexKeyValues.setIntAt(attx, Integer.parseInt(sourceVertexArgValuesIterator.next()));
         destinationVertexKeyValues.setIntAt(attx, Integer.parseInt(destinationVertexArgValuesIterator.next()));
         attx++;

      }//while

      /**
      * Initialize the source and destination vertex keys from the
      * argument values.
      */
      this.sourceVertexKey = new VertexKey(sourceVertexKeyValues);
      this.destinationVertexKey = new VertexKey(destinationVertexKeyValues);

      /**
      * Provide the schema of the output table. A row with a single
      * boolean attribute is output if the search is successful.
      */
      ArrayList<ColumnDefinition> outputColumns = new ArrayList<ColumnDefinition>();
      outputColumns.add(new ColumnDefinition("found", SqlType.bool()));
      contract.setOutputInfo(new OutputInfo(outputColumns));

      /**
      * Complete the graph contract and cache the completed contract.
      */
      contract.complete();
   }//contracted not completed

}//GraphSearch constructor