... 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) ...