private MultiKeyUntyped getKeys(EventBean event) {
   Object[] keys = new Object[partitionExpressions.length];
   eventsPerStream[0] = event;
   int count = 0;
   for (ExprEvaluator node : partitionExpressions) {
     keys[count++] = node.evaluate(eventsPerStream, true, exprEvaluatorContext);
   }
   return new MultiKeyUntyped(keys);
 }
 public boolean matches(EventBean[] eventsPerStream, ExprEvaluatorContext exprEvaluatorContext) {
   if (exprNode == null) {
     return true;
   }
   Boolean result = (Boolean) exprNode.evaluate(eventsPerStream, true, exprEvaluatorContext);
   if (result != null) {
     return result;
   }
   return false;
 }
Пример #3
0
  public Object evaluate(
      long startTs,
      long endTs,
      EventBean[] eventsPerStream,
      boolean isNewData,
      ExprEvaluatorContext context) {
    Object parameter = evaluatorTimestamp.evaluate(eventsPerStream, isNewData, context);
    if (parameter == null) {
      return parameter;
    }

    return intervalOpEval.evaluate(startTs, endTs, parameter, eventsPerStream, isNewData, context);
  }
Пример #4
0
 public Object evaluate(
     long startTs,
     long endTs,
     Object parameterStartTs,
     EventBean[] eventsPerStream,
     boolean isNewData,
     ExprEvaluatorContext context) {
   Object paramEndTs = evaluatorEndTimestamp.evaluate(eventsPerStream, isNewData, context);
   if (paramEndTs == null) {
     return null;
   }
   return evaluate(
       startTs, endTs, parameterStartTs, paramEndTs, eventsPerStream, isNewData, context);
 }
  private static Object coerceProperty(
      String propertyName,
      Class containingType,
      Object value,
      Class type,
      EngineImportService engineImportService,
      boolean forceNumeric)
      throws ExprValidationException {
    if (value instanceof ExprNode && type != ExprNode.class) {
      if (value instanceof ExprIdentNode) {
        ExprIdentNode identNode = (ExprIdentNode) value;
        Property prop;
        try {
          prop = PropertyParser.parse(identNode.getFullUnresolvedName(), false);
        } catch (Exception ex) {
          throw new ExprValidationException(
              "Failed to parse property '" + identNode.getFullUnresolvedName() + "'");
        }
        if (!(prop instanceof MappedProperty)) {
          throw new ExprValidationException(
              "Unrecognized property '" + identNode.getFullUnresolvedName() + "'");
        }
        MappedProperty mappedProperty = (MappedProperty) prop;
        if (mappedProperty.getPropertyNameAtomic().toLowerCase().equals(SYSTEM_PROPETIES_NAME)) {
          return System.getProperty(mappedProperty.getKey());
        }
      } else {
        ExprNode exprNode = (ExprNode) value;
        ExprEvaluator evaluator = exprNode.getExprEvaluator();
        if (evaluator == null) {
          throw new ExprValidationException(
              "Failed to evaluate expression '" + exprNode.toExpressionString() + "'");
        }
        value = evaluator.evaluate(null, true, null);
      }
    }

    if (value == null) {
      return null;
    }
    if (value.getClass() == type) {
      return value;
    }
    if (JavaClassHelper.isAssignmentCompatible(value.getClass(), type)) {
      if (forceNumeric
          && JavaClassHelper.getBoxedType(value.getClass()) != JavaClassHelper.getBoxedType(type)
          && JavaClassHelper.isNumeric(type)
          && JavaClassHelper.isNumeric(value.getClass())) {
        value = JavaClassHelper.coerceBoxed((Number) value, JavaClassHelper.getBoxedType(type));
      }
      return value;
    }
    if (JavaClassHelper.isSubclassOrImplementsInterface(value.getClass(), type)) {
      return value;
    }
    if (type.isArray()) {
      if (!(value instanceof Collection)) {
        throw new ExprValidationException(
            "Property '"
                + propertyName
                + "' of class "
                + JavaClassHelper.getClassNameFullyQualPretty(containingType)
                + " expects an array but receives a value of type "
                + value.getClass().getName());
      }
      Object[] items = ((Collection) value).toArray();
      Object coercedArray = Array.newInstance(type.getComponentType(), items.length);
      for (int i = 0; i < items.length; i++) {
        Object coercedValue =
            coerceProperty(
                propertyName + " (array element)",
                type,
                items[i],
                type.getComponentType(),
                engineImportService,
                false);
        Array.set(coercedArray, i, coercedValue);
      }
      return coercedArray;
    }
    if (!(value instanceof Map)) {
      throw new ExprValidationException(
          "Property '"
              + propertyName
              + "' of class "
              + JavaClassHelper.getClassNameFullyQualPretty(containingType)
              + " expects an "
              + JavaClassHelper.getClassNameFullyQualPretty(type)
              + " but receives a value of type "
              + value.getClass().getName());
    }
    Map<String, Object> props = (Map<String, Object>) value;
    return instantiatePopulateObject(props, type, engineImportService);
  }
Пример #6
0
  public IntervalOpImpl(
      DatetimeMethodEnum method,
      String methodNameUse,
      EventType[] typesPerStream,
      List<ExprNode> expressions)
      throws ExprValidationException {

    ExprEvaluator evaluatorEndTimestamp = null;
    Class timestampType;

    if (expressions.get(0) instanceof ExprStreamUnderlyingNode) {
      ExprStreamUnderlyingNode und = (ExprStreamUnderlyingNode) expressions.get(0);
      parameterStreamNum = und.getStreamId();
      EventType type = typesPerStream[parameterStreamNum];
      parameterPropertyStart = type.getStartTimestampPropertyName();
      if (parameterPropertyStart == null) {
        throw new ExprValidationException(
            "For date-time method '"
                + methodNameUse
                + "' the first parameter is event type '"
                + type.getName()
                + "', however no timestamp property has been defined for this event type");
      }

      timestampType = type.getPropertyType(parameterPropertyStart);
      EventPropertyGetter getter = type.getGetter(parameterPropertyStart);
      evaluatorTimestamp = new ExprEvaluatorStreamLongProp(parameterStreamNum, getter);

      if (type.getEndTimestampPropertyName() != null) {
        parameterPropertyEnd = type.getEndTimestampPropertyName();
        EventPropertyGetter getterEndTimestamp = type.getGetter(type.getEndTimestampPropertyName());
        evaluatorEndTimestamp =
            new ExprEvaluatorStreamLongProp(parameterStreamNum, getterEndTimestamp);
      } else {
        parameterPropertyEnd = parameterPropertyStart;
      }
    } else {
      evaluatorTimestamp = expressions.get(0).getExprEvaluator();
      timestampType = evaluatorTimestamp.getType();

      if (expressions.get(0) instanceof ExprIdentNode) {
        ExprIdentNode identNode = (ExprIdentNode) expressions.get(0);
        parameterStreamNum = identNode.getStreamId();
        parameterPropertyStart = identNode.getResolvedPropertyName();
        parameterPropertyEnd = parameterPropertyStart;
      }

      if (!JavaClassHelper.isDatetimeClass(evaluatorTimestamp.getType())) {
        throw new ExprValidationException(
            "For date-time method '"
                + methodNameUse
                + "' the first parameter expression returns '"
                + evaluatorTimestamp.getType()
                + "', however requires a Date, Calendar, Long-type return value or event (with timestamp)");
      }
    }

    IntervalComputer intervalComputer = IntervalComputerFactory.make(method, expressions);

    // evaluation without end timestamp
    if (evaluatorEndTimestamp == null) {
      if (JavaClassHelper.isSubclassOrImplementsInterface(timestampType, Calendar.class)) {
        intervalOpEval = new IntervalOpEvalCal(intervalComputer);
      } else if (JavaClassHelper.isSubclassOrImplementsInterface(timestampType, Date.class)) {
        intervalOpEval = new IntervalOpEvalDate(intervalComputer);
      } else if (JavaClassHelper.getBoxedType(timestampType) == Long.class) {
        intervalOpEval = new IntervalOpEvalLong(intervalComputer);
      } else {
        throw new IllegalArgumentException(
            "Invalid interval first parameter type '" + timestampType + "'");
      }
    } else {
      if (JavaClassHelper.isSubclassOrImplementsInterface(timestampType, Calendar.class)) {
        intervalOpEval = new IntervalOpEvalCalWithEnd(intervalComputer, evaluatorEndTimestamp);
      } else if (JavaClassHelper.isSubclassOrImplementsInterface(timestampType, Date.class)) {
        intervalOpEval = new IntervalOpEvalDateWithEnd(intervalComputer, evaluatorEndTimestamp);
      } else if (JavaClassHelper.getBoxedType(timestampType) == Long.class) {
        intervalOpEval = new IntervalOpEvalLongWithEnd(intervalComputer, evaluatorEndTimestamp);
      } else {
        throw new IllegalArgumentException(
            "Invalid interval first parameter type '" + timestampType + "'");
      }
    }
  }