protected String toString(String type) { StringBuilder definitionBuilder = new StringBuilder(); if (annotations != null && annotations.size() > 0) { for (Annotation annotation : annotations) { definitionBuilder.append(annotation.toString()); } } definitionBuilder.append("define ").append(type).append(" ").append(id).append(" ("); boolean isFirst = true; for (Attribute attribute : attributeList) { if (!isFirst) { definitionBuilder.append(", "); } else { isFirst = false; } definitionBuilder.append(attribute.getName()).append(" "). append(attribute.getType().toString().toLowerCase(Locale.getDefault())); } definitionBuilder.append(")"); return definitionBuilder.toString(); } @Override
public static String buildStreamDefinition(StreamDefinition streamDefinition) { List<String> columns = new ArrayList<>(); Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null"); if (streamDefinition.getColumns() != null) { for (StreamColumn column : streamDefinition.getColumns()) { columns.add(String.format("%s %s", column.getName(), convertToSiddhiAttributeType(column.getType()).toString().toLowerCase())); } } else { LOG.warn("No columns found for stream {}" + streamDefinition.getStreamId()); } return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getStreamId(), StringUtils.join(columns, ",")); }
public String getStreamDefinitionExpression(StreamDefinition streamDefinition) { List<String> columns = new ArrayList<>(); Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null"); for (Attribute attribute : streamDefinition.getAttributeList()) { columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase())); } return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ",")); }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 2) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:strcmp() function, " + "required 2, but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the first argument of str:strcmp() function, " + "required "+Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the second argument of str:strcmp() function, " + "required "+Attribute.Type.STRING+", but found "+attributeExpressionExecutors[1].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 2) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:containsIgnoreCase() function, required 2, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the first argument of str:containsIgnoreCase() function, " + "required "+ Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the second argument of str:containsIgnoreCase() function, " + "required "+ Attribute.Type.STRING+", but found "+attributeExpressionExecutors[1].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 2) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:equalsIgnoreCase() function, required 2, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the first argument of str:equalsIgnoreCase() function, " + "required "+ Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the second argument of str:equalsIgnoreCase() function, " + "required "+ Attribute.Type.STRING+", but found "+attributeExpressionExecutors[1].getReturnType().toString()); } }
/** * Get record details. * * @param attributes Set of attributes * @return List of record details */ private List<RecordDetail> getRecordDetails(Attribute[] attributes) { List<RecordDetail> details = new ArrayList<>(); for (Attribute attribute : attributes) { details.add(new RecordDetail() .name(attribute.getName()) .dataType(attribute.getType().toString())); } return details; }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 2) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:repeat() function, required 2, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the first argument of str:repeat() function, " + "required "+Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.INT) { throw new ExecutionPlanValidationException("Invalid parameter type found for the second argument of str:repeat() function, " + "required "+Attribute.Type.INT+", but found "+attributeExpressionExecutors[1].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 2) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:containsIgnoreCase() function, required 2, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the first argument of str:containsIgnoreCase() function, " + "required " + Attribute.Type.STRING + ", but found " + attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the second argument of str:containsIgnoreCase() function, " + "required " + Attribute.Type.STRING + ", but found " + attributeExpressionExecutors[1].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 2) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:equalsIgnoreCase() function, required 2, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the first argument of str:equalsIgnoreCase() function, " + "required " + Attribute.Type.STRING + ", but found " + attributeExpressionExecutors[0].getReturnType().toString()); } if (attributeExpressionExecutors[1].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the second argument of str:equalsIgnoreCase() function, " + "required " + Attribute.Type.STRING + ", but found " + attributeExpressionExecutors[1].getReturnType().toString()); } }
/** * Generates FunctionConfig from the given Siddhi FunctionDefinition * * @param functionDefinition Siddhi FunctionDefinition * @return FunctionConfig object */ public FunctionConfig generateFunctionConfig(FunctionDefinition functionDefinition) { FunctionConfig functionConfig = new FunctionConfig(functionDefinition.getId(), functionDefinition.getLanguage(), functionDefinition.getReturnType().toString(), functionDefinition.getBody()); preserveAndBindCodeSegment(functionDefinition, functionConfig); return functionConfig; } }
public String getStreamDefinitionExpression(StreamDefinition streamDefinition) { List<String> columns = new ArrayList<>(); Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null"); for (Attribute attribute : streamDefinition.getAttributeList()) { columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase())); } return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ",")); }
public String getStreamDefinitionExpression(String streamId) { StreamDefinition streamDefinition = getStreamDefinition(streamId); List<String> columns = new ArrayList<>(); Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null"); for (Attribute attribute : streamDefinition.getAttributeList()) { columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase())); } return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ",")); } }
public String getStreamDefinitionExpression(String streamId) { StreamDefinition streamDefinition = getStreamDefinition(streamId); List<String> columns = new ArrayList<>(); Preconditions.checkNotNull(streamDefinition, "StreamDefinition is null"); for (Attribute attribute : streamDefinition.getAttributeList()) { columns.add(String.format("%s %s", attribute.getName(), attribute.getType().toString().toLowerCase())); } return String.format(DEFINE_STREAM_TEMPLATE, streamDefinition.getId(), StringUtils.join(columns, ",")); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 1) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:hex() function, " + "required 1, but found " + attributeExpressionExecutors.length); } Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); if (attributeType != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the argument of str:hex() function, " + "required " + Attribute.Type.STRING + "but found " + attributeType.toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 1) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:reverse() function, required 1, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for str:reverse() function, required " +Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 1) { throw new ExecutionPlanValidationException( "Invalid no of arguments passed to str:trim() function, required 1, but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for str:trim() function, required " +Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 1) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to math:unhex() function, " + "required 1, but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for the argument of math:unhex() function, " + "required "+Attribute.Type.STRING+" but found "+attributeExpressionExecutors[0].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 1) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:upper() function, required 1, but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for str:upper() function, required " +Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } }
@Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ExecutionPlanContext executionPlanContext) { if (attributeExpressionExecutors.length != 1) { throw new ExecutionPlanValidationException("Invalid no of arguments passed to str:lower() function, required 1, " + "but found " + attributeExpressionExecutors.length); } if (attributeExpressionExecutors[0].getReturnType() != Attribute.Type.STRING) { throw new ExecutionPlanValidationException("Invalid parameter type found for str:lower() function, required " +Attribute.Type.STRING+", but found "+attributeExpressionExecutors[0].getReturnType().toString()); } }