传动系统客户端
driveline的Python项目详细描述
驱动程序python sdk
Python SDK的核心是类DrivelineClient
importasynciofromdrivelineimportDrivelineClient,run_asyncasyncdefmain():asyncwithDrivelineClient('ws://127.0.0.1:8080')asclient:# list all streamsasyncforstream_nameinawaitclient.list_streams('*'):print('found stream:',stream_name)# list all keys is the document storeasyncforkey_nameinawaitclient.list_keys('*'):print('found document with key',key_name)# store a document in the document storeawaitclient.store('key/1',dict(title='Welcome',body='Hello, world!'))# load a key from the document storefuture_record=awaitclient.load('key/1')record=awaitfuture_recordprint('document associated with key/1 is:',record.record,'id:',record.record_id)# remove all records in the document store with keys matching 'key/...'awaitclient.removeMatches('key/*')# run a live query against a stream. # We want all records that have an odd indexdefquery_handler(res):print('query returned record:',res.record,'id:',res.record_id)query=awaitclient.continuous_query('SELECT * FROM STREAM my_stream where index % 1 == 1',query_handler)# stop the queryawaitasyncio.sleep(10)awaitclient.cancel(query)# quitawaitclient.close()if__name__=='__main__':run_async(main())
DQL动力传动系统查询语言
查询语法
基本语法
SELECT<selector>FROMSTREAM<stream>[WHERE<expression>]SELECT*FROMSTREAMstream_1SELECT*FROMSTREAMstream_1WHEREkey=valueSELECTtimeASt,(2+3)ASfiveFROMSTREAMstream_1WHEREageBETWEEN21AND25ORnameLIKE'Joe%'
DQL
支持标准的查询语法,不包括连接和
聚合。这意味着DQL
可以用于所有形式的数据过滤
以及在实时流上对数据进行分区
KV查询
SELECT<selector>FROM<string-key-name-expression>[WHERE<expression>]SELECT*FROM'users/*'WHEREcolor='red'
多键查询是一个DQL
扩展,允许您订阅多个
事件流,在新流形成时自动订阅它们,
基于流名称表达式。流名称表达式使用文件系统/pythongGlob
,
使用?
、*
和**
作为通配符匹配字符。
ecmascript对象表示法(javascript扩展)
SELECT{time,name:user.name,phone_number:user.phone.mobile.number,original:{...*}}FROMstream
以表格形式输入:
{time:123,user:{name:'joe',phone:{mobile:{number:'1-800-123-4567'}}}}
结果:
{time:123,name:'joe',phone_number:'1-800-123-4567',original:{time:123,user:phone:{...}}}
运算符
下表按以下顺序汇总了所有语言运算符 优先级
Name | Description | Example | Additional details |
---|---|---|---|
^{ | extended logical OR | ^{ | ^{ |
^{ | logical AND | ^{ | ^{ |
^{ | logical NOT | ^{ | ^{ |
^{ | Null check | ^{ | ^{ |
^{ | Set lookup | ^{ | All values in paranthesis must be constants |
^{ | Compare range | ^{ | ^{ |
^{ | Compare | ^{ | |
^{ | Pattern match | ^{ | ^{ |
^{ | Unary plus/minus | ^{ | |
^{ | Addition | ^{ | |
^{ | Multiplicative | ^{ | |
^{ | Paranthesis | ^{ | |
^{ | Constant | ^{ | |
^{ | Numeric constant | ||
^{ | String constant | ^{ | |
^{ | Identifier | ^{ | |
^{ | Identifier | ^{ | (backticks) Allows using identifier names that are otherwise invalid, e.g., contain invalid characters or symbols |
内置函数
Name | Description | Example |
---|---|---|
ABS | Absolute value ^{ | ^{ |
CEIL | Rounded up value ^{ | ^{ |
FLOOR | Rounded down value ^{ | ^{ |
EXP | Natural exponent ^{ | ^{ |
LN | Natural logarithm ^{ | ^{ |
SQRT | Square root ^{ | ^{ |
HASH | Hash function ^{ | ^{ |
CHAR_LENGTH | Length of string ^{ | ^{ |
POSITION | Index of substring in string ^{ | ^{ |
LOCATE | Index of substring in string ^{ | ^{ |