Skip to content

Commit 231630c

Browse files
Merge pull request #2916 from actiontech/2192
knowledge base support konwledge graph
2 parents de3371b + bcf0ed0 commit 231630c

File tree

10 files changed

+39
-92
lines changed

10 files changed

+39
-92
lines changed

.github/workflows/check-pr-files.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: Prevent file change
1313
with:
1414
githubToken: ${{ secrets.GITHUB_TOKEN }}
15-
pattern: ^(?!.*_ee\/.*$)(?!.*_ee\.go$)(?!.*_ee_test\.go$)(?!.*_rel\.go$)(?!.*_rel_test\.go$)(?!go\.mod$)(?!go\.sum$)(?!\.github\/workflows\/check-pr-files\.yml$)(?!vendor\/.*)(?!.*_qa\.go$).*
15+
pattern: ^(?!.*_ee\/.*$)(?!.*_ee\.go$)(?!.*_ee_test\.go$)(?!.*_rel\.go$)(?!.*_rel_test\.go$)(?!go\.mod$)(?!go\.sum$)(?!\.github\/workflows\/check-pr-files\.yml$)(?!vendor\/.*)(?!.*_qa\.go$)(?!.*\.xml$).*
1616
trustedAuthors: xalvarez
1717

1818
# 禁止actions自动提交commit

sqle/api/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
448448
// 知识库 Knowledge Base
449449
v1Router.GET("/knowledge_bases", v1.GetKnowledgeBaseList)
450450
v1Router.GET("/knowledge_bases/tags", v1.GetKnowledgeBaseTagList)
451+
v1Router.GET("/knowledge_bases/graph", v1.GetKnowledgeGraph)
451452

452453
//rule
453454
v1Router.GET("/rules", v1.GetRules)

sqle/api/controller/v1/knowledge_base.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,12 @@ type NodeResponse struct {
8989
ID string `json:"id"`
9090
Name string `json:"name"`
9191
Weight uint64 `json:"weight"`
92-
Data interface{} `json:"data,omitempty"`
9392
}
9493

9594
// EdgeResponse represents an edge in the API response
9695
type EdgeResponse struct {
97-
FromID string `json:"from_id"` // 存储Node的ID而不是指针
98-
FromName string `json:"from_name"` // 方便前端显示
99-
ToID string `json:"to_id"` // 存储Node的ID而不是指针
100-
ToName string `json:"to_name"` // 方便前端显示
96+
FromID string `json:"from_id"` // 存储Node的ID
97+
ToID string `json:"to_id"` // 存储Node的ID
10198
Weight uint64 `json:"weight"` // 权重
10299
IsDirected bool `json:"is_directed"` // 是否有向
103100
}
@@ -106,11 +103,4 @@ type EdgeResponse struct {
106103
type GraphResponse struct {
107104
Nodes []*NodeResponse `json:"nodes"` // 节点集合
108105
Edges []*EdgeResponse `json:"edges"` // 边集合
109-
Stats GraphStats `json:"stats"` // 添加图的统计信息
110-
}
111-
112-
// GraphStats 包含图的统计信息
113-
type GraphStats struct {
114-
TotalNodes uint64 `json:"total_nodes"`
115-
TotalEdges uint64 `json:"total_edges"`
116106
}

sqle/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type SqleOptions struct {
4141
Service SeviceOpts `yaml:"service"`
4242
OptimizationConfig OptimizationConfig `yaml:"optimization_config"`
4343
SQLRewritingConfig SQLRewritingConfig `yaml:"sql_rewriting_config"`
44+
KnowledgeBaseTempLicense string `yaml:"knowledge_base_temp_license"`
4445
}
4546

4647
type SeviceOpts struct {

sqle/docs/docs.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13573,23 +13573,15 @@ var doc = `{
1357313573
"type": "object",
1357413574
"properties": {
1357513575
"from_id": {
13576-
"description": "存储Node的ID而不是指针",
13577-
"type": "string"
13578-
},
13579-
"from_name": {
13580-
"description": "方便前端显示",
13576+
"description": "存储Node的ID",
1358113577
"type": "string"
1358213578
},
1358313579
"is_directed": {
1358413580
"description": "是否有向",
1358513581
"type": "boolean"
1358613582
},
1358713583
"to_id": {
13588-
"description": "存储Node的ID而不是指针",
13589-
"type": "string"
13590-
},
13591-
"to_name": {
13592-
"description": "方便前端显示",
13584+
"description": "存储Node的ID",
1359313585
"type": "string"
1359413586
},
1359513587
"weight": {
@@ -16054,22 +16046,6 @@ var doc = `{
1605416046
"items": {
1605516047
"$ref": "#/definitions/v1.NodeResponse"
1605616048
}
16057-
},
16058-
"stats": {
16059-
"description": "添加图的统计信息",
16060-
"type": "object",
16061-
"$ref": "#/definitions/v1.GraphStats"
16062-
}
16063-
}
16064-
},
16065-
"v1.GraphStats": {
16066-
"type": "object",
16067-
"properties": {
16068-
"total_edges": {
16069-
"type": "integer"
16070-
},
16071-
"total_nodes": {
16072-
"type": "integer"
1607316049
}
1607416050
}
1607516051
},
@@ -16575,9 +16551,6 @@ var doc = `{
1657516551
"v1.NodeResponse": {
1657616552
"type": "object",
1657716553
"properties": {
16578-
"data": {
16579-
"type": "object"
16580-
},
1658116554
"id": {
1658216555
"type": "string"
1658316556
},

sqle/docs/swagger.json

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13557,23 +13557,15 @@
1355713557
"type": "object",
1355813558
"properties": {
1355913559
"from_id": {
13560-
"description": "存储Node的ID而不是指针",
13561-
"type": "string"
13562-
},
13563-
"from_name": {
13564-
"description": "方便前端显示",
13560+
"description": "存储Node的ID",
1356513561
"type": "string"
1356613562
},
1356713563
"is_directed": {
1356813564
"description": "是否有向",
1356913565
"type": "boolean"
1357013566
},
1357113567
"to_id": {
13572-
"description": "存储Node的ID而不是指针",
13573-
"type": "string"
13574-
},
13575-
"to_name": {
13576-
"description": "方便前端显示",
13568+
"description": "存储Node的ID",
1357713569
"type": "string"
1357813570
},
1357913571
"weight": {
@@ -16038,22 +16030,6 @@
1603816030
"items": {
1603916031
"$ref": "#/definitions/v1.NodeResponse"
1604016032
}
16041-
},
16042-
"stats": {
16043-
"description": "添加图的统计信息",
16044-
"type": "object",
16045-
"$ref": "#/definitions/v1.GraphStats"
16046-
}
16047-
}
16048-
},
16049-
"v1.GraphStats": {
16050-
"type": "object",
16051-
"properties": {
16052-
"total_edges": {
16053-
"type": "integer"
16054-
},
16055-
"total_nodes": {
16056-
"type": "integer"
1605716033
}
1605816034
}
1605916035
},
@@ -16559,9 +16535,6 @@
1655916535
"v1.NodeResponse": {
1656016536
"type": "object",
1656116537
"properties": {
16562-
"data": {
16563-
"type": "object"
16564-
},
1656516538
"id": {
1656616539
"type": "string"
1656716540
},

sqle/docs/swagger.yaml

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,19 +1367,13 @@ definitions:
13671367
v1.EdgeResponse:
13681368
properties:
13691369
from_id:
1370-
description: 存储Node的ID而不是指针
1371-
type: string
1372-
from_name:
1373-
description: 方便前端显示
1370+
description: 存储Node的ID
13741371
type: string
13751372
is_directed:
13761373
description: 是否有向
13771374
type: boolean
13781375
to_id:
1379-
description: 存储Node的ID而不是指针
1380-
type: string
1381-
to_name:
1382-
description: 方便前端显示
1376+
description: 存储Node的ID
13831377
type: string
13841378
weight:
13851379
description: 权重
@@ -3078,17 +3072,6 @@ definitions:
30783072
items:
30793073
$ref: '#/definitions/v1.NodeResponse'
30803074
type: array
3081-
stats:
3082-
$ref: '#/definitions/v1.GraphStats'
3083-
description: 添加图的统计信息
3084-
type: object
3085-
type: object
3086-
v1.GraphStats:
3087-
properties:
3088-
total_edges:
3089-
type: integer
3090-
total_nodes:
3091-
type: integer
30923075
type: object
30933076
v1.HighPriorityConditionReq:
30943077
properties:
@@ -3430,8 +3413,6 @@ definitions:
34303413
type: object
34313414
v1.NodeResponse:
34323415
properties:
3433-
data:
3434-
type: object
34353416
id:
34363417
type: string
34373418
name:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//go:build !enterprise
2+
// +build !enterprise
3+
4+
package license
5+
6+
import "fmt"
7+
8+
func CheckKnowledgeBaseLicense(license string) error {
9+
return fmt.Errorf("knowledge base license is not supported in community edition")
10+
}

sqle/model/knowledge_base.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ()
44

55
type Knowledge struct {
66
Model
7+
RuleName string `gorm:"type:varchar(255);default:''" json:"rule_name"` // 规则名称
78
Title string `gorm:"type:varchar(255);not null" json:"title"` // 标题
89
Description string `gorm:"type:text" json:"description"` // 描述
910
Content string `gorm:"type:text;index:,class:FULLTEXT" json:"content"` // 内容

sqle/server/support_checker.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package server
33
import (
44
"fmt"
55

6+
"github.com/actiontech/sqle/sqle/config"
67
"github.com/actiontech/sqle/sqle/driver"
78
driverV2 "github.com/actiontech/sqle/sqle/driver/v2"
9+
"github.com/actiontech/sqle/sqle/license"
810
optimization "github.com/actiontech/sqle/sqle/server/optimization/rule"
911
)
1012

1113
const (
1214
executeSqlFileMode string = "execute_sql_file_mode"
1315
sqlOptimization string = "sql_optimization"
1416
backup string = "backup"
17+
knowledge_base string = "knowledge_base"
1518
)
1619

1720
type StatusChecker interface {
@@ -26,6 +29,8 @@ func NewModuleStatusChecker(driverType string, moduleName string) (StatusChecker
2629
return sqlOptimizationChecker{}, nil
2730
case backup:
2831
return sqlBackupChecker{driverType: driverType}, nil
32+
case knowledge_base:
33+
return knowledgeBaseChecker{driverType: driverType}, nil
2934
}
3035
return nil, fmt.Errorf("no checker matched")
3136
}
@@ -53,3 +58,15 @@ func (s sqlBackupChecker) CheckIsSupport() bool {
5358
svc := BackupService{}
5459
return svc.CheckIsDbTypeSupportEnableBackup(s.driverType) == nil
5560
}
61+
62+
// knowledgeBaseChecker 知识库检查器
63+
type knowledgeBaseChecker struct {
64+
driverType string
65+
}
66+
67+
func (s knowledgeBaseChecker) CheckIsSupport() bool {
68+
if license.CheckKnowledgeBaseLicense(config.GetOptions().SqleOptions.KnowledgeBaseTempLicense) != nil {
69+
return false
70+
}
71+
return true
72+
}

0 commit comments

Comments
 (0)