Archery icon indicating copy to clipboard operation
Archery copied to clipboard

ES与OpenSearch数据源添加SQL上线功能支持-v0.7-beta

Open feiazifeiazi opened this issue 1 year ago • 4 comments

ES和OpenSearch支持上线功能。

示例语句:


#PUT只有索引名,没有api-endpoint时, 解释为创建索引,请求体需要包含mappings或settings。
#PUT有索引名,有_doc,没有Id,错误写法,必须要写Id。

#post 有索引名, 没有_doc,错误写法。报错。
#post 有索引,有_doc,  有或没有id 均可。
#post 有索引,api-endpoint=_search时,这是查询,报错。

#delete 有索引,没有_doc,解释为删除表。 archery禁止此操作,需要报错。
#delete 有索引,有_doc,没有id,删除必须包含id,需要报错。


# api-endpoint为_update时,只能post,不能put,错误写法,报错。
# api-endpoint为_update_by_query时,只能post,不能put,错误写法,报错。


 

#新增带Id
POST /dmp__users/_doc/1
{
  "Code": "A01",
  "Name": "王晓晓",
  "Age": 12,
  "CreateTime": "2024-08-19 12:34:56.7890"
}

#新增带Id
POST /dmp__users/_doc/2 
{
  "Code": "A01",
  "Name": "常建国",
  "Age": 12,
  "CreateTime": "2024-08-19 12:34:56.7890"
}

#新增带Id
POST /dmp__users/_doc/abcd3
{
  "Code": "A01",
  "Name": "常建国abcd3",
  "Age": 12,
  "CreateTime": "2024-08-19 12:34:56.7890"
}


#新增没有Id
POST /dmp__users/_doc 
{
  "Code": "A02",
  "Name": "王小明",
  "Age": 13,
  "CreateTime": "2024-08-19 12:34:56.7890"
}

# 修改全部字段
PUT /dmp__users/_doc/1
{
  "Name": "常建国-只剩下这一个字段了"
}

# 更新现有文档,只会改这一个字段。
POST /dmp__users/_update/2
{
  "doc": {
    "Name": "王晓晓New2"
  }
}


# 更新现有文档,不存在的id,告警。
POST /dmp__users/_update/aa2
{
  "doc": {
    "Name": "王晓晓New2"
  }
}



#新建一个表
PUT /dmp__index1
#新建一个表
PUT /dmp__index2
{
 "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 1
    }
  },
  "mappings": {
    "properties": {
      "Code": {
        "type": "text"
      },
      "Age": {
        "type": "integer"
      },
      "CreateTime": {
        "type": "date"
      }
    }
  }
}
#新建一个表,已经存在的表,告警。
PUT /dmp__index2

#删除数据
DELETE /dmp__users/_doc/abcd3

#删除数据,不存在的id,告警。
DELETE /dmp__users/_doc/a3

#批量修改
POST /dmp__users/_update_by_query
{
  "script": {
    "source": "ctx._source.Age = params.new_value",
    "lang": "painless",
    "params": {
      "new_value": 456133
    }
  },
  "query": {
    "term": {
      "Name.keyword": "王小明"
    }
  }
}

feiazifeiazi avatar Aug 20 '24 10:08 feiazifeiazi

Codecov Report

Attention: Patch coverage is 86.90476% with 55 lines in your changes missing coverage. Please review.

Project coverage is 78.08%. Comparing base (83c9664) to head (cf71e03). Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
sql/engines/elasticsearch.py 76.59% 55 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2768      +/-   ##
==========================================
+ Coverage   77.85%   78.08%   +0.23%     
==========================================
  Files         122      122              
  Lines       16892    17311     +419     
==========================================
+ Hits        13151    13518     +367     
- Misses       3741     3793      +52     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Aug 20 '24 10:08 codecov[bot]

现在还是覆盖率没达标, 我有一个提议, 现在 engine 实际上比较自由, 你可以尝试去做一个 python 的 package, 然后发布到 pypi 上, archery 去装你的包, 然后加载, 就可以达到同样的效果.

好处在代码和发布都是你来控制, CI, 覆盖率, 你想做就做.

当然我也清楚这些代码就不属于 archery 了, 我理解社区就是这样, 我自己也想把 archery 的比较独立的部分能够独立出去, 建立起来一个比较良好的, 可插拔的框架, 方便更多人的定制, 也方便更多人基于这个平台做更多有益于数据安全的事情.

LeoQuote avatar Aug 20 '24 10:08 LeoQuote

现在还是覆盖率没达标, 我有一个提议, 现在 engine 实际上比较自由, 你可以尝试去做一个 python 的 package, 然后发布到 pypi 上, archery 去装你的包, 然后加载, 就可以达到同样的效果.

好处在代码和发布都是你来控制, CI, 覆盖率, 你想做就做.

当然我也清楚这些代码就不属于 archery 了, 我理解社区就是这样, 我自己也想把 archery 的比较独立的部分能够独立出去, 建立起来一个比较良好的, 可插拔的框架, 方便更多人的定制, 也方便更多人基于这个平台做更多有益于数据安全的事情.

覆盖率问题是因为单元测试方法还没开始写。 这是Archery该有或可以有的功能,不要以插件的方式吧。应该要原生集成支持,原生插件也行,要归到archery。

feiazifeiazi avatar Aug 21 '24 02:08 feiazifeiazi

@LeoQuote 帮忙审一下。

feiazifeiazi avatar Aug 27 '24 11:08 feiazifeiazi