Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增sql分析接口,为了获取sql类型和表名 #2445

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
v1Router.POST("/audit_files", v1.DirectAuditFiles)
v2Router.POST("/audit_files", v2.DirectAuditFiles)
v1Router.GET("/sql_analysis", v1.DirectGetSQLAnalysis)
v1Router.GET("/sql_parse", v1.DirectParseSQL)

// 企业公告
v1Router.GET("/company_notice", v1.GetCompanyNotice)
// 系统功能开关
Expand Down
35 changes: 35 additions & 0 deletions sqle/api/controller/v1/sql_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,38 @@ type SqlAnalysisResDataV1 struct {
func DirectGetSQLAnalysis(c echo.Context) error {
return directGetSQLAnalysis(c)
}

type DirectParseSQLReq struct {
InstanceType string `json:"instance_type" query:"instance_type" example:"MySQL" valid:"required"`
SQL string `json:"sql" query:"sql" example:"select * from t1; select * from t2;" valid:"required"`
}

type DirectParseSQLRes struct {
controller.BaseRes
Data []*ParseSQLResData `json:"data"`
}

type ParseSQLResData struct {
SQL string `json:"sql"`
SQLType string `json:"sql_type"`
ExtractTable []*ExtractTable `json:"extract_table"`
}

type ExtractTable struct {
SchemaName string `json:"schema_name"`
TableName string `json:"table_name"`
}

// DirectParseSQL
// @Summary 解析SQL
// @Description parse sql
// @Id parseSQL
// @Tags sql_parse
// @Security ApiKeyAuth
// @param instance_type query string true "instance type"
// @Param sql query string true "sql"
// @Success 200 {object} v1.DirectParseSQLRes
// @router /v1/sql_parse [get]
func DirectParseSQL(c echo.Context) error {
return nil
}
86 changes: 86 additions & 0 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6038,6 +6038,45 @@ var doc = `{
}
}
},
"/v1/sql_parse": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "parse sql",
"tags": [
"sql_parse"
],
"summary": "解析SQL",
"operationId": "parseSQL",
"parameters": [
{
"type": "string",
"description": "instance type",
"name": "instance_type",
"in": "query",
"required": true
},
{
"type": "string",
"description": "sql",
"name": "sql",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.DirectParseSQLRes"
}
}
}
}
},
"/v1/statistic/instances/sql_average_execution_time": {
"get": {
"security": [
Expand Down Expand Up @@ -9472,6 +9511,25 @@ var doc = `{
}
}
},
"v1.DirectParseSQLRes": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.ParseSQLResData"
}
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.DriversResV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -9523,6 +9581,17 @@ var doc = `{
}
}
},
"v1.ExtractTable": {
"type": "object",
"properties": {
"schema_name": {
"type": "string"
},
"table_name": {
"type": "string"
}
}
},
"v1.FeishuConfigurationV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -11752,6 +11821,23 @@ var doc = `{
}
}
},
"v1.ParseSQLResData": {
"type": "object",
"properties": {
"extract_table": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.ExtractTable"
}
},
"sql": {
"type": "string"
},
"sql_type": {
"type": "string"
}
}
},
"v1.PartialSyncAuditPlanSQLsReqV1": {
"type": "object",
"properties": {
Expand Down
86 changes: 86 additions & 0 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -6022,6 +6022,45 @@
}
}
},
"/v1/sql_parse": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "parse sql",
"tags": [
"sql_parse"
],
"summary": "解析SQL",
"operationId": "parseSQL",
"parameters": [
{
"type": "string",
"description": "instance type",
"name": "instance_type",
"in": "query",
"required": true
},
{
"type": "string",
"description": "sql",
"name": "sql",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.DirectParseSQLRes"
}
}
}
}
},
"/v1/statistic/instances/sql_average_execution_time": {
"get": {
"security": [
Expand Down Expand Up @@ -9456,6 +9495,25 @@
}
}
},
"v1.DirectParseSQLRes": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.ParseSQLResData"
}
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.DriversResV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -9507,6 +9565,17 @@
}
}
},
"v1.ExtractTable": {
"type": "object",
"properties": {
"schema_name": {
"type": "string"
},
"table_name": {
"type": "string"
}
}
},
"v1.FeishuConfigurationV1": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -11736,6 +11805,23 @@
}
}
},
"v1.ParseSQLResData": {
"type": "object",
"properties": {
"extract_table": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.ExtractTable"
}
},
"sql": {
"type": "string"
},
"sql_type": {
"type": "string"
}
}
},
"v1.PartialSyncAuditPlanSQLsReqV1": {
"type": "object",
"properties": {
Expand Down
56 changes: 56 additions & 0 deletions sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,19 @@ definitions:
example: ok
type: string
type: object
v1.DirectParseSQLRes:
properties:
code:
example: 0
type: integer
data:
items:
$ref: '#/definitions/v1.ParseSQLResData'
type: array
message:
example: ok
type: string
type: object
v1.DriversResV1:
properties:
driver_name_list:
Expand Down Expand Up @@ -793,6 +806,13 @@ definitions:
perform_improve_per:
type: number
type: object
v1.ExtractTable:
properties:
schema_name:
type: string
table_name:
type: string
type: object
v1.FeishuConfigurationV1:
properties:
app_id:
Expand Down Expand Up @@ -2322,6 +2342,17 @@ definitions:
example: ok
type: string
type: object
v1.ParseSQLResData:
properties:
extract_table:
items:
$ref: '#/definitions/v1.ExtractTable'
type: array
sql:
type: string
sql_type:
type: string
type: object
v1.PartialSyncAuditPlanSQLsReqV1:
properties:
audit_plan_sql_list:
Expand Down Expand Up @@ -8210,6 +8241,31 @@ paths:
summary: 直接审核SQL
tags:
- sql_audit
/v1/sql_parse:
get:
description: parse sql
operationId: parseSQL
parameters:
- description: instance type
in: query
name: instance_type
required: true
type: string
- description: sql
in: query
name: sql
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/v1.DirectParseSQLRes'
security:
- ApiKeyAuth: []
summary: 解析SQL
tags:
- sql_parse
/v1/statistic/instances/sql_average_execution_time:
get:
description: get average execution time of sql
Expand Down
Loading