@Override public DataProvider init(String topic, String sessionId, JsonElement jsonElement) throws DataProviderException { this.siddhiDataProviderConfig = new Gson().fromJson(jsonElement, SiddhiDataProviderConfig.class); siddhiDataProviderConfig.setQueryData(((JsonObject) jsonElement).get(STORE_QUERY)); siddhiDataProviderConfig.setSiddhiAppContext(((JsonObject) jsonElement).get(SIDDHI_APP).getAsString()); this.timeColumns = Arrays.asList(this.siddhiDataProviderConfig.getTimeColumns().toUpperCase(Locale.ENGLISH) .split(",")); super.init(topic, sessionId, siddhiDataProviderConfig); SiddhiAppRuntime siddhiAppRuntime = getSiddhiAppRuntime(); siddhiAppRuntime.setPurgingEnabled(false); siddhiAppRuntime.start(); StoreQuery storeQuery = SiddhiCompiler.parseStoreQuery(siddhiDataProviderConfig.getQueryData() .getAsJsonObject().get(QUERY).getAsString()); Attribute[] outputAttributeList = siddhiAppRuntime.getStoreQueryOutputAttributes(storeQuery); metadata = new DataSetMetadata(outputAttributeList.length); Attribute outputAttribute; for (int i = 0; i < outputAttributeList.length; i++) { outputAttribute = outputAttributeList[i]; metadata.put(i, outputAttribute.getName(), getMetadataTypes(outputAttribute.getName(), outputAttribute.getType().toString())); } return this; }
if (attribute.getType().equals(Attribute.Type.INT)) { columnTypes.append(elementMappings.get(RDBMSEventTableConstants.EVENT_TABLE_RDBMS_INTEGER)); } else if (attribute.getType().equals(Attribute.Type.LONG)) { columnTypes.append(elementMappings.get(RDBMSEventTableConstants.EVENT_TABLE_RDBMS_LONG)); } else if (attribute.getType().equals(Attribute.Type.FLOAT)) { columnTypes.append(elementMappings.get(RDBMSEventTableConstants.EVENT_TABLE_RDBMS_FLOAT)); } else if (attribute.getType().equals(Attribute.Type.DOUBLE)) { columnTypes.append(elementMappings.get(RDBMSEventTableConstants.EVENT_TABLE_RDBMS_DOUBLE)); } else if (attribute.getType().equals(Attribute.Type.STRING)) { columnTypes.append(elementMappings.get(RDBMSEventTableConstants.EVENT_TABLE_RDBMS_STRING)); } else if (attribute.getType().equals(Attribute.Type.BOOL)) { columnTypes.append(elementMappings.get(RDBMSEventTableConstants.EVENT_TABLE_RDBMS_BOOL));
+ attributeTypeMap.get(key.trim()).name() + " in the stream " + streamID + " of siddhi text input mapper."); isValidEvent.set(false);
correlationDataPositions.add(i); } else if (attributeName.startsWith(ARBITRARY_DATA_PREFIX)) { if (attributeType.equals(Attribute.Type.STRING)) { arbitraryDataPositions.add( new AttributePosition(attributeName.replace(ARBITRARY_DATA_PREFIX, ""), i));
OMElement element = (OMElement) elementObj; if (element.getFirstElement() != null) { if (attributeType.equals(Attribute.Type.STRING)) { data[attributeMapping.getPosition()] = element.toString(); } else {
correlationDataList.add(i); } else if (attributeName.startsWith(ARBITRARY_DATA_PREFIX)) { if (attributeType.equals(Attribute.Type.STRING)) { arbitraryDataList.add( new AttributePosition(attributeName.replace(ARBITRARY_DATA_PREFIX, ""), i));
try { Object dataValue = null; if (attribute.getType().equals(Attribute.Type.STRING)) { dataValue = eventRecords.get(j); } else {
if (Type.DOUBLE.equals(attrType)) { firstVal = (Double) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Double) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.INT.equals(attrType)) { firstVal = (Integer) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Integer) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.LONG.equals(attrType)) { firstVal = (Long) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Long) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.FLOAT.equals(attrType)) { firstVal = (Float) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Float) lastInEvent.getData()[subjectedAttrIndex];
if (Type.DOUBLE.equals(attrType)) { firstVal = (Double) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Double) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.INT.equals(attrType)) { firstVal = (Integer) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Integer) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.LONG.equals(attrType)) { firstVal = (Long) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Long) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.FLOAT.equals(attrType)) { firstVal = (Float) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Float) lastInEvent.getData()[subjectedAttrIndex];
if (Type.DOUBLE.equals(subjectedAttrType)) { firstVal = (Double) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Double) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.INT.equals(subjectedAttrType)) { firstVal = (Integer) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Integer) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.LONG.equals(subjectedAttrType)) { firstVal = (Long) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Long) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.FLOAT.equals(subjectedAttrType)) { firstVal = (Float) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Float) lastInEvent.getData()[subjectedAttrIndex];
if (Type.DOUBLE.equals(subjectedAttrType)) { firstVal = (Double) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Double) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.INT.equals(subjectedAttrType)) { firstVal = (Integer) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Integer) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.LONG.equals(subjectedAttrType)) { firstVal = (Long) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Long) lastInEvent.getData()[subjectedAttrIndex]; } else if (Type.FLOAT.equals(subjectedAttrType)) { firstVal = (Float) firstInEvent.getData()[subjectedAttrIndex]; lastVal = (Float) lastInEvent.getData()[subjectedAttrIndex];
try { Object dataValue = null; if (type.equals(Attribute.Type.STRING)) { dataValue = eventRecords.get(position); } else {
Object parameter = entry.getValue(); Attribute variable = (Attribute) parameter; if (variable.getType().equals(Attribute.Type.STRING)) { compiledQuery = compiledQuery.replaceAll(entry.getKey(), "\"" + conditionParameterMap.get(variable.getName()).toString() + "\"");
private static String getSampleValue(Attribute.Type attributeType) { Random rand = new Random(); switch (attributeType.name().toLowerCase()) { case Constants.ATTR_TYPE_FLOAT: { int hostIndex = rand.nextInt(5);
/** * Convert the given {@link Event} to Text string. * * @param event Event object * @return the constructed TEXT string */ private Object constructDefaultMapping(Event event, boolean isEventGroup) { StringBuilder eventText = new StringBuilder(); Object[] data = event.getData(); for (int i = 0; i < data.length; i++) { Object attributeValue = data[i]; Attribute attribute = attributeList.get(i); if ((attributeValue != null) && attribute.getType().equals(Attribute.Type.STRING)) { eventText.append(attribute.getName()).append(EVENT_ATTRIBUTE_VALUE_SEPARATOR) .append(STRING_ENCLOSING_ELEMENT).append(attributeValue.toString()) .append(STRING_ENCLOSING_ELEMENT).append(EVENT_ATTRIBUTE_SEPARATOR).append(endOfLine); } else { eventText.append(attribute.getName()).append(EVENT_ATTRIBUTE_VALUE_SEPARATOR) .append(attributeValue).append(EVENT_ATTRIBUTE_SEPARATOR).append(endOfLine); } } int idx = eventText.lastIndexOf(EVENT_ATTRIBUTE_SEPARATOR); if (!isEventGroup) { eventText.delete(idx, idx + (EVENT_ATTRIBUTE_SEPARATOR + endOfLine).length()); } else { eventText.delete(idx, idx + EVENT_ATTRIBUTE_SEPARATOR.length()); } return eventText.toString(); } }
/** * The initialization method for MileToKilometre, this method will be called before the other methods * * @param attributeExpressionExecutors the executors of each function parameter * @param siddhiAppContext the context of the execution plan */ @Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader reader, SiddhiAppContext siddhiAppContext) { Unit<Length> mile = KILO(METRE).multiply(1.609344E+00); converter = mile.getConverterTo(KILO(METRE)); if (attributeExpressionExecutors.length != 1) { throw new SiddhiAppValidationException( "Invalid no of arguments passed to unitconversion:miTokm() function, " + "required 1, but found " + attributeExpressionExecutors.length); } Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) || (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) { throw new SiddhiAppValidationException("Invalid parameter type found " + "for the argument of UnitConversion function, " + "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG + " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE + ", but found " + attributeType.toString()); } }
/** * The initialization method for CentimetreToMile, this method will be called before the other methods * * @param attributeExpressionExecutors the executors of each function parameter * @param siddhiAppContext the context of the execution plan */ @Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader reader, SiddhiAppContext siddhiAppContext) { Unit<Length> mile = KILO(METRE).multiply(1.609344E+00); converter = CENTI(METRE).getConverterTo(mile); if (attributeExpressionExecutors.length != 1) { throw new SiddhiAppValidationException("Invalid no of arguments passed to " + "unitconversion:cmTomi() function, " + "required 1, but found " + attributeExpressionExecutors.length); } Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) || (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) { throw new SiddhiAppValidationException("Invalid parameter type found " + "for the argument of UnitConversion function, " + "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG + " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE + ", but found " + attributeType.toString()); } }
/** * The initialization method for KilometreToMile, this method will be called before the other methods * * @param attributeExpressionExecutors the executors of each function parameter * @param siddhiAppContext the context of the execution plan */ @Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader reader, SiddhiAppContext siddhiAppContext) { Unit<Length> mile = KILO(METRE).multiply(1.609344E+00); converter = KILO(METRE).getConverterTo(mile); if (attributeExpressionExecutors.length != 1) { throw new SiddhiAppValidationException( "Invalid no of arguments passed to unitconversion:kmTomi() function, " + "required 1, but found " + attributeExpressionExecutors.length); } Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) || (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) { throw new SiddhiAppValidationException("Invalid parameter type found " + "for the argument of UnitConversion function, " + "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG + " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE + ", but found " + attributeType.toString()); } }
/** * The initialization method for KilogramToPound, this method will be called before the other methods * * @param attributeExpressionExecutors the executors of each function parameter * @param siddhiAppContext the context of the execution plan */ @Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader reader, SiddhiAppContext siddhiAppContext) { Unit<Mass> pound = KILOGRAM.multiply(4.535924E-01); converter = KILOGRAM.getConverterTo(pound); if (attributeExpressionExecutors.length != 1) { throw new SiddhiAppValidationException( "Invalid no of arguments passed to unitconversion:kgTolb() function, " + "required 1, but found " + attributeExpressionExecutors.length); } Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) || (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) { throw new SiddhiAppValidationException("Invalid parameter type found " + "for the argument of UnitConversion function, " + "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG + " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE + ", but found " + attributeType.toString()); } }
/** * The initialization method for YearToDay, this method will be called before the other methods * * @param attributeExpressionExecutors the executors of each function parameter * @param siddhiAppContext the context of the execution plan */ @Override protected void init(ExpressionExecutor[] attributeExpressionExecutors, ConfigReader reader, SiddhiAppContext siddhiAppContext) { converter = YEAR.getConverterTo(DAY); if (attributeExpressionExecutors.length != 1) { throw new SiddhiAppValidationException( "Invalid no of arguments passed to unitconversion:yTod() function, " + "required 1, but found " + attributeExpressionExecutors.length); } Attribute.Type attributeType = attributeExpressionExecutors[0].getReturnType(); if (!((attributeType == Attribute.Type.DOUBLE) || (attributeType == Attribute.Type.INT) || (attributeType == Attribute.Type.FLOAT) || (attributeType == Attribute.Type.LONG))) { throw new SiddhiAppValidationException("Invalid parameter type found " + "for the argument of UnitConversion function, " + "required " + Attribute.Type.INT + " or " + Attribute.Type.LONG + " or " + Attribute.Type.FLOAT + " or " + Attribute.Type.DOUBLE + ", but found " + attributeType.toString()); } }