當前位置: 首頁>>代碼示例>>Golang>>正文


Golang parser.ParseExprTraditional函數代碼示例

本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/parser.ParseExprTraditional函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseExprTraditional函數的具體用法?Golang ParseExprTraditional怎麽用?Golang ParseExprTraditional使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ParseExprTraditional函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestRetryResolveQNames

// Test that we can resolve the qnames in an expression that has already been
// resolved.
func TestRetryResolveQNames(t *testing.T) {
	defer leaktest.AfterTest(t)()

	expr, err := parser.ParseExprTraditional(`COUNT(a)`)
	if err != nil {
		t.Fatal(err)
	}

	for i := 0; i < 2; i++ {
		desc := testTableDesc()
		s := testInitDummySelectNode(desc)
		if err := desc.AllocateIDs(); err != nil {
			t.Fatal(err)
		}

		_, err := s.resolveQNames(expr)
		if err != nil {
			t.Fatal(err)
		}
		if len(s.qvals) != 1 {
			t.Fatalf("%d: expected 1 qvalue, but found %d", i, len(s.qvals))
		}
		if _, ok := s.qvals[columnRef{&s.source.info, 0}]; !ok {
			t.Fatalf("%d: unable to find qvalue for column 0 (a)", i)
		}
	}
}
開發者ID:JKhawaja,項目名稱:cockroach,代碼行數:29,代碼來源:select_qvalue_test.go

示例2: parseAndNormalizeExpr

func parseAndNormalizeExpr(t *testing.T, sql string) (parser.Expr, qvalMap) {
	expr, err := parser.ParseExprTraditional(sql)
	if err != nil {
		t.Fatalf("%s: %v", sql, err)
	}
	expr, err = (parser.EvalContext{}).NormalizeExpr(expr)
	if err != nil {
		t.Fatalf("%s: %v", sql, err)
	}

	// Perform qualified name resolution because {analyze,simplify}Expr want
	// expressions containing qvalues.
	s := &scanNode{}
	s.desc = testTableDesc()
	s.visibleCols = s.desc.Columns

	if err := s.desc.AllocateIDs(); err != nil {
		t.Fatal(err)
	}

	expr, err = s.resolveQNames(expr)
	if err != nil {
		t.Fatalf("%s: %v", sql, err)
	}
	if _, err := expr.TypeCheck(); err != nil {
		t.Fatalf("%s: %v", sql, err)
	}
	return expr, s.qvals
}
開發者ID:gechong,項目名稱:cockroach,代碼行數:29,代碼來源:analyze_test.go

示例3: makeCheckExprs

func (p *planner) makeCheckExprs(cols []sqlbase.ColumnDescriptor) ([]parser.Expr, error) {
	// Check to see if any of the columns have CHECK expressions. If there are
	// no CHECK expressions, we don't bother with constructing it.
	numCheck := 0
	for _, col := range cols {
		if col.CheckExpr != nil {
			numCheck++
			break
		}
	}
	if numCheck == 0 {
		return nil, nil
	}

	checkExprs := make([]parser.Expr, 0, numCheck)
	for _, col := range cols {
		if col.CheckExpr == nil {
			continue
		}
		expr, err := parser.ParseExprTraditional(*col.CheckExpr)
		if err != nil {
			return nil, err
		}
		checkExprs = append(checkExprs, expr)
	}
	return checkExprs, nil
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:27,代碼來源:insert.go

示例4: parseAndNormalizeExpr

func parseAndNormalizeExpr(t *testing.T, sql string) (parser.Expr, qvalMap) {
	expr, err := parser.ParseExprTraditional(sql)
	if err != nil {
		t.Fatalf("%s: %v", sql, err)
	}
	expr, err = (parser.EvalContext{}).NormalizeExpr(expr)
	if err != nil {
		t.Fatalf("%s: %v", sql, err)
	}

	// Perform qualified name resolution because {analyze,simplify}Expr want
	// expressions containing qvalues.
	desc := testTableDesc()
	sel := testInitDummySelectNode(desc)
	if err := desc.AllocateIDs(); err != nil {
		t.Fatal(err)
	}
	expr, nErr := sel.resolveQNames(expr)
	if nErr != nil {
		t.Fatalf("%s: %v", sql, nErr)
	}
	if _, err := expr.TypeCheck(nil); err != nil {
		t.Fatalf("%s: %v", sql, err)
	}
	return expr, sel.qvals
}
開發者ID:ekkotron,項目名稱:cockroach,代碼行數:26,代碼來源:analyze_test.go

示例5: TestRetryResolveQNames

// Test that we can resolve the qnames in an expression that has already been
// resolved.
func TestRetryResolveQNames(t *testing.T) {
	defer leaktest.AfterTest(t)

	expr, err := parser.ParseExprTraditional(`COUNT(a)`)
	if err != nil {
		t.Fatal(err)
	}

	for i := 0; i < 2; i++ {
		s := &scanNode{}
		s.desc = testTableDesc()
		s.visibleCols = s.desc.Columns
		if err := s.desc.AllocateIDs(); err != nil {
			t.Fatal(err)
		}

		_, pErr := s.resolveQNames(expr)
		if pErr != nil {
			t.Fatal(pErr)
		}
		if len(s.qvals) != 1 {
			t.Fatalf("%d: expected 1 qvalue, but found %d", i, len(s.qvals))
		}
		if _, ok := s.qvals[ColumnID(1)]; !ok {
			t.Fatalf("%d: unable to find qvalue for column ID 1", i)
		}
	}
}
開發者ID:billhongs,項目名稱:cockroach,代碼行數:30,代碼來源:scan_test.go

示例6: init

func (c *checkHelper) init(p *planner, tableDesc *sqlbase.TableDescriptor) error {
	if len(tableDesc.Checks) == 0 {
		return nil
	}

	c.qvals = make(qvalMap)
	c.cols = tableDesc.Columns
	table := tableInfo{
		columns: makeResultColumns(tableDesc.Columns),
	}

	c.exprs = make([]parser.TypedExpr, len(tableDesc.Checks))
	for i, check := range tableDesc.Checks {
		raw, err := parser.ParseExprTraditional(check.Expr)
		if err != nil {
			return err
		}
		typedExpr, err := p.analyzeExpr(raw, []*tableInfo{&table}, c.qvals,
			parser.TypeBool, false, "")
		if err != nil {
			return err
		}
		c.exprs[i] = typedExpr
	}
	return nil
}
開發者ID:mjibson,項目名稱:cockroach,代碼行數:26,代碼來源:check.go

示例7: makeDefaultExprs

func makeDefaultExprs(
	cols []sqlbase.ColumnDescriptor, parse *parser.Parser, evalCtx parser.EvalContext,
) ([]parser.TypedExpr, error) {
	// Check to see if any of the columns have DEFAULT expressions. If there
	// are no DEFAULT expressions, we don't bother with constructing the
	// defaults map as the defaults are all NULL.
	haveDefaults := false
	for _, col := range cols {
		if col.DefaultExpr != nil {
			haveDefaults = true
			break
		}
	}
	if !haveDefaults {
		return nil, nil
	}

	// Build the default expressions map from the parsed SELECT statement.
	defaultExprs := make([]parser.TypedExpr, 0, len(cols))
	for _, col := range cols {
		if col.DefaultExpr == nil {
			defaultExprs = append(defaultExprs, parser.DNull)
			continue
		}
		expr, err := parser.ParseExprTraditional(*col.DefaultExpr)
		if err != nil {
			return nil, err
		}
		typedExpr, err := parser.TypeCheck(expr, nil, col.Type.ToDatumType())
		if err != nil {
			return nil, err
		}
		if typedExpr, err = parse.NormalizeExpr(evalCtx, typedExpr); err != nil {
			return nil, err
		}
		if parser.ContainsVars(typedExpr) {
			return nil, util.Errorf("default expression contains variables")
		}
		defaultExprs = append(defaultExprs, typedExpr)
	}
	return defaultExprs, nil
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:42,代碼來源:insert.go

示例8: processExpression

// processExpression parses the string expression inside an Expression,
// interpreting $0, $1, etc as indexed variables.
func processExpression(exprSpec Expression, h *parser.IndexedVarHelper) (parser.TypedExpr, error) {
	expr, err := parser.ParseExprTraditional(exprSpec.Expr)
	if err != nil {
		return nil, err
	}

	// Convert ValArgs to IndexedVars
	v := valArgsConvert{h: h, err: nil}
	expr, _ = parser.WalkExpr(&v, expr)
	if v.err != nil {
		return nil, v.err
	}

	// Convert to a fully typed expression.
	typedExpr, err := parser.TypeCheck(expr, nil, nil)
	if err != nil {
		return nil, err
	}

	return typedExpr, nil
}
開發者ID:GitGoldie,項目名稱:cockroach,代碼行數:23,代碼來源:dist_sql_expr.go

示例9: makeDefaultExprs

func (p *planner) makeDefaultExprs(cols []ColumnDescriptor) ([]parser.Expr, error) {
	// Check to see if any of the columns have DEFAULT expressions. If there are
	// no DEFAULT expressions, we don't bother with constructing the defaults map
	// as the defaults are all NULL.
	haveDefaults := false
	for _, col := range cols {
		if col.DefaultExpr != nil {
			haveDefaults = true
			break
		}
	}
	if !haveDefaults {
		return nil, nil
	}

	// Build the default expressions map from the parsed SELECT statement.
	defaultExprs := make([]parser.Expr, 0, len(cols))
	for _, col := range cols {
		if col.DefaultExpr == nil {
			defaultExprs = append(defaultExprs, parser.DNull)
			continue
		}
		expr, err := parser.ParseExprTraditional(*col.DefaultExpr)
		if err != nil {
			return nil, err
		}
		expr, err = p.parser.NormalizeExpr(p.evalCtx, expr)
		if err != nil {
			return nil, err
		}
		if parser.ContainsVars(expr) {
			return nil, util.Errorf("default expression contains variables")
		}
		defaultExprs = append(defaultExprs, expr)
	}
	return defaultExprs, nil
}
開發者ID:liugangnhm,項目名稱:cockroach,代碼行數:37,代碼來源:insert.go

示例10: parseZoneName

func parseZoneName(s string) ([]string, error) {
	if strings.ToLower(s) == ".default" {
		return nil, nil
	}
	expr, err := parser.ParseExprTraditional(s)
	if err != nil {
		return nil, fmt.Errorf("malformed name: %s", s)
	}
	qname, ok := expr.(*parser.QualifiedName)
	if !ok {
		return nil, fmt.Errorf("malformed name: %s", s)
	}
	// This is a bit of a hack: "." is not a valid database name which we use as
	// a placeholder in order to normalize the qualified name.
	if err := qname.NormalizeTableName("."); err != nil {
		return nil, err
	}
	var names []string
	if n := qname.Database(); n != "." {
		names = append(names, n)
	}
	names = append(names, qname.Table())
	return names, nil
}
開發者ID:mjibson,項目名稱:cockroach,代碼行數:24,代碼來源:zone.go

示例11: init

func (c *checkHelper) init(p *planner, tableDesc *sqlbase.TableDescriptor) error {
	if len(tableDesc.Checks) == 0 {
		return nil
	}

	c.qvals = make(qvalMap)
	c.cols = tableDesc.Columns
	table := tableInfo{
		columns: makeResultColumns(tableDesc.Columns),
	}

	c.exprs = make([]parser.TypedExpr, len(tableDesc.Checks))
	for i, check := range tableDesc.Checks {
		raw, err := parser.ParseExprTraditional(check.Expr)
		if err != nil {
			return err
		}
		replaced, err := p.replaceSubqueries(raw, 1)
		if err != nil {
			return nil
		}
		resolved, err := resolveQNames(replaced, []*tableInfo{&table}, c.qvals, &p.qnameVisitor)
		if err != nil {
			return err
		}
		typedExpr, err := parser.TypeCheck(resolved, nil, parser.TypeBool)
		if err != nil {
			return err
		}
		if typedExpr, err = p.parser.NormalizeExpr(p.evalCtx, typedExpr); err != nil {
			return err
		}
		c.exprs[i] = typedExpr
	}
	return nil
}
開發者ID:JKhawaja,項目名稱:cockroach,代碼行數:36,代碼來源:check.go


注:本文中的github.com/cockroachdb/cockroach/sql/parser.ParseExprTraditional函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。