Ejemplo n.º 1
0
 private static Date getRecordTime(
     ELEval elEvaluator, ELVars variables, String expression, Record record)
     throws OnRecordErrorException {
   try {
     TimeNowEL.setTimeNowInContext(variables, new Date());
     RecordEL.setRecordInContext(variables, record);
     return elEvaluator.eval(variables, expression, Date.class);
   } catch (ELEvalException e) {
     LOG.error("Failed to evaluate expression '{}' : ", expression, e.toString(), e);
     throw new OnRecordErrorException(record, e.getErrorCode(), e.getParams());
   }
 }
Ejemplo n.º 2
0
 public static void validateExpression(
     ELEval elEvaluator,
     ELVars variables,
     String expression,
     Stage.Context context,
     String group,
     String config,
     ErrorCode err,
     Class<?> type,
     List<Stage.ConfigIssue> issues) {
   RecordEL.setRecordInContext(variables, context.createRecord("forValidation"));
   try {
     context.parseEL(expression);
     elEvaluator.eval(variables, expression, type);
   } catch (Exception ex) {
     issues.add(context.createConfigIssue(group, config, err, expression, ex.toString(), ex));
   }
 }
Ejemplo n.º 3
0
  public static Multimap<String, Record> partitionBatchByExpression(
      ELEval elEvaluator,
      ELVars variables,
      String expression,
      ELEval timeDriverEvaluator,
      ELVars timeDriverVariables,
      String timeDriverExpression,
      Calendar calendar,
      Batch batch)
      throws OnRecordErrorException {
    Multimap<String, Record> partitions = ArrayListMultimap.create();

    Iterator<Record> batchIterator = batch.getRecords();

    while (batchIterator.hasNext()) {
      Record record = batchIterator.next();
      RecordEL.setRecordInContext(variables, record);
      // The expression may not include time EL in which case time driver parameters will be null.
      if (timeDriverEvaluator != null) {
        Date recordTime =
            getRecordTime(timeDriverEvaluator, timeDriverVariables, timeDriverExpression, record);
        calendar.setTime(recordTime);
        TimeEL.setCalendarInContext(variables, calendar);
        TimeNowEL.setTimeNowInContext(variables, recordTime);
      }

      try {
        String partitionName = elEvaluator.eval(variables, expression, String.class);
        LOG.debug("Expression '{}' is evaluated to '{}' : ", expression, partitionName);
        partitions.put(partitionName, record);
      } catch (ELEvalException e) {
        LOG.error("Failed to evaluate expression '{}' : ", expression, e.toString(), e);
        throw new OnRecordErrorException(record, e.getErrorCode(), e.getParams());
      }
    }

    return partitions;
  }