Java Code Examples for io.siddhi.core.executor.ExpressionExecutor#getReturnType()
The following examples show how to use
io.siddhi.core.executor.ExpressionExecutor#getReturnType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomPlusFunctionExtension.java From flink-siddhi with Apache License 2.0 | 6 votes |
/** * The initialization method for FunctionExecutor, this method will be called before the other methods */ @Override protected StateFactory init(ExpressionExecutor[] expressionExecutors, ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) { for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) { Attribute.Type attributeType = expressionExecutor.getReturnType(); if (attributeType == Attribute.Type.DOUBLE) { returnType = attributeType; } else if ((attributeType == Attribute.Type.STRING) || (attributeType == Attribute.Type.BOOL)) { throw new SiddhiAppCreationException("Plus cannot have parameters with types String or Bool"); } else { returnType = Attribute.Type.LONG; } } return null; }
Example 2
Source File: CustomFunctionExtension.java From siddhi with Apache License 2.0 | 6 votes |
/** * The initialization method for FunctionExecutor, this method will be called before the other methods * * @param attributeExpressionExecutors are the executors of each function parameters * @param configReader * @param siddhiQueryContext the context of the siddhi query */ @Override protected StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) { for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) { Attribute.Type attributeType = expressionExecutor.getReturnType(); if (attributeType == Attribute.Type.DOUBLE) { returnType = attributeType; } else if ((attributeType == Attribute.Type.STRING) || (attributeType == Attribute.Type.BOOL)) { throw new SiddhiAppCreationException("Plus cannot have parameters with types String or Bool"); } else { returnType = Attribute.Type.LONG; } } return null; }
Example 3
Source File: TimeBatchWindowProcessor.java From siddhi with Apache License 2.0 | 6 votes |
private void initTimeParameter(ExpressionExecutor attributeExpressionExecutor) { if (attributeExpressionExecutor instanceof ConstantExpressionExecutor) { if (attributeExpressionExecutor.getReturnType() == Attribute.Type.INT) { timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutor) .getValue(); } else if (attributeExpressionExecutor.getReturnType() == Attribute.Type.LONG) { timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutor) .getValue(); } else { throw new SiddhiAppValidationException("TimeBatch window's window.time (1st) parameter 'window.time' " + "should be either int or long, but found " + attributeExpressionExecutor.getReturnType()); } } else { throw new SiddhiAppValidationException("TimeBatch window's window.time (1st) parameter 'window.time' " + "should be a constant but found a dynamic attribute " + attributeExpressionExecutor.getClass().getCanonicalName()); } }
Example 4
Source File: ExpressionParser.java From siddhi with Apache License 2.0 | 6 votes |
/** * Calculate the return type of arithmetic operation executors.(Ex: add, subtract, etc) * * @param leftExpressionExecutor left ExpressionExecutor * @param rightExpressionExecutor right ExpressionExecutor * @return Attribute Type */ private static Attribute.Type parseArithmeticOperationResultType(ExpressionExecutor leftExpressionExecutor, ExpressionExecutor rightExpressionExecutor) { if (leftExpressionExecutor.getReturnType() == Attribute.Type.DOUBLE || rightExpressionExecutor.getReturnType() == Attribute.Type.DOUBLE) { return Attribute.Type.DOUBLE; } else if (leftExpressionExecutor.getReturnType() == Attribute.Type.FLOAT || rightExpressionExecutor.getReturnType() == Attribute.Type.FLOAT) { return Attribute.Type.FLOAT; } else if (leftExpressionExecutor.getReturnType() == Attribute.Type.LONG || rightExpressionExecutor.getReturnType() == Attribute.Type.LONG) { return Attribute.Type.LONG; } else if (leftExpressionExecutor.getReturnType() == Attribute.Type.INT || rightExpressionExecutor.getReturnType() == Attribute.Type.INT) { return Attribute.Type.INT; } else { throw new ArithmeticException("Arithmetic operation between " + leftExpressionExecutor.getReturnType() + " and " + rightExpressionExecutor.getReturnType() + " cannot be executed"); } }
Example 5
Source File: CustomFunctionExtension.java From siddhi with Apache License 2.0 | 6 votes |
@Override public StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) { for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) { Attribute.Type attributeType = expressionExecutor.getReturnType(); if (attributeType == Attribute.Type.DOUBLE) { returnType = attributeType; } else if ((attributeType == Attribute.Type.STRING) || (attributeType == Attribute.Type.BOOL)) { throw new SiddhiAppCreationException("Plus cannot have parameters with types String or Bool"); } else { returnType = Attribute.Type.LONG; } } return null; }
Example 6
Source File: CoalesceFunctionExecutor.java From siddhi with Apache License 2.0 | 5 votes |
@Override public StateFactory init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiQueryContext siddhiQueryContext) { if (attributeExpressionExecutors.length == 0) { throw new SiddhiAppValidationException("Coalesce must have at least one parameter"); } Attribute.Type type = attributeExpressionExecutors[0].getReturnType(); for (ExpressionExecutor expressionExecutor : attributeExpressionExecutors) { if (type != expressionExecutor.getReturnType()) { throw new SiddhiAppValidationException("Coalesce cannot have parameters with different type"); } } returnType = type; return null; }
Example 7
Source File: OrderByEventComparator.java From siddhi with Apache License 2.0 | 4 votes |
@Override public int compare(ComplexEvent complexEvent1, ComplexEvent complexEvent2) { if (groupByExecutors != null) { for (int i = 0, groupByExecutorsLength = groupByExecutors.length; i < groupByExecutorsLength; i++) { ExpressionExecutor executor = groupByExecutors[i]; boolean isAscending = isAscendingArray[i]; Object value1 = executor.execute(complexEvent1); Object value2 = executor.execute(complexEvent2); if (value1 != null && value2 != null) { int results = 0; Attribute.Type type = executor.getReturnType(); switch (type) { case STRING: results = ((String) value1).compareTo(((String) value2)); break; case INT: results = ((Integer) value1).compareTo(((Integer) value2)); break; case LONG: results = ((Long) value1).compareTo(((Long) value2)); break; case FLOAT: results = ((Float) value1).compareTo(((Float) value2)); break; case DOUBLE: results = ((Double) value1).compareTo(((Double) value2)); break; case BOOL: results = ((Boolean) value1).compareTo(((Boolean) value2)); break; case OBJECT: int hashDiff = value1.hashCode() - value2.hashCode(); if (hashDiff < 0) { results = -1; } else if (hashDiff > 0) { results = 1; } } if (!isAscending) { results = results * -1; } if (results != 0) { return results; } } else if (value1 != null) { return -1; } else if (value2 != null) { return 1; } } return 0; } else { return 0; } }