Siddhi Query Language_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Siddhi Query Language

Siddhi Query Language

 2018/8/27 18:47:32  shangboz  程序员俱乐部  我要评论(0)
  • 摘要:SiddhiQueryLanguage的官方解释如下:SiddhiQueryLanguage(SiddhiQL)isdesignedtoprocesseventstreamstoidentifycomplexeventoccurrencesSiddhi在4.0版本进行了升级,支持流处理,事件流图:上图中的几个组件大致说明:StreamAlogicalseriesofeventsorderedintimewithauniquelyidentifiablename
  • 标签:

Siddhi Query Language的官方解释如下:

Siddhi Query Language (SiddhiQL) is designed to process event streams to identify complex event occurrences

Siddhi在4.0版本进行了升级,支持流处理,事件流图:

上图中的几个组件大致说明:

Stream A logical series of events ordered in time with a uniquely identifiable name, and set of defined attributes with specific data types defining its schema. Event An event is associated with only one stream, and all events of that stream have an identical set of attributes that are assigned specific types (or the same schema). An event contains a timestamp and set of attribute values according to the schema. Table A structured representation of data stored with a defined schema. Stored data can be backed by?In-Memory,?RDBMs,?MongoDB, etc. to be accessed and manipulated at runtime. Query A logical construct that processes events in streaming manner by combining existing streams and/or tables, and generates events to an output stream or table. A query consumes one or more input streams, and zero or one table. Then it processes these events in a streaming manner and publishes the output events to streams or tables for further processing or to generate notifications. Source A contract that consumes data from external sources (such as?TCP,?Kafka,?HTTP, etc)in the form of events, then converts each event (which can be in?XML,?JSON,?binary, etc. format) to a Siddhi event, and passes that to a Stream for processing. Sink A contract that takes events arriving at a stream, maps them to a predefined data format (such as?XML,?JSON,?binary, etc), and publishes them to external endpoints (such as?E-mail,?TCP,?Kafka,?HTTP, etc). Input Handler A mechanism to programmatically inject events into streams. Stream/Query Callback A mechanism to programmatically consume output events from streams and queries. Partition A logical container that isolates the processing of queries based on partition keys. Here, a separate instance of queries is generated for each partition key to achieve isolation. Inner Stream A positionable stream that connects portioned queries within their partitions, preserving isolation.

?

Siddhi SQL 4.0版本相比于3.0版本增加了流处理的支持

基本语法:

?

class="java" name="code"><siddhi app>  : 
        <app annotation> * 
        ( <stream definition> | <table definition> | ... ) + 
        ( <query> | <partition> ) +
        ;?

?

?

SiddhiQL主要包括以下几个方面:

  • 事件流定义(Event Stream Definitions)
  • 事件表定义(Event Table Definitions)
  • 分区(Partitions)
  • 查询(Queries)
? 1、事件流(Event Stream) 事件流是具有定义模式的事件序列。可以使用查询导入和操作一个或多个事件流,以便识别复杂的事件条件,并创建新的事件流来通知查询响应。 事件流定义:
define stream <stream name> (<attribute name> <attribute type>, <attribute name> <attribute type>, ... );
? 2、查询(Query) 每一个Siddhi查询可以消费一个或者多个事件流并且会根据查询结果创建一个新的事件。 一个查询包括一个输入区和一个输出区,有些还会包括一个推断区,一个查询定义如下:
from <input stream name> 
select <attribute name>, <attribute name>, ...
insert into <output stream name>
?Siddhi查询是一个类sql语言,其中内置多种函数及组合查询,具体的的参考其官网的说明: 3.0版本:https://docs.wso2.com/display/cep410/siddhiql+guide+3.0#SiddhiQLGuide3.0-EventStream 4.0版本:https://wso2.github.io/siddhi/documentation/siddhi-4.0/#source-mapper ? 3、分区(Partition) partition可以将流分成多个独立的组然后进行独立的平行处理,一个partition包含一个或者多个查询,并且存在多个实例,其中每个分区复制相同的查询和流。每一个Partition都标记一个key,这些partition只处理每一个key相对应的事件流。 partition key 有两种定义方式: 1.根据值定义:
partition with ( <expression> of <stream name>, <expression> of <stream name>, ... )
begin
    <query>
    <query>
    ...
end; 
?2.根据范围定义:
partition with ( <condition> as <partition key> or <condition> as <partition key> or ... of <stream name>, ... )
begin
    <query>
    <query>
    ...
end;
? 4、表(Table) 表是流或事件表的存储版本。其定义方式跟流定义类似,通过table definition定义。这些事件默认存储在本地内存中(支持集群),但是Siddhi也提供了一些扩展存储,可以存储到例如数据库等多种外接设备中。 表的定义:
define table <table name> (<attribute name> <attribute type>, <attribute name> <attribute type>, ... );
??类似于数据库表,siddhi中定义的表同样可以指定主键和索引,分别通过注解@PrimaryKey(name)和@Index(name)定义。siddhi中的表也支持Insert、join、delete、update、in等操作,但是需要注意,如果一个表定义了主键约束,那么该主键必须不能重复,不然就会出现逐渐冲突问题。(详细参考官网说明) ? 5、触发器(Trigger) 触发器可以周期性触发事件,通过 define trigger定义触发器
define trigger <trigger name> at ('start'| every <time interval>| '<cron expression>');
?下面这个例子是每5分钟触发一次事件流
define trigger FiveMinTriggerStream at every 5 min;
?下面是每周一到周五的上午10点15分触发事件流
define trigger FiveMinTriggerStream at '0 15 10 ? * MON-FRI';
? 6、脚本(Script) siddhi可以通过定义function的方式在流里执行其他的编程语言脚本,如:Javascript、R、Scala等 定义格式:
define function <function name>[<language name>] return <return type> {
    <operation of the function>
};
? Siddhi SQL 4.0增加了Windows定义
  • 相关文章
发表评论
用户名: 匿名