MCPcopy
hub / github.com/pingcap/tidb / ParseExpression

Function ParseExpression

pkg/util/generatedexpr/generated_expr.go:60–70  ·  view source on GitHub ↗

ParseExpression parses an ExprNode from a string. When TiDB loads infoschema from TiKV, `GeneratedExprString` of `ColumnInfo` is a string field, so we need to parse it into ast.ExprNode. This function is for that.

(expr string)

Source from the content-addressed store, hash-verified

58// of `ColumnInfo` is a string field, so we need to parse
59// it into ast.ExprNode. This function is for that.
60func ParseExpression(expr string) (node ast.ExprNode, err error) {
61 expr = fmt.Sprintf("select %s", expr)
62 charset, collation := charset.GetDefaultCharsetAndCollate()
63 stmts, _, err := parser.New().ParseSQL(expr,
64 parser.CharsetConnection(charset),
65 parser.CollationConnection(collation))
66 if err == nil {
67 node = stmts[0].(*ast.SelectStmt).Fields.Fields[0].Expr
68 }
69 return node, util.SyntaxError(err)
70}
71
72// SimpleResolveName resolves all column names in the expression node.
73func SimpleResolveName(node ast.ExprNode, tblInfo *model.TableInfo) (ast.ExprNode, error) {

Callers 5

TableFromMetaFunction · 0.92
buildGeneratedExprFunction · 0.92
onCreateVectorIndexMethod · 0.92
TestParseExpressionFunction · 0.85

Calls 6

NewFunction · 0.92
CharsetConnectionTypeAlias · 0.92
CollationConnectionTypeAlias · 0.92
SyntaxErrorFunction · 0.92
ParseSQLMethod · 0.65

Tested by 1

TestParseExpressionFunction · 0.68