Example - 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
...
OrderLimit orderLimit = null;
...
if (planContract.hasQueryContextInfo())
      {
         qci = planContract.getQueryContextInfo();
         // read in order limit
         if (qci.hasOrderLimit())
         {
            orderLimit = qci.getOrderLimit();
         }
         outPreds = qci.getOnOutputPredicates();
      }
...
///////////////////////////////////////////////////////////////////
// The following example determines whether OrderLimit
// can be applied.
// OrderLimit can be applied by the function if either of the
// following is true:
// - There are no ORDER BY columns in OrderLimit.
// or
// - The query’s ORDER BY columns are a prefix subsequence of the
// ordered output columns.
//
// Example:
//   In the following query:
//    SELECT a, b, c FROM foo() ORDER BY c, b LIMIT 100
//   If foo’s output guarantees ordering on c, b,... then you
//   can apply the limit on a per worker basis.
boolean willApplyLimit = false;
if (planContract.hasQueryContextInfo()
        && qci.hasOrderLimit() && planContract.hasPlanOutputInfo()){
     // assume here that the PlanOutputInfo has already be set by the
     // function.
     planOutputInfo = planContract.getPlanOutputInfo();
     assert planOutputInfo != null;
     // It's safe to apply limit
     // if there are no order by columns.
     if (orderLimit.getOrderDefinitions().isEmpty())
     {
        willApplyLimit = true;
     }
     // The helper method areOrderCompatible returns true if
     // the limit's order by columns are a prefix of the
     // ordered output columns, and false otherwise.

     else if (planOutputInfo.hasOrder() &&
      areOrdersCompatible (planOutputInfo.getOrder().
      getOrderDefinitions(),
      orderLimit.getOrderDefinitions()))
     {
        willApplyLimit = true;
     }
     else
     {
        willApplyLimit = false;
     }
 }
 QueryContextReply qcr = new QueryContextReply.Builder()
  ...
  .setApplyLimit(willApplyLimit)
  ...