Beispiel #1
0
  /**
   * Ctor.
   *
   * @param typeName is the event type name
   * @param eventType is the event type of the wrapped events
   * @param properties is the additional properties this wrapper adds
   * @param metadata event type metadata
   * @param eventAdapterService is the service for resolving unknown wrapped types
   */
  public WrapperEventType(
      EventTypeMetadata metadata,
      String typeName,
      int eventTypeId,
      EventType eventType,
      Map<String, Object> properties,
      EventAdapterService eventAdapterService) {
    checkForRepeatedPropertyNames(eventType, properties);

    this.metadata = metadata;
    this.underlyingEventType = eventType;
    EventTypeMetadata metadataMapType = EventTypeMetadata.createAnonymous(typeName);
    this.underlyingMapType =
        new MapEventType(
            metadataMapType, typeName, 0, eventAdapterService, properties, null, null, null);
    this.isNoMapProperties = properties.isEmpty();
    this.eventAdapterService = eventAdapterService;
    this.eventTypeId = eventTypeId;
    propertyGetterCache = new HashMap<String, EventPropertyGetter>();

    updatePropertySet();

    if (metadata.getTypeClass() == EventTypeMetadata.TypeClass.NAMED_WINDOW) {
      startTimestampPropertyName = eventType.getStartTimestampPropertyName();
      endTimestampPropertyName = eventType.getEndTimestampPropertyName();
      EventTypeUtility.validateTimestampProperties(
          this, startTimestampPropertyName, endTimestampPropertyName);
    }
  }
Beispiel #2
0
  /**
   * Obtain information used by filter analyzer to handle this dot-method invocation as part of
   * query planning/indexing.
   *
   * @param typesPerStream event types
   * @param currentMethod
   * @param currentParameters
   * @param inputDesc descriptor of what the input to this interval method is
   */
  public ExprDotNodeFilterAnalyzerDTIntervalDesc getFilterDesc(
      EventType[] typesPerStream,
      DatetimeMethodEnum currentMethod,
      List<ExprNode> currentParameters,
      ExprDotNodeFilterAnalyzerInput inputDesc) {

    // with intervals is not currently query planned
    if (currentParameters.size() > 1) {
      return null;
    }

    // Get input (target)
    int targetStreamNum;
    String targetPropertyStart;
    String targetPropertyEnd;
    if (inputDesc instanceof ExprDotNodeFilterAnalyzerInputStream) {
      ExprDotNodeFilterAnalyzerInputStream targetStream =
          (ExprDotNodeFilterAnalyzerInputStream) inputDesc;
      targetStreamNum = targetStream.getStreamNum();
      EventType targetType = typesPerStream[targetStreamNum];
      targetPropertyStart = targetType.getStartTimestampPropertyName();
      targetPropertyEnd =
          targetType.getEndTimestampPropertyName() != null
              ? targetType.getEndTimestampPropertyName()
              : targetPropertyStart;
    } else if (inputDesc instanceof ExprDotNodeFilterAnalyzerInputProp) {
      ExprDotNodeFilterAnalyzerInputProp targetStream =
          (ExprDotNodeFilterAnalyzerInputProp) inputDesc;
      targetStreamNum = targetStream.getStreamNum();
      targetPropertyStart = targetStream.getPropertyName();
      targetPropertyEnd = targetStream.getPropertyName();
    } else {
      return null;
    }

    // check parameter info
    if (parameterPropertyStart == null) {
      return null;
    }

    return new ExprDotNodeFilterAnalyzerDTIntervalDesc(
        currentMethod,
        typesPerStream,
        targetStreamNum,
        targetPropertyStart,
        targetPropertyEnd,
        parameterStreamNum,
        parameterPropertyStart,
        parameterPropertyEnd);
  }
Beispiel #3
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 + "'");
      }
    }
  }